1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\Common\Annotations; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Simple Annotation Reader. |
24
|
|
|
* |
25
|
|
|
* This annotation reader is intended to be used in projects where you have |
26
|
|
|
* full-control over all annotations that are available. |
27
|
|
|
* |
28
|
|
|
* @since 2.2 |
29
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
30
|
|
|
* @author Fabio B. Silva <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class SimpleAnnotationReader implements Reader, ReaderWithConstantsAnnotations |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var DocParser |
36
|
|
|
*/ |
37
|
|
|
private $parser; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor. |
41
|
|
|
* |
42
|
|
|
* Initializes a new SimpleAnnotationReader. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
$this->parser = new DocParser(); |
47
|
|
|
$this->parser->setIgnoreNotImportedAnnotations(true); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Adds a namespace in which we will look for annotations. |
52
|
|
|
* |
53
|
|
|
* @param string $namespace |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function addNamespace($namespace) |
58
|
|
|
{ |
59
|
|
|
$this->parser->addNamespace($namespace); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
|
|
public function getClassAnnotations(\ReflectionClass $class) |
66
|
|
|
{ |
67
|
|
|
return $this->parser->parse($class->getDocComment(), 'class '.$class->getName()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritDoc} |
72
|
|
|
*/ |
73
|
|
|
public function getMethodAnnotations(\ReflectionMethod $method) |
74
|
|
|
{ |
75
|
|
|
return $this->parser->parse($method->getDocComment(), |
76
|
|
|
'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritDoc} |
81
|
|
|
*/ |
82
|
|
|
public function getPropertyAnnotations(\ReflectionProperty $property) |
83
|
|
|
{ |
84
|
|
|
return $this->parser->parse($property->getDocComment(), |
85
|
|
|
'property '.$property->getDeclaringClass()->name.'::$'.$property->getName()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritDoc} |
90
|
|
|
*/ |
91
|
|
|
public function getConstantAnnotations(\ReflectionClassConstant $constant): array |
92
|
|
|
{ |
93
|
|
|
return $this->parser->parse($constant->getDocComment(), |
94
|
|
|
'constant '.$constant->getDeclaringClass()->name.'::'.$constant->getName()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritDoc} |
99
|
|
|
*/ |
100
|
|
|
public function getClassAnnotation(\ReflectionClass $class, $annotationName) |
101
|
|
|
{ |
102
|
|
|
foreach ($this->getClassAnnotations($class) as $annot) { |
103
|
|
|
if ($annot instanceof $annotationName) { |
104
|
|
|
return $annot; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return null; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritDoc} |
113
|
|
|
*/ |
114
|
|
|
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName) |
115
|
|
|
{ |
116
|
|
|
foreach ($this->getMethodAnnotations($method) as $annot) { |
117
|
|
|
if ($annot instanceof $annotationName) { |
118
|
|
|
return $annot; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritDoc} |
127
|
|
|
*/ |
128
|
|
|
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName) |
129
|
|
|
{ |
130
|
|
|
foreach ($this->getPropertyAnnotations($property) as $annot) { |
131
|
|
|
if ($annot instanceof $annotationName) { |
132
|
|
|
return $annot; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return null; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* {@inheritDoc} |
141
|
|
|
*/ |
142
|
|
|
public function getConstantAnnotation(\ReflectionClassConstant $constant, $annotationName) |
143
|
|
|
{ |
144
|
|
|
foreach ($this->getConstantAnnotations($constant) as $annot) { |
145
|
|
|
if ($annot instanceof $annotationName) { |
146
|
|
|
return $annot; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return null; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.