1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Common\Annotations; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Simple Annotation Reader. |
7
|
|
|
* |
8
|
|
|
* This annotation reader is intended to be used in projects where you have |
9
|
|
|
* full-control over all annotations that are available. |
10
|
|
|
* |
11
|
|
|
* @since 2.2 |
12
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
13
|
|
|
* @author Fabio B. Silva <[email protected]> |
14
|
|
|
* @deprecated Deprecated in favour of using AnnotationReader |
15
|
|
|
*/ |
16
|
|
|
class SimpleAnnotationReader implements Reader |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var DocParser |
20
|
|
|
*/ |
21
|
|
|
private $parser; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Constructor. |
25
|
|
|
* |
26
|
|
|
* Initializes a new SimpleAnnotationReader. |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
$this->parser = new DocParser(); |
31
|
|
|
$this->parser->setIgnoreNotImportedAnnotations(true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Adds a namespace in which we will look for annotations. |
36
|
|
|
* |
37
|
|
|
* @param string $namespace |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function addNamespace($namespace) |
42
|
|
|
{ |
43
|
|
|
$this->parser->addNamespace($namespace); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritDoc} |
48
|
|
|
*/ |
49
|
|
|
public function getClassAnnotations(\ReflectionClass $class) |
50
|
|
|
{ |
51
|
|
|
return $this->parser->parse($class->getDocComment(), 'class '.$class->getName()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
public function getMethodAnnotations(\ReflectionMethod $method) |
58
|
|
|
{ |
59
|
|
|
return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritDoc} |
64
|
|
|
*/ |
65
|
|
|
public function getPropertyAnnotations(\ReflectionProperty $property) |
66
|
|
|
{ |
67
|
|
|
return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritDoc} |
72
|
|
|
*/ |
73
|
|
|
public function getClassAnnotation(\ReflectionClass $class, $annotationName) |
74
|
|
|
{ |
75
|
|
|
foreach ($this->getClassAnnotations($class) as $annot) { |
76
|
|
|
if ($annot instanceof $annotationName) { |
77
|
|
|
return $annot; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
|
|
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName) |
88
|
|
|
{ |
89
|
|
|
foreach ($this->getMethodAnnotations($method) as $annot) { |
90
|
|
|
if ($annot instanceof $annotationName) { |
91
|
|
|
return $annot; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritDoc} |
100
|
|
|
*/ |
101
|
|
|
public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName) |
102
|
|
|
{ |
103
|
|
|
foreach ($this->getPropertyAnnotations($property) as $annot) { |
104
|
|
|
if ($annot instanceof $annotationName) { |
105
|
|
|
return $annot; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return null; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|