WooCommerce Code Reference

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

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.

Constants

Properties

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

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()

Reads the data sources for specs and persists those specs.

public read_specs_from_data_sources() : bool
Return values
boolWhether 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_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
boolThe result of the validation.