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.
24 * @var EventDispatcherInterface
29 * Creates an unmodifiable proxy for an event dispatcher.
31 * @param EventDispatcherInterface $dispatcher The proxied event dispatcher
33 public function __construct(EventDispatcherInterface $dispatcher)
35 $this->dispatcher = $dispatcher;
41 public function dispatch($eventName, Event $event = null)
43 return $this->dispatcher->dispatch($eventName, $event);
49 public function addListener($eventName, $listener, $priority = 0)
51 throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
57 public function addSubscriber(EventSubscriberInterface $subscriber)
59 throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
65 public function removeListener($eventName, $listener)
67 throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
73 public function removeSubscriber(EventSubscriberInterface $subscriber)
75 throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
81 public function getListeners($eventName = null)
83 return $this->dispatcher->getListeners($eventName);
89 public function getListenerPriority($eventName, $listener)
91 return $this->dispatcher->getListenerPriority($eventName, $listener);
97 public function hasListeners($eventName = null)
99 return $this->dispatcher->hasListeners($eventName);