EventManagerInterface.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.6.0
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Event;
  15. /**
  16. * Interface EventManagerInterface
  17. */
  18. interface EventManagerInterface
  19. {
  20. /**
  21. * Adds a new listener to an event.
  22. *
  23. * A variadic interface to add listeners that emulates jQuery.on().
  24. *
  25. * Binding an EventListenerInterface:
  26. *
  27. * ```
  28. * $eventManager->on($listener);
  29. * ```
  30. *
  31. * Binding with no options:
  32. *
  33. * ```
  34. * $eventManager->on('Model.beforeSave', $callable);
  35. * ```
  36. *
  37. * Binding with options:
  38. *
  39. * ```
  40. * $eventManager->on('Model.beforeSave', ['priority' => 90], $callable);
  41. * ```
  42. *
  43. * @param string|\Cake\Event\EventListenerInterface|null $eventKey The event unique identifier name
  44. * with which the callback will be associated. If $eventKey is an instance of
  45. * Cake\Event\EventListenerInterface its events will be bound using the `implementedEvents` methods.
  46. *
  47. * @param array|callable $options Either an array of options or the callable you wish to
  48. * bind to $eventKey. If an array of options, the `priority` key can be used to define the order.
  49. * Priorities are treated as queues. Lower values are called before higher ones, and multiple attachments
  50. * added to the same priority queue will be treated in the order of insertion.
  51. *
  52. * @param callable|null $callable The callable function you want invoked.
  53. *
  54. * @return $this
  55. * @throws \InvalidArgumentException When event key is missing or callable is not an
  56. * instance of Cake\Event\EventListenerInterface.
  57. */
  58. public function on($eventKey = null, $options = [], $callable = null);
  59. /**
  60. * Remove a listener from the active listeners.
  61. *
  62. * Remove a EventListenerInterface entirely:
  63. *
  64. * ```
  65. * $manager->off($listener);
  66. * ```
  67. *
  68. * Remove all listeners for a given event:
  69. *
  70. * ```
  71. * $manager->off('My.event');
  72. * ```
  73. *
  74. * Remove a specific listener:
  75. *
  76. * ```
  77. * $manager->off('My.event', $callback);
  78. * ```
  79. *
  80. * Remove a callback from all events:
  81. *
  82. * ```
  83. * $manager->off($callback);
  84. * ```
  85. *
  86. * @param string|\Cake\Event\EventListenerInterface $eventKey The event unique identifier name
  87. * with which the callback has been associated, or the $listener you want to remove.
  88. * @param callable|null $callable The callback you want to detach.
  89. * @return $this
  90. */
  91. public function off($eventKey, $callable = null);
  92. /**
  93. * Dispatches a new event to all configured listeners
  94. *
  95. * @param string|\Cake\Event\EventInterface $event The event key name or instance of EventInterface.
  96. * @return \Cake\Event\EventInterface
  97. * @triggers $event
  98. */
  99. public function dispatch($event);
  100. /**
  101. * Returns a list of all listeners for an eventKey in the order they should be called
  102. *
  103. * @param string $eventKey Event key.
  104. * @return array
  105. */
  106. public function listeners($eventKey);
  107. }