[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/zendframework/zend-eventmanager/src/ -> EventManagerAwareTrait.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   5   * @link      http://github.com/zendframework/zend-eventmanager for the canonical source repository
   6   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
   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       */
  40      public function setEventManager(EventManagerInterface $events)
  41      {
  42          $identifiers = [__CLASS__, get_class($this)];
  43          if (isset($this->eventIdentifier)) {
  44              if ((is_string($this->eventIdentifier))
  45                  || (is_array($this->eventIdentifier))
  46                  || ($this->eventIdentifier instanceof Traversable)
  47              ) {
  48                  $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier));
  49              } elseif (is_object($this->eventIdentifier)) {
  50                  $identifiers[] = $this->eventIdentifier;
  51              }
  52              // silently ignore invalid eventIdentifier types
  53          }
  54          $events->setIdentifiers($identifiers);
  55          $this->events = $events;
  56          if (method_exists($this, 'attachDefaultListeners')) {
  57              $this->attachDefaultListeners();
  58          }
  59      }
  60  
  61      /**
  62       * Retrieve the event manager
  63       *
  64       * Lazy-loads an EventManager instance if none registered.
  65       *
  66       * @return EventManagerInterface
  67       */
  68      public function getEventManager()
  69      {
  70          if (! $this->events instanceof EventManagerInterface) {
  71              $this->setEventManager(new EventManager());
  72          }
  73          return $this->events;
  74      }
  75  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1