Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep di52 compatibility #102

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/Telemetry/Events/Event_Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
*/
class Event_Subscriber extends Abstract_Subscriber {

/**
* Holds the events in a non-persistent way.
*
* @since 2.3.1
*
* @var array
*/
private static $events = [];
Camwyn marked this conversation as resolved.
Show resolved Hide resolved

/**
* @inheritDoc
*
Expand Down Expand Up @@ -48,17 +57,13 @@
public function cache_event( $name, $data ) {
$events = [];

if ( $this->container->has( 'events' ) ) {
$events = $this->container->get( 'events' );
}

$events[] = [
self::$events[] = [
'name' => $name,
'data' => wp_json_encode( $data ),
'stellar_slug' => Config::get_stellar_slug(),
];

$this->container->bind( 'events', $events );
self::$events = $events;
}

/**
Expand All @@ -69,7 +74,7 @@
* @return void
*/
public function send_cached_events() {
if ( ! $this->container->has( 'events' ) ) {
if ( empty( self::$events ) ) {
return;
}

Expand All @@ -82,12 +87,12 @@
'sslverify' => false,
'body' => [
'action' => Event::AJAX_ACTION,
'events' => $this->container->get( 'events' ),
'events' => self::$events,
],
]
);

$this->container->bind( 'events', [] );
self::$events = [];
}

/**
Expand All @@ -101,6 +106,14 @@
// Get the passed event array.
$events = filter_input( INPUT_POST, 'events', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); // phpcs:ignore WordPressVIPMinimum.Security.PHPFilterFunctions.RestrictedFilter

if ( empty( $events ) ) {
return;
}

if ( ! is_array( $events ) ) {

Check failure on line 113 in src/Telemetry/Events/Event_Subscriber.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to function is_array() with non-empty-array<string> will always evaluate to true.
$events = (array) $events;
}

$this->container->get( Event::class )->send_batch( $events );
borkweb marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading