DataSourcePoller
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.
Tags
Table of Contents
- 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.
- $args : array<string|int, mixed>
- Default args.
- $data_sources : array<string|int, mixed>
- Default data sources array.
- $id : string
- Id of DataSourcePoller.
- $logger : WC_Logger|null
- The logger instance.
- __construct() : mixed
- Constructor.
- delete_specs_transient() : bool
- Delete the specs transient.
- 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
- Reads the data sources for specs and persists those specs.
- 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() : mixed
- Merge the specs.
- read_data_source() : array<string|int, mixed>
- Read a single data source and return the read specs
- validate_spec() : bool
- Validate the spec.
- log_deprecation() : mixed
- Log a deprecation to the error log.
Constants
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'
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()
$logger
The logger instance.
protected
static WC_Logger|null
$logger
= 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
Tags
Return values
bool — success of failure of transient deletion.get_instance()
Get class instance.
public
abstract 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>
Tags
Return values
array<string|int, mixed> — list of specs.read_specs_from_data_sources()
Reads the data sources for specs and persists those specs.
public
read_specs_from_data_sources() : bool
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.
Tags
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 the specs.
protected
merge_specs(array<string|int, mixed> $specs_to_merge_in, array<string|int, mixed> &$specs, string $url) : mixed
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 (for error reporting).
Return values
mixed —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.log_deprecation()
Log a deprecation to the error log.
private
static log_deprecation() : mixed