Drupal investigation

ImmutableEventDispatcher.php 2.4KB

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