55namespace WPGraphQL \Logging \Events ;
66
77/**
8- * Simple pub /sub Event Manager for WPGraphQL Logging
8+ * Pub /sub Event Manager for WPGraphQL Logging.
99 *
10- * Provides a lightweight event bus with optional WordPress bridge.
10+ * This class provides a lightweight event bus with a WordPress bridge.
1111 *
12- * Users can:
13- * - subscribe to events using subscribe()
14- * - publish events using publish()
15- * - also listen via WordPress hooks: `wpgraphql_logging_event_{event_name}`
12+ * Users can subscribe to events using subscribe() and publish events using publish().
13+ * They can also listen via WordPress hooks: `wpgraphql_logging_event_{event_name}`.
14+ *
15+ * @package WPGraphQL\Logging
16+ *
17+ * @since 0.0.1
1618 */
1719final class EventManager {
1820 /**
19- * In-memory map of event name to priority to listeners .
21+ * Events that can be subscribed to.
2022 *
2123 * @var array<string, array<int, array<int, callable>>>
2224 */
23- private static array $ events = [];
25+ protected static array $ events = [];
2426
2527 /**
26- * Transform listeners that can modify a payload.
28+ * Transformers that can modify an event's payload.
2729 *
2830 * @var array<string, array<int, array<int, callable>>>
2931 */
@@ -52,13 +54,14 @@ public static function subscribe(string $event_name, callable $listener, int $pr
5254 *
5355 * @param string $event_name Event name (see Events constants).
5456 * @param array<string, mixed> $payload Arbitrary payload for listeners.
57+ *
58+ * @psalm-suppress HookNotFound
5559 */
5660 public static function publish (string $ event_name , array $ payload = []): void {
5761
5862 $ ordered_listeners = self ::get_ordered_listeners ( $ event_name );
5963
6064 if ( [] === $ ordered_listeners ) {
61- /** @psalm-suppress HookNotFound */
6265 do_action ( 'wpgraphql_logging_event_ ' . $ event_name , $ payload );
6366 return ;
6467 }
@@ -67,7 +70,6 @@ public static function publish(string $event_name, array $payload = []): void {
6770 self ::invoke_listener ( $ listener , $ payload );
6871 }
6972
70- /** @psalm-suppress HookNotFound */
7173 do_action ( 'wpgraphql_logging_event_ ' . $ event_name , $ payload );
7274 }
7375
@@ -95,21 +97,21 @@ public static function subscribe_to_transform(string $event_name, callable $tran
9597 * @param string $event_name Event name.
9698 * @param array<string, mixed> $payload Initial payload.
9799 *
100+ * @psalm-suppress HookNotFound
101+ *
98102 * @return array<string, mixed> Modified payload.
99103 */
100104 public static function transform (string $ event_name , array $ payload ): array {
101105
102106 $ ordered_transforms = self ::get_ordered_transforms ( $ event_name );
103107 if ( [] === $ ordered_transforms ) {
104- /** @psalm-suppress HookNotFound */
105108 return apply_filters ( 'wpgraphql_logging_filter_ ' . $ event_name , $ payload );
106109 }
107110
108111 foreach ( $ ordered_transforms as $ transform ) {
109112 $ payload = self ::invoke_transform ( $ transform , $ payload );
110113 }
111114
112- /** @psalm-suppress HookNotFound */
113115 return apply_filters ( 'wpgraphql_logging_filter_ ' . $ event_name , $ payload );
114116 }
115117
0 commit comments