[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-code/src/Annotation/ -> AnnotationManager.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   5   * @link      http://github.com/zendframework/zf2 for the canonical source repository
   6   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   http://framework.zend.com/license/new-bsd New BSD License
   8   */
   9  
  10  namespace Zend\Code\Annotation;
  11  
  12  use Zend\Code\Annotation\Parser\ParserInterface;
  13  use Zend\EventManager\Event;
  14  use Zend\EventManager\EventManager;
  15  use Zend\EventManager\EventManagerAwareInterface;
  16  use Zend\EventManager\EventManagerInterface;
  17  
  18  /**
  19   * Pluggable annotation manager
  20   *
  21   * Simply composes an EventManager. When createAnnotation() is called, it fires
  22   * off an event of the same name, passing it the resolved annotation class, the
  23   * annotation content, and the raw annotation string; the first listener to
  24   * return an object will halt execution of the event, and that object will be
  25   * returned as the annotation.
  26   */
  27  class AnnotationManager implements EventManagerAwareInterface
  28  {
  29      const EVENT_CREATE_ANNOTATION = 'createAnnotation';
  30  
  31      /**
  32       * @var EventManagerInterface
  33       */
  34      protected $events;
  35  
  36      /**
  37       * Set the event manager instance
  38       *
  39       * @param  EventManagerInterface $events
  40       * @return AnnotationManager
  41       */
  42      public function setEventManager(EventManagerInterface $events)
  43      {
  44          $events->setIdentifiers(array(
  45              __CLASS__,
  46              get_class($this),
  47          ));
  48          $this->events = $events;
  49  
  50          return $this;
  51      }
  52  
  53      /**
  54       * Retrieve event manager
  55       *
  56       * Lazy loads an instance if none registered.
  57       *
  58       * @return EventManagerInterface
  59       */
  60      public function getEventManager()
  61      {
  62          if (null === $this->events) {
  63              $this->setEventManager(new EventManager());
  64          }
  65  
  66          return $this->events;
  67      }
  68  
  69      /**
  70       * Attach a parser to listen to the createAnnotation event
  71       *
  72       * @param  ParserInterface $parser
  73       * @return AnnotationManager
  74       */
  75      public function attach(ParserInterface $parser)
  76      {
  77          $this->getEventManager()
  78               ->attach(self::EVENT_CREATE_ANNOTATION, array($parser, 'onCreateAnnotation'));
  79  
  80          return $this;
  81      }
  82  
  83      /**
  84       * Create Annotation
  85       *
  86       * @param  string[] $annotationData
  87       * @return false|\stdClass
  88       */
  89      public function createAnnotation(array $annotationData)
  90      {
  91          $event = new Event();
  92          $event->setName(self::EVENT_CREATE_ANNOTATION);
  93          $event->setTarget($this);
  94          $event->setParams(array(
  95              'class'   => $annotationData[0],
  96              'content' => $annotationData[1],
  97              'raw'     => $annotationData[2],
  98          ));
  99  
 100          $eventManager = $this->getEventManager();
 101          $results = $eventManager->trigger($event, function ($r) {
 102              return (is_object($r));
 103          });
 104  
 105          $annotation = $results->last();
 106  
 107          return (is_object($annotation) ? $annotation : false);
 108      }
 109  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1