EventDispatcherInterface.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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. * EventDispatcherInterface describes an event dispatcher class.
  13. *
  14. * @see http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/index.html Apple's Cocoa framework
  15. *
  16. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  17. */
  18. interface EventDispatcherInterface
  19. {
  20. /**
  21. * Connects a listener to a given event name.
  22. *
  23. * Listeners with a higher priority are executed first.
  24. *
  25. * @param string $name An event name
  26. * @param mixed $listener A PHP callable
  27. * @param integer $priority The priority (between -10 and 10 -- defaults to 0)
  28. */
  29. function connect($name, $listener, $priority = 0);
  30. /**
  31. * Disconnects one, or all listeners for the given event name.
  32. *
  33. * @param string $name An event name
  34. * @param mixed|null $listener The listener to remove, or null to remove all
  35. *
  36. * @return void
  37. */
  38. function disconnect($name, $listener = null);
  39. /**
  40. * Notifies all listeners of a given event.
  41. *
  42. * @param EventInterface $event An EventInterface instance
  43. */
  44. function notify(EventInterface $event);
  45. /**
  46. * Notifies all listeners of a given event until one processes the event.
  47. *
  48. * A listener tells the dispatcher that it has processed the event
  49. * by calling the setProcessed() method on it.
  50. *
  51. * It can then return a value that will be forwarded to the caller.
  52. *
  53. * @param EventInterface $event An EventInterface instance
  54. *
  55. * @return mixed The returned value of the listener that processed the event
  56. */
  57. function notifyUntil(EventInterface $event);
  58. /**
  59. * Filters a value by calling all listeners of a given event.
  60. *
  61. * @param EventInterface $event An EventInterface instance
  62. * @param mixed $value The value to be filtered
  63. *
  64. * @return mixed The filtered value
  65. */
  66. function filter(EventInterface $event, $value);
  67. /**
  68. * Returns true if the given event name has some listeners.
  69. *
  70. * @param string $name The event name
  71. *
  72. * @return Boolean true if some listeners are connected, false otherwise
  73. */
  74. function hasListeners($name);
  75. /**
  76. * Returns all listeners associated with a given event name.
  77. *
  78. * @param string $name The event name
  79. *
  80. * @return array An array of listeners
  81. */
  82. function getListeners($name);
  83. }