[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/event/ -> dispatcher.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\event;
  15  
  16  use Symfony\Component\EventDispatcher\EventDispatcher;
  17  use Symfony\Component\EventDispatcher\Event;
  18  
  19  /**
  20  * Extension of the Symfony EventDispatcher
  21  *
  22  * It provides an additional `trigger_event` method, which
  23  * gives some syntactic sugar for dispatching events. Instead
  24  * of creating the event object, the method will do that for
  25  * you.
  26  *
  27  * Example:
  28  *
  29  *     $vars = array('page_title');
  30  *     extract($phpbb_dispatcher->trigger_event('core.index', compact($vars)));
  31  *
  32  */
  33  class dispatcher extends EventDispatcher implements dispatcher_interface
  34  {
  35      /**
  36       * @var bool
  37       */
  38      protected $disabled = false;
  39  
  40      /**
  41      * {@inheritdoc}
  42      */
  43  	public function trigger_event($eventName, $data = [])
  44      {
  45          $event = new \phpbb\event\data($data);
  46          $this->dispatch($eventName, $event);
  47          return $event->get_data_filtered(array_keys($data));
  48      }
  49  
  50      /**
  51       * {@inheritdoc}
  52       */
  53  	public function dispatch($eventName, Event $event = null)
  54      {
  55          if ($this->disabled)
  56          {
  57              return $event;
  58          }
  59  
  60          foreach ((array) $eventName as $name)
  61          {
  62              $event = parent::dispatch($name, $event);
  63          }
  64  
  65          return $event;
  66      }
  67  
  68      /**
  69       * {@inheritdoc}
  70       */
  71  	public function disable()
  72      {
  73          $this->disabled = true;
  74      }
  75  
  76      /**
  77       * {@inheritdoc}
  78       */
  79  	public function enable()
  80      {
  81          $this->disabled = false;
  82      }
  83  }


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