Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

LazyListenerAggregate.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.49 KiB


001  <?php
002  /**
003   * Zend Framework (http://framework.zend.com/)
004   *
005   * @link      http://github.com/zendframework/zend-eventmanager for the canonical source repository
006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007   * @license   https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
008   */
009   
010  namespace Zend\EventManager;
011   
012  use Interop\Container\ContainerInterface;
013   
014  /**
015   * Aggregate listener for attaching lazy listeners.
016   *
017   * Lazy listeners are listeners where creation is deferred until they are
018   * triggered; this removes the most costly mechanism of pulling a listener
019   * from a container unless the listener is actually invoked.
020   *
021   * Usage is:
022   *
023   * <code>
024   * $events->attachAggregate(new LazyListenerAggregate(
025   *     $lazyEventListenersOrDefinitions,
026   *     $container
027   * ));
028   * </code>
029   */
030  class LazyListenerAggregate implements ListenerAggregateInterface
031  {
032      use ListenerAggregateTrait;
033   
034      /**
035       * @var ContainerInterface Container from which to pull lazy listeners.
036       */
037      private $container;
038   
039      /**
040       * @var array Additional environment/option variables to use when creating listener.
041       */
042      private $env;
043   
044      /**
045       * Generated LazyEventListener instances.
046       *
047       * @var LazyEventListener[]
048       */
049      private $lazyListeners = [];
050   
051      /**
052       * Constructor
053       *
054       * Accepts the composed $listeners, as well as the $container and $env in
055       * order to create a listener aggregate that defers listener creation until
056       * the listener is triggered.
057       *
058       * Listeners may be either LazyEventListener instances, or lazy event
059       * listener definitions that can be provided to a LazyEventListener
060       * constructor in order to create a new instance; in the latter case, the
061       * $container and $env will be passed at instantiation as well.
062       *
063       * @var array $listeners LazyEventListener instances or array definitions
064       *     to pass to the LazyEventListener constructor.
065       * @var ContainerInterface $container
066       * @var array $env
067       * @throws Exception\InvalidArgumentException for invalid listener items.
068       */
069      public function __construct(array $listeners, ContainerInterface $container, array $env = [])
070      {
071          $this->container = $container;
072          $this->env       = $env;
073   
074          // This would raise an exception for invalid structs
075          foreach ($listeners as $listener) {
076              if (is_array($listener)) {
077                  $listener = new LazyEventListener($listener, $container, $env);
078              }
079   
080              if (! $listener instanceof LazyEventListener) {
081                  throw new Exception\InvalidArgumentException(sprintf(
082                      'All listeners must be LazyEventListener instances or definitions; received %s',
083                      (is_object($listener) ? get_class($listener) : gettype($listener))
084                  ));
085              }
086   
087              $this->lazyListeners[] = $listener;
088          }
089      }
090   
091      /**
092       * Attach the aggregate to the event manager.
093       *
094       * Loops through all composed lazy listeners, and attaches them to the
095       * event manager.
096       *
097       * @var EventManagerInterface $events
098       * @var int $priority
099       */
100      public function attach(EventManagerInterface $events, $priority = 1)
101      {
102          foreach ($this->lazyListeners as $lazyListener) {
103              $this->listeners[] = $events->attach(
104                  $lazyListener->getEvent(),
105                  $lazyListener,
106                  $lazyListener->getPriority($priority)
107              );
108          }
109      }
110  }
111