Nessuna descrizione

ImmutableEventDispatcher.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = LegacyEventDispatcherProxy::decorate($dispatcher);
  22. }
  23. /**
  24. * {@inheritdoc}
  25. *
  26. * @param string|null $eventName
  27. */
  28. public function dispatch($event/*, string $eventName = null*/)
  29. {
  30. $eventName = 1 < \func_num_args() ? func_get_arg(1) : null;
  31. if (is_scalar($event)) {
  32. // deprecated
  33. $swap = $event;
  34. $event = $eventName ?? new Event();
  35. $eventName = $swap;
  36. }
  37. return $this->dispatcher->dispatch($event, $eventName);
  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 getListenerPriority($eventName, $listener)
  78. {
  79. return $this->dispatcher->getListenerPriority($eventName, $listener);
  80. }
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function hasListeners($eventName = null)
  85. {
  86. return $this->dispatcher->hasListeners($eventName);
  87. }
  88. }