docParser = $docParser; return $this; } /** * Retrieve the DocParser instance * * If none is registered, lazy-loads a new instance. * * @return DocParser */ public function getDocParser() { if (!$this->docParser instanceof DocParser) { $this->setDocParser(new DocParser()); } return $this->docParser; } /** * Handle annotation creation * * @param EventInterface $e * @return false|\stdClass */ public function onCreateAnnotation(EventInterface $e) { $annotationClass = $e->getParam('class', false); if (!$annotationClass) { return false; } if (!isset($this->allowedAnnotations[$annotationClass])) { return false; } $annotationString = $e->getParam('raw', false); if (!$annotationString) { return false; } // Annotation classes provided by the AnnotationScanner are already // resolved to fully-qualified class names. Adding the global namespace // prefix allows the Doctrine annotation parser to locate the annotation // class correctly. $annotationString = preg_replace('/^(@)/', '$1\\', $annotationString); $parser = $this->getDocParser(); $annotations = $parser->parse($annotationString); if (empty($annotations)) { return false; } $annotation = array_shift($annotations); if (!is_object($annotation)) { return false; } return $annotation; } /** * Specify an allowed annotation class * * @param string $annotation * @return DoctrineAnnotationParser */ public function registerAnnotation($annotation) { $this->allowedAnnotations[$annotation] = true; return $this; } /** * Set many allowed annotations at once * * @param array|Traversable $annotations Array or traversable object of * annotation class names * @throws Exception\InvalidArgumentException * @return DoctrineAnnotationParser */ public function registerAnnotations($annotations) { if (!is_array($annotations) && !$annotations instanceof Traversable) { throw new Exception\InvalidArgumentException(sprintf( '%s: expects an array or Traversable; received "%s"', __METHOD__, (is_object($annotations) ? get_class($annotations) : gettype($annotations)) )); } foreach ($annotations as $annotation) { $this->allowedAnnotations[$annotation] = true; } return $this; } }