PluginProbe
Auto Alt Text / trunk
Auto Alt Text vtrunk
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / src / App / Events / EventDispatcherInterface.php

EventDispatcherInterface.php in Auto Alt Text trunk, at src/App/Events/EventDispatcherInterface.php

68 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AATXT\App\Events;
4
5 /**
6 * Interface for event dispatching.
7 *
8 * This interface defines the contract for an event dispatcher that allows
9 * decoupled communication between components through events and listeners.
10 *
11 * The event system follows the Observer pattern, allowing components to:
12 * - Dispatch events when something significant happens
13 * - Register listeners to react to specific events
14 * - Maintain loose coupling between event producers and consumers
15 *
16 * @package AATXT\App\Events
17 */
18 interface EventDispatcherInterface
19 {
20 /**
21 * Dispatch an event to all registered listeners.
22 *
23 * All listeners registered for the event's class will be called
24 * in the order they were registered.
25 *
26 * @param object $event The event object to dispatch
27 * @return object The same event object (allows for event modification by listeners)
28 */
29 public function dispatch(object $event): object;
30
31 /**
32 * Register a listener for a specific event class.
33 *
34 * The listener will be called whenever an event of the specified class
35 * (or a subclass) is dispatched.
36 *
37 * @param string $eventClass The fully-qualified class name of the event to listen for
38 * @param callable $listener The listener callback, receives the event as first argument
39 * @return void
40 */
41 public function listen(string $eventClass, callable $listener): void;
42
43 /**
44 * Remove a listener for a specific event class.
45 *
46 * @param string $eventClass The event class
47 * @param callable $listener The listener to remove
48 * @return bool True if the listener was found and removed
49 */
50 public function removeListener(string $eventClass, callable $listener): bool;
51
52 /**
53 * Get all listeners for a specific event class.
54 *
55 * @param string $eventClass The event class
56 * @return array<callable> Array of registered listeners
57 */
58 public function getListeners(string $eventClass): array;
59
60 /**
61 * Check if there are any listeners for a specific event class.
62 *
63 * @param string $eventClass The event class
64 * @return bool True if there are registered listeners
65 */
66 public function hasListeners(string $eventClass): bool;
67 }
68