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.
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>.
20 namespace Doctrine\Common\Annotations;
22 use Doctrine\Common\Annotations\Annotation\Target;
25 * Simple Annotation Reader.
27 * This annotation reader is intended to be used in projects where you have
28 * full-control over all annotations that are available.
31 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
32 * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
34 class SimpleAnnotationReader implements Reader
44 * Initializes a new SimpleAnnotationReader.
46 public function __construct()
48 $this->parser = new DocParser();
49 $this->parser->setIgnoreNotImportedAnnotations(true);
53 * Adds a namespace in which we will look for annotations.
55 * @param string $namespace
57 public function addNamespace($namespace)
59 $this->parser->addNamespace($namespace);
63 * Gets the annotations applied to a class.
65 * @param \ReflectionClass $class The ReflectionClass of the class from which
66 * the class annotations should be read.
68 * @return array An array of Annotations.
70 public function getClassAnnotations(\ReflectionClass $class)
72 return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
76 * Gets the annotations applied to a method.
78 * @param \ReflectionMethod $method The ReflectionMethod of the method from which
79 * the annotations should be read.
81 * @return array An array of Annotations.
83 public function getMethodAnnotations(\ReflectionMethod $method)
85 return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
89 * Gets the annotations applied to a property.
91 * @param \ReflectionProperty $property The ReflectionProperty of the property
92 * from which the annotations should be read.
94 * @return array An array of Annotations.
96 public function getPropertyAnnotations(\ReflectionProperty $property)
98 return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName());
102 * Gets a class annotation.
104 * @param \ReflectionClass $class The ReflectionClass of the class from which
105 * the class annotations should be read.
106 * @param string $annotationName The name of the annotation.
108 * @return mixed The Annotation or NULL, if the requested annotation does not exist.
110 public function getClassAnnotation(\ReflectionClass $class, $annotationName)
112 foreach ($this->getClassAnnotations($class) as $annot) {
113 if ($annot instanceof $annotationName) {
122 * Gets a method annotation.
124 * @param \ReflectionMethod $method
125 * @param string $annotationName The name of the annotation.
127 * @return mixed The Annotation or NULL, if the requested annotation does not exist.
129 public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
131 foreach ($this->getMethodAnnotations($method) as $annot) {
132 if ($annot instanceof $annotationName) {
141 * Gets a property annotation.
143 * @param \ReflectionProperty $property
144 * @param string $annotationName The name of the annotation.
145 * @return mixed The Annotation or NULL, if the requested annotation does not exist.
147 public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
149 foreach ($this->getPropertyAnnotations($property) as $annot) {
150 if ($annot instanceof $annotationName) {