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;
23 * Simple Annotation Reader.
25 * This annotation reader is intended to be used in projects where you have
26 * full-control over all annotations that are available.
29 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
30 * @author Fabio B. Silva <fabio.bat.silva@gmail.com>
32 class SimpleAnnotationReader implements Reader
42 * Initializes a new SimpleAnnotationReader.
44 public function __construct()
46 $this->parser = new DocParser();
47 $this->parser->setIgnoreNotImportedAnnotations(true);
51 * Adds a namespace in which we will look for annotations.
53 * @param string $namespace
57 public function addNamespace($namespace)
59 $this->parser->addNamespace($namespace);
65 public function getClassAnnotations(\ReflectionClass $class)
67 return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
73 public function getMethodAnnotations(\ReflectionMethod $method)
75 return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
81 public function getPropertyAnnotations(\ReflectionProperty $property)
83 return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName());
89 public function getClassAnnotation(\ReflectionClass $class, $annotationName)
91 foreach ($this->getClassAnnotations($class) as $annot) {
92 if ($annot instanceof $annotationName) {
103 public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
105 foreach ($this->getMethodAnnotations($method) as $annot) {
106 if ($annot instanceof $annotationName) {
117 public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
119 foreach ($this->getPropertyAnnotations($property) as $annot) {
120 if ($annot instanceof $annotationName) {