ImmutableEventDispatcher.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }