[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
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-2016 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 use function get_class; 19 use function is_object; 20 21 /** 22 * Pluggable annotation manager 23 * 24 * Simply composes an EventManager. When createAnnotation() is called, it fires 25 * off an event of the same name, passing it the resolved annotation class, the 26 * annotation content, and the raw annotation string; the first listener to 27 * return an object will halt execution of the event, and that object will be 28 * returned as the annotation. 29 */ 30 class AnnotationManager implements EventManagerAwareInterface 31 { 32 const EVENT_CREATE_ANNOTATION = 'createAnnotation'; 33 34 /** 35 * @var EventManagerInterface 36 */ 37 protected $events; 38 39 /** 40 * Set the event manager instance 41 * 42 * @param EventManagerInterface $events 43 * @return AnnotationManager 44 */ 45 public function setEventManager(EventManagerInterface $events) 46 { 47 $events->setIdentifiers([ 48 __CLASS__, 49 get_class($this), 50 ]); 51 $this->events = $events; 52 53 return $this; 54 } 55 56 /** 57 * Retrieve event manager 58 * 59 * Lazy loads an instance if none registered. 60 * 61 * @return EventManagerInterface 62 */ 63 public function getEventManager() 64 { 65 if (null === $this->events) { 66 $this->setEventManager(new EventManager()); 67 } 68 69 return $this->events; 70 } 71 72 /** 73 * Attach a parser to listen to the createAnnotation event 74 * 75 * @param ParserInterface $parser 76 * @return AnnotationManager 77 */ 78 public function attach(ParserInterface $parser) 79 { 80 $this->getEventManager() 81 ->attach(self::EVENT_CREATE_ANNOTATION, [$parser, 'onCreateAnnotation']); 82 83 return $this; 84 } 85 86 /** 87 * Create Annotation 88 * 89 * @param string[] $annotationData 90 * @return false|\stdClass 91 */ 92 public function createAnnotation(array $annotationData) 93 { 94 $event = new Event(); 95 $event->setName(self::EVENT_CREATE_ANNOTATION); 96 $event->setTarget($this); 97 $event->setParams([ 98 'class' => $annotationData[0], 99 'content' => $annotationData[1], 100 'raw' => $annotationData[2], 101 ]); 102 103 $eventManager = $this->getEventManager(); 104 $results = $eventManager->triggerEventUntil(function ($r) { 105 return is_object($r); 106 }, $event); 107 108 $annotation = $results->last(); 109 110 return is_object($annotation) ? $annotation : false; 111 } 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |