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