You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.2 KiB

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