ImmutableEventDispatcher.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 EventDispatcherInterface $dispatcher;
  19. public function __construct(EventDispatcherInterface $dispatcher)
  20. {
  21. $this->dispatcher = $dispatcher;
  22. }
  23. public function dispatch(object $event, ?string $eventName = null): object
  24. {
  25. return $this->dispatcher->dispatch($event, $eventName);
  26. }
  27. /**
  28. * @return never
  29. */
  30. public function addListener(string $eventName, callable|array $listener, int $priority = 0)
  31. {
  32. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  33. }
  34. /**
  35. * @return never
  36. */
  37. public function addSubscriber(EventSubscriberInterface $subscriber)
  38. {
  39. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  40. }
  41. /**
  42. * @return never
  43. */
  44. public function removeListener(string $eventName, callable|array $listener)
  45. {
  46. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  47. }
  48. /**
  49. * @return never
  50. */
  51. public function removeSubscriber(EventSubscriberInterface $subscriber)
  52. {
  53. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  54. }
  55. public function getListeners(?string $eventName = null): array
  56. {
  57. return $this->dispatcher->getListeners($eventName);
  58. }
  59. public function getListenerPriority(string $eventName, callable|array $listener): ?int
  60. {
  61. return $this->dispatcher->getListenerPriority($eventName, $listener);
  62. }
  63. public function hasListeners(?string $eventName = null): bool
  64. {
  65. return $this->dispatcher->hasListeners($eventName);
  66. }
  67. }