RemoteInboxNotificationsDataSourcePoller
extends DataSourcePoller
in package
Specs data source poller class.
This handles polling specs from JSON endpoints, and stores the specs in to the database as an option.
Table of Contents
- DATA_SOURCES = array()
- Default data sources array.
- FILTER_NAME = 'data_source_poller_data_sources'
- Name of data sources filter.
- FILTER_NAME_SPECS = 'data_source_poller_specs'
- Name of data source specs filter.
- ID = 'remote_inbox_notifications'
- PUBLISHED_SNAPSHOT_TRANSIENT = 'woocommerce_admin_remote_inbox_notifications_published_snapshot'
- Transient holding the latest read's fetch time and published slugs, or null slugs for an inconclusive read.
- $args : array<string|int, mixed>
- Default args.
- $data_sources : array<string|int, mixed>
- Default data sources array.
- $id : string
- Id of DataSourcePoller.
- $instance : RemoteInboxNotificationsDataSourcePoller
- Class instance.
- $logger : WC_Logger|null
- The logger instance.
- $published_slugs : array<string|int, string>|null
- Published identities from this read's canonical response, or null when it is not authoritative.
- __construct() : mixed
- Constructor.
- delete_specs_transient() : bool
- Delete the specs transient.
- get_cached_specs() : array<string|int, mixed>
- Gets specs from cache if it exists.
- get_data_sources() : array<string|int, mixed>
- Get data sources.
- get_instance() : mixed
- Get class instance.
- get_specs_from_data_sources() : array<string|int, mixed>
- Reads the data sources for specs and persists those specs.
- read_specs_from_data_sources() : bool
- Read the data sources and record the identities published by the canonical WooCommerce.com feed.
- set_specs_transient() : mixed
- Set the specs transient.
- get_logger() : WC_Logger
- Get the logger instance.
- get_spec_key() : string|bool
- Returns the key identifier of spec, this can easily be overwritten. Defaults to id.
- merge_specs() : void
- Merge runnable specs and track canonical publication identities independently of validation.
- read_data_source() : array<string|int, mixed>
- Read a single data source and return the read specs
- validate_spec() : bool
- Validate the spec.
- save_published_snapshot() : void
- Store a read's publication evidence unless a newer read is already stored.
- validate_action() : bool
- Validate the action.
Constants
DATA_SOURCES
Default data sources array.
public
mixed
DATA_SOURCES
= array()
Tags
FILTER_NAME
Name of data sources filter.
public
mixed
FILTER_NAME
= 'data_source_poller_data_sources'
FILTER_NAME_SPECS
Name of data source specs filter.
public
mixed
FILTER_NAME_SPECS
= 'data_source_poller_specs'
ID
public
mixed
ID
= 'remote_inbox_notifications'
PUBLISHED_SNAPSHOT_TRANSIENT
Transient holding the latest read's fetch time and published slugs, or null slugs for an inconclusive read.
private
mixed
PUBLISHED_SNAPSHOT_TRANSIENT
= 'woocommerce_admin_remote_inbox_notifications_published_snapshot'
Properties
$args
Default args.
protected
array<string|int, mixed>
$args
= array()
$data_sources
Default data sources array.
protected
array<string|int, mixed>
$data_sources
= array()
$id
Id of DataSourcePoller.
protected
string
$id
= array()
$instance
Class instance.
protected
static RemoteInboxNotificationsDataSourcePoller
$instance
= null
$logger
The logger instance.
protected
static WC_Logger|null
$logger
= null
$published_slugs
Published identities from this read's canonical response, or null when it is not authoritative.
private
array<string|int, string>|null
$published_slugs
= null
Methods
__construct()
Constructor.
public
__construct(string $id[, array<string|int, mixed> $data_sources = array() ][, array<string|int, mixed> $args = array() ]) : mixed
Parameters
- $id : string
-
id of DataSourcePoller.
- $data_sources : array<string|int, mixed> = array()
-
urls for data sources.
- $args : array<string|int, mixed> = array()
-
Options for DataSourcePoller.
Return values
mixed —delete_specs_transient()
Delete the specs transient.
public
delete_specs_transient() : bool
Return values
bool — success of failure of transient deletion.get_cached_specs()
Gets specs from cache if it exists.
public
get_cached_specs() : array<string|int, mixed>
Return values
array<string|int, mixed> — list of specs.get_data_sources()
Get data sources.
public
static get_data_sources() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_instance()
Get class instance.
public
static get_instance() : mixed
Return values
mixed —get_specs_from_data_sources()
Reads the data sources for specs and persists those specs.
public
get_specs_from_data_sources() : array<string|int, mixed>
Return values
array<string|int, mixed> — list of specs.read_specs_from_data_sources()
Read the data sources and record the identities published by the canonical WooCommerce.com feed.
public
read_specs_from_data_sources() : bool
Invalid specs with usable slugs still count as published. An inconclusive response retains only its timestamp to reject older reads.
Tags
Return values
bool — Whether any specs were read.set_specs_transient()
Set the specs transient.
public
set_specs_transient(array<string|int, mixed> $specs, int $expiration) : mixed
Parameters
- $specs : array<string|int, mixed>
-
The specs to set in the transient.
- $expiration : int
-
The expiration time for the transient.
Return values
mixed —get_logger()
Get the logger instance.
protected
static get_logger() : WC_Logger
Return values
WC_Logger —get_spec_key()
Returns the key identifier of spec, this can easily be overwritten. Defaults to id.
protected
get_spec_key(mixed $spec) : string|bool
Parameters
- $spec : mixed
-
a JSON parsed spec coming from the JSON feed.
Return values
string|bool —merge_specs()
Merge runnable specs and track canonical publication identities independently of validation.
protected
merge_specs(array<string|int, mixed> $specs_to_merge_in, array<string|int, mixed> &$specs, string $url) : void
Parameters
- $specs_to_merge_in : array<string|int, mixed>
-
The specs to merge in to $specs.
- $specs : array<string|int, mixed>
-
The list of specs being merged into.
- $url : string
-
The url of the feed being merged in.
Tags
Return values
void —read_data_source()
Read a single data source and return the read specs
protected
static read_data_source(string $url) : array<string|int, mixed>
Parameters
- $url : string
-
The URL to read the specs from.
Return values
array<string|int, mixed> — The specs that have been read from the data source.validate_spec()
Validate the spec.
protected
validate_spec(object $spec, string $url) : bool
Parameters
- $spec : object
-
The spec to validate.
- $url : string
-
The url of the feed that provided the spec.
Return values
bool — The result of the validation.save_published_snapshot()
Store a read's publication evidence unless a newer read is already stored.
private
save_published_snapshot(int $fetched_at, array<string|int, string>|null $slugs) : void
Parameters
- $fetched_at : int
-
When the read started.
- $slugs : array<string|int, string>|null
-
Published slugs, or null for an inconclusive read.
Return values
void —validate_action()
Validate the action.
private
validate_action(object $action, string $url) : bool
Parameters
- $action : object
-
The action to validate.
- $url : string
-
The url of the feed containing the action (for error reporting).
