Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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