Classes
The classes a provider is registered with, and the interface its weather forecast adapter implements. Generated from the code of Elio Blocks 1.0.0.
Provider
ElioBlocks\Provider\Provider
An organization Elio gets data from (Open-Meteo, OpenWeatherMap): its name, the credentials it identifies the site with, the credit its data is shown with, and what it serves, one adapter per domain.
Registered with elio_blocks_register_provider(), as is or through a class of its own that passes all of it to this constructor (OpenMeteo).
Since 0.4.0
Provider::__construct()
public function __construct(
public readonly string $slug,
public readonly string $label,
array $credentials = array(),
public readonly ?ProviderAttribution $attribution = null,
public readonly array $adapters = array(),
)
Constructor.
Parameters
$slugstring: Unique identifier (e.g.'open-meteo'): lowercase letters, digits, hyphens.$labelstring: Name shown to people (e.g.'Open-Meteo').$credentialslist<ProviderCredential>: What identifies the site to it, in the order the settings page asks for them.$attributionProviderAttribution|null: Credit its license asks for wherever its data is shown. Null for none.$adapterslist<object>: What it serves, one adapter per domain: aWeatherForecastAdapterInterfacefor the weather forecast. Of two for one domain, the first is asked.
Provider::getAdapter()
final public function getAdapter(string $interface): ?object
Returns its adapter for a domain, or null when it does not serve it.
Parameters
$interfaceclass-string<T>: Interface of the adapters of the domain (WeatherForecastAdapterInterface).
Returns T|null
ProviderCredential
ElioBlocks\Provider\ProviderCredential
A value a provider needs to identify the site: an API key, an account name and its password, a contact address. The settings page asks for it, in the card of its provider, and the provider gets it when it fetches data.
Since 0.4.0
ProviderCredential::__construct()
public function __construct(
public readonly string $name,
public readonly string $label,
public readonly string $description = '',
public readonly bool $required = false,
public readonly bool $secret = false,
)
Constructor.
Parameters
$namestring: Identifier, unique within its provider: lowercase letters, digits and underscores. It names the constantELIO_BLOCKS_{SLUG}_{NAME}.$labelstring: Name shown to people.$descriptionstring: What it is for, shown under the field (plain text). Empty for none.$requiredbool: Whether the provider cannot answer without it.$secretbool: Whether it is typed hidden and never sent back to the browser.
ProviderAttribution
ElioBlocks\Provider\ProviderAttribution
The credit a provider asks for wherever its data is shown, as its license requires (Open-Meteo: a link to its site and to CC BY 4.0). The provider-attribution block prints it at the bottom of each report: its own sentence, the label of the provider linked to its site.
Since 0.4.0
ProviderAttribution::__construct()
public function __construct(
public readonly string $url,
public readonly string $license = '',
public readonly string $licenseUrl = '',
)
Constructor.
Parameters
$urlstring: Site of the provider, which its label links to.$licensestring: Name of the license of its data (e.g. 'CC BY 4.0'). Empty for none.$licenseUrlstring: Page of that license. Empty for none.
WeatherForecastAdapterInterface
ElioBlocks\WeatherForecast\WeatherForecastAdapterInterface
How a provider serves the weather forecast.
One of the adapters a provider is registered with (elio_blocks_register_provider()): the provider holds the name, the credentials and the attribution, this fetches its weather forecast.
Since 0.4.0: Replaces WeatherForecastProviderInterface, which elio_blocks_register_weather_forecast_provider() registered.
WeatherForecastAdapterInterface::fetch()
public function fetch(float $latitude, float $longitude, string $units, array $args = array()): array
Fetches weather forecast data for the given coordinates.
$args holds:
'credentials'(array<string, string>): the credentials the provider declared (elio_blocks_register_provider()) that are set, by name; one not set is absent. Each comes from itsELIO_BLOCKS_{SLUG}_{NAME}constant (wp-config.php, uppercased, hyphens as underscores) when defined, else from the settings page. When a required one is not set,fetch()is not called.
Parameters
$latitudefloat: Latitude.$longitudefloat: Longitude.$unitsstring: Unit system ('metric'|'imperial').$argsarray<string, mixed>: Request arguments, see above.
Returns array<string, mixed>: Normalized weather forecast data.
Throws
\ElioBlocks\WeatherForecast\Exception\ProviderUnavailable: Network failure, timeout, HTTP error.\ElioBlocks\WeatherForecast\Exception\InvalidProviderResponse: The answer is not a weather forecast.