4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\EventDispatcher
;
15 * A read-only proxy for an event dispatcher.
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 class ImmutableEventDispatcher
implements EventDispatcherInterface
22 * The proxied dispatcher.
23 * @var EventDispatcherInterface
28 * Creates an unmodifiable proxy for an event dispatcher.
30 * @param EventDispatcherInterface $dispatcher The proxied event dispatcher.
32 public function __construct(EventDispatcherInterface
$dispatcher)
34 $this->dispatcher
= $dispatcher;
40 public function dispatch($eventName, Event
$event = null)
42 return $this->dispatcher
->dispatch($eventName, $event);
48 public function addListener($eventName, $listener, $priority = 0)
50 throw new \
BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
56 public function addSubscriber(EventSubscriberInterface
$subscriber)
58 throw new \
BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
64 public function removeListener($eventName, $listener)
66 throw new \
BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
72 public function removeSubscriber(EventSubscriberInterface
$subscriber)
74 throw new \
BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
80 public function getListeners($eventName = null)
82 return $this->dispatcher
->getListeners($eventName);
88 public function hasListeners($eventName = null)
90 return $this->dispatcher
->hasListeners($eventName);