1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\EventDispatcher;
13
14/**
15 * A read-only proxy for an event dispatcher.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19class ImmutableEventDispatcher implements EventDispatcherInterface
20{
21    private $dispatcher;
22
23    public function __construct(EventDispatcherInterface $dispatcher)
24    {
25        $this->dispatcher = $dispatcher;
26    }
27
28    /**
29     * {@inheritdoc}
30     */
31    public function dispatch(object $event, string $eventName = null): object
32    {
33        return $this->dispatcher->dispatch($event, $eventName);
34    }
35
36    /**
37     * {@inheritdoc}
38     */
39    public function addListener(string $eventName, $listener, int $priority = 0)
40    {
41        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
42    }
43
44    /**
45     * {@inheritdoc}
46     */
47    public function addSubscriber(EventSubscriberInterface $subscriber)
48    {
49        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
50    }
51
52    /**
53     * {@inheritdoc}
54     */
55    public function removeListener(string $eventName, $listener)
56    {
57        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
58    }
59
60    /**
61     * {@inheritdoc}
62     */
63    public function removeSubscriber(EventSubscriberInterface $subscriber)
64    {
65        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
66    }
67
68    /**
69     * {@inheritdoc}
70     */
71    public function getListeners(string $eventName = null)
72    {
73        return $this->dispatcher->getListeners($eventName);
74    }
75
76    /**
77     * {@inheritdoc}
78     */
79    public function getListenerPriority(string $eventName, $listener)
80    {
81        return $this->dispatcher->getListenerPriority($eventName, $listener);
82    }
83
84    /**
85     * {@inheritdoc}
86     */
87    public function hasListeners(string $eventName = null)
88    {
89        return $this->dispatcher->hasListeners($eventName);
90    }
91}
92