Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

DoctrineAnnotationParser.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 4.49 KiB


 001  <?php
 002  /**
 003   * Zend Framework (http://framework.zend.com/)
 004   *
 005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 006   * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
 007   * @license   http://framework.zend.com/license/new-bsd New BSD License
 008   */
 009   
 010  namespace Zend\Code\Annotation\Parser;
 011   
 012  use Doctrine\Common\Annotations\AnnotationRegistry;
 013  use Doctrine\Common\Annotations\DocParser;
 014  use Traversable;
 015  use Zend\Code\Exception;
 016  use Zend\EventManager\EventInterface;
 017   
 018  use function array_shift;
 019  use function class_exists;
 020  use function get_class;
 021  use function gettype;
 022  use function is_array;
 023  use function is_object;
 024  use function preg_replace;
 025  use function sprintf;
 026   
 027  /**
 028   * A parser for docblock annotations that utilizes the annotation parser from
 029   * Doctrine\Common.
 030   *
 031   * Consumes Doctrine\Common\Annotations\DocParser, and responds to events from
 032   * AnnotationManager. If the annotation examined is in the list of classes we
 033   * are interested in, the raw annotation is passed to the DocParser in order to
 034   * retrieve the annotation object instance. Otherwise, it is skipped.
 035   */
 036  class DoctrineAnnotationParser implements ParserInterface
 037  {
 038      /**
 039       * @var array Annotation classes we support on this iteration
 040       */
 041      protected $allowedAnnotations = [];
 042   
 043      /**
 044       * @var DocParser
 045       */
 046      protected $docParser;
 047   
 048      public function __construct()
 049      {
 050          // Hack to ensure an attempt to autoload an annotation class is made
 051          AnnotationRegistry::registerLoader(function ($class) {
 052              return (bool) class_exists($class);
 053          });
 054      }
 055   
 056      /**
 057       * Set the DocParser instance
 058       *
 059       * @param  DocParser $docParser
 060       * @return DoctrineAnnotationParser
 061       */
 062      public function setDocParser(DocParser $docParser)
 063      {
 064          $this->docParser = $docParser;
 065          return $this;
 066      }
 067   
 068      /**
 069       * Retrieve the DocParser instance
 070       *
 071       * If none is registered, lazy-loads a new instance.
 072       *
 073       * @return DocParser
 074       */
 075      public function getDocParser()
 076      {
 077          if (! $this->docParser instanceof DocParser) {
 078              $this->setDocParser(new DocParser());
 079          }
 080   
 081          return $this->docParser;
 082      }
 083   
 084      /**
 085       * Handle annotation creation
 086       *
 087       * @param  EventInterface $e
 088       * @return false|\stdClass
 089       */
 090      public function onCreateAnnotation(EventInterface $e)
 091      {
 092          $annotationClass = $e->getParam('class', false);
 093          if (! $annotationClass) {
 094              return false;
 095          }
 096   
 097          if (! isset($this->allowedAnnotations[$annotationClass])) {
 098              return false;
 099          }
 100   
 101          $annotationString = $e->getParam('raw', false);
 102          if (! $annotationString) {
 103              return false;
 104          }
 105   
 106          // Annotation classes provided by the AnnotationScanner are already
 107          // resolved to fully-qualified class names. Adding the global namespace
 108          // prefix allows the Doctrine annotation parser to locate the annotation
 109          // class correctly.
 110          $annotationString = preg_replace('/^(@)/', '$1\\', $annotationString);
 111   
 112          $parser      = $this->getDocParser();
 113          $annotations = $parser->parse($annotationString);
 114          if (empty($annotations)) {
 115              return false;
 116          }
 117   
 118          $annotation = array_shift($annotations);
 119          if (! is_object($annotation)) {
 120              return false;
 121          }
 122   
 123          return $annotation;
 124      }
 125   
 126      /**
 127       * Specify an allowed annotation class
 128       *
 129       * @param  string $annotation
 130       * @return DoctrineAnnotationParser
 131       */
 132      public function registerAnnotation($annotation)
 133      {
 134          $this->allowedAnnotations[$annotation] = true;
 135          return $this;
 136      }
 137   
 138      /**
 139       * Set many allowed annotations at once
 140       *
 141       * @param  array|Traversable $annotations Array or traversable object of
 142       *         annotation class names
 143       * @throws Exception\InvalidArgumentException
 144       * @return DoctrineAnnotationParser
 145       */
 146      public function registerAnnotations($annotations)
 147      {
 148          if (! is_array($annotations) && ! $annotations instanceof Traversable) {
 149              throw new Exception\InvalidArgumentException(sprintf(
 150                  '%s: expects an array or Traversable; received "%s"',
 151                  __METHOD__,
 152                  is_object($annotations) ? get_class($annotations) : gettype($annotations)
 153              ));
 154          }
 155   
 156          foreach ($annotations as $annotation) {
 157              $this->allowedAnnotations[$annotation] = true;
 158          }
 159   
 160          return $this;
 161      }
 162  }
 163