ImmutableEventDispatcher.php 2.1KB

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. private $dispatcher;
  19. public function __construct(EventDispatcherInterface $dispatcher)
  20. {
  21. $this->dispatcher = $dispatcher;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function dispatch($eventName, Event $event = null)
  27. {
  28. return $this->dispatcher->dispatch($eventName, $event);
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function addListener($eventName, $listener, $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($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($eventName = null)
  62. {
  63. return $this->dispatcher->getListeners($eventName);
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function getListenerPriority($eventName, $listener)
  69. {
  70. return $this->dispatcher->getListenerPriority($eventName, $listener);
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function hasListeners($eventName = null)
  76. {
  77. return $this->dispatcher->hasListeners($eventName);
  78. }
  79. }