Skip to content

Commit 79f7a04

Browse files
authored
Merge pull request #102 from stellarwp/fix/di52-compatible-events
Keep di52 compatibility
2 parents c311c04 + 3ef4050 commit 79f7a04

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/Telemetry/Events/Event_Subscriber.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
*/
2222
class Event_Subscriber extends Abstract_Subscriber {
2323

24+
/**
25+
* @var array
26+
*/
27+
private static $events = [];
28+
2429
/**
2530
* @inheritDoc
2631
*
@@ -46,19 +51,11 @@ public function register() {
4651
* @return void
4752
*/
4853
public function cache_event( $name, $data ) {
49-
$events = [];
50-
51-
if ( $this->container->has( 'events' ) ) {
52-
$events = $this->container->get( 'events' );
53-
}
54-
55-
$events[] = [
54+
self::$events[] = [
5655
'name' => $name,
5756
'data' => wp_json_encode( $data ),
5857
'stellar_slug' => Config::get_stellar_slug(),
5958
];
60-
61-
$this->container->bind( 'events', $events );
6259
}
6360

6461
/**
@@ -69,7 +66,7 @@ public function cache_event( $name, $data ) {
6966
* @return void
7067
*/
7168
public function send_cached_events() {
72-
if ( ! $this->container->has( 'events' ) ) {
69+
if ( empty( self::$events ) ) {
7370
return;
7471
}
7572

@@ -82,12 +79,12 @@ public function send_cached_events() {
8279
'sslverify' => false,
8380
'body' => [
8481
'action' => Event::AJAX_ACTION,
85-
'events' => $this->container->get( 'events' ),
82+
'events' => self::$events,
8683
],
8784
]
8885
);
8986

90-
$this->container->bind( 'events', [] );
87+
self::$events = [];
9188
}
9289

9390
/**
@@ -101,6 +98,10 @@ public function send_events() {
10198
// Get the passed event array.
10299
$events = filter_input( INPUT_POST, 'events', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); // phpcs:ignore WordPressVIPMinimum.Security.PHPFilterFunctions.RestrictedFilter
103100

104-
$this->container->get( Event::class )->send_batch( $events );
101+
if ( empty( $events ) ) {
102+
return;
103+
}
104+
105+
$this->container->get( Event::class )->send_batch( (array) $events );
105106
}
106107
}

0 commit comments

Comments
 (0)