Maslosoft Zamm API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/zamm
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/zamm/
*/
namespace Maslosoft\Zamm;
use Exception;
use Maslosoft\Zamm\Decorators\AnnotationRemover;
use Maslosoft\Zamm\Decorators\DocTagRemover;
use Maslosoft\Zamm\Decorators\StarRemover;
use Maslosoft\Zamm\Helpers\DocWrapper;
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface;
use Maslosoft\Zamm\Traits\SourceMagic;
use ReflectionClass;
/**
* DocBlock
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class DocBlock implements SourceAccessorInterface
{
use SourceMagic;
/**
*
* @var ReflectionClass
*/
private $info = null;
public function __construct($className = null)
{
$this->info = new ReflectionClass($className);
}
/**
* Get doc comment for method.
* @param string $name
* @return DocWrapper
*/
public function method($name)
{
assert($this->info->hasMethod($name));
return $this->decorate($this->info->getMethod($name)->getDocComment());
}
/**
* Get doc comment for property.
* @param string $name
* @return DocWrapper
*/
public function property($name)
{
assert($this->info->hasProperty($name));
return $this->decorate($this->info->getProperty($name)->getDocComment());
}
public static function __callStatic($name, $arguments)
{
}
public function __toString()
{
return (string) $this->decorate($this->info->getDocComment());
}
private function decorate($docBlock)
{
try
{
$decorators = [
new StarRemover(),
new DocTagRemover(),
new AnnotationRemover()
];
foreach ($decorators as $decorator)
{
$decorator->decorate($docBlock);
}
}
catch (Exception $ex)
{
return $ex->getMessage();
}
return new DocWrapper($docBlock);
}
}
API documentation generated by ApiGen