Source
* @param string $url The url of the feed being merged in (for error reporting).
<?php
/**
* Handles polling and storage of specs
*/
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
defined( 'ABSPATH' ) || exit;
/**
* Specs data source poller class.
* This handles polling specs from JSON endpoints, and
* stores the specs in to the database as an option.
*/
class DataSourcePoller {
const DATA_SOURCES = array(
'https://woocommerce.com/wp-json/wccom/inbox-notifications/1.0/notifications.json',
);
/**
* The logger instance.
*
* @var WC_Logger|null
*/
protected static $logger = null;
/**
* Get the logger instance.
*
* @return WC_Logger
*/
private static function get_logger() {
if ( is_null( self::$logger ) ) {
self::$logger = wc_get_logger();
}
return self::$logger;
}
/**
* Reads the data sources for specs and persists those specs.
*
* @return bool Whether any specs were read.
*/
public static function read_specs_from_data_sources() {
$specs = array();
// Note that this merges the specs from the data sources based on the
// slug - last one wins.
foreach ( self::DATA_SOURCES as $url ) {
$specs_from_data_source = self::read_data_source( $url, $specs );
self::merge_specs( $specs_from_data_source, $specs, $url );
}
// Persist the specs as an option.
update_option( RemoteInboxNotificationsEngine::SPECS_OPTION_NAME, $specs );
return 0 !== count( $specs );
}
/**
* Read a single data source and return the read specs
*