ImmutableEventDispatcher.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  19. * The proxied dispatcher.
  20. * @var EventDispatcherInterface
  21. */
  22. private $dispatcher;
  23. /**
  24. * Creates an unmodifiable proxy for an event dispatcher.
  25. *
  26. * @param EventDispatcherInterface $dispatcher The proxied event dispatcher.
  27. */
  28. public function __construct(EventDispatcherInterface $dispatcher)
  29. {
  30. $this->dispatcher = $dispatcher;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function dispatch($eventName, Event $event = null)
  36. {
  37. return $this->dispatcher->dispatch($eventName, $event);
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function addListener($eventName, $listener, $priority = 0)
  43. {
  44. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function addSubscriber(EventSubscriberInterface $subscriber)
  50. {
  51. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function removeListener($eventName, $listener)
  57. {
  58. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  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. * {@inheritdoc}
  69. */
  70. public function getListeners($eventName = null)
  71. {
  72. return $this->dispatcher->getListeners($eventName);
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function hasListeners($eventName = null)
  78. {
  79. return $this->dispatcher->hasListeners($eventName);
  80. }
  81. }