[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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-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\EventManager; 11 12 use Traversable; 13 14 /** 15 * A trait for objects that provide events. 16 * 17 * If you use this trait in an object, you will probably want to also implement 18 * EventManagerAwareInterface, which will make it so the default initializer in 19 * a ZF2 MVC application will automatically inject an instance of the 20 * EventManager into your object when it is pulled from the ServiceManager. 21 * 22 * @see Zend\Mvc\Service\ServiceManagerConfig 23 */ 24 trait EventManagerAwareTrait 25 { 26 /** 27 * @var EventManagerInterface 28 */ 29 protected $events; 30 31 /** 32 * Set the event manager instance used by this context. 33 * 34 * For convenience, this method will also set the class name / LSB name as 35 * identifiers, in addition to any string or array of strings set to the 36 * $this->eventIdentifier property. 37 * 38 * @param EventManagerInterface $events 39 * @return mixed 40 */ 41 public function setEventManager(EventManagerInterface $events) 42 { 43 $identifiers = array(__CLASS__, get_class($this)); 44 if (isset($this->eventIdentifier)) { 45 if ((is_string($this->eventIdentifier)) 46 || (is_array($this->eventIdentifier)) 47 || ($this->eventIdentifier instanceof Traversable) 48 ) { 49 $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier)); 50 } elseif (is_object($this->eventIdentifier)) { 51 $identifiers[] = $this->eventIdentifier; 52 } 53 // silently ignore invalid eventIdentifier types 54 } 55 $events->setIdentifiers($identifiers); 56 $this->events = $events; 57 if (method_exists($this, 'attachDefaultListeners')) { 58 $this->attachDefaultListeners(); 59 } 60 return $this; 61 } 62 63 /** 64 * Retrieve the event manager 65 * 66 * Lazy-loads an EventManager instance if none registered. 67 * 68 * @return EventManagerInterface 69 */ 70 public function getEventManager() 71 { 72 if (!$this->events instanceof EventManagerInterface) { 73 $this->setEventManager(new EventManager()); 74 } 75 return $this->events; 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |