Skip to main content

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

Source

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

  • $slug string: Unique identifier (e.g. 'open-meteo'): lowercase letters, digits, hyphens.
  • $label string: Name shown to people (e.g. 'Open-Meteo').
  • $credentials list<ProviderCredential>: What identifies the site to it, in the order the settings page asks for them.
  • $attribution ProviderAttribution|null: Credit its license asks for wherever its data is shown. Null for none.
  • $adapters list<object>: What it serves, one adapter per domain: a WeatherForecastAdapterInterface for the weather forecast. Of two for one domain, the first is asked.

Source

Provider::getAdapter()​

final public function getAdapter(string $interface): ?object

Returns its adapter for a domain, or null when it does not serve it.

Parameters

  • $interface class-string<T>: Interface of the adapters of the domain (WeatherForecastAdapterInterface).

Returns T|null

Source

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

Source

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

  • $name string: Identifier, unique within its provider: lowercase letters, digits and underscores. It names the constant ELIO_BLOCKS_{SLUG}_{NAME}.
  • $label string: Name shown to people.
  • $description string: What it is for, shown under the field (plain text). Empty for none.
  • $required bool: Whether the provider cannot answer without it.
  • $secret bool: Whether it is typed hidden and never sent back to the browser.

Source

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

Source

ProviderAttribution::__construct()​

public function __construct(
public readonly string $url,
public readonly string $license = '',
public readonly string $licenseUrl = '',
)

Constructor.

Parameters

  • $url string: Site of the provider, which its label links to.
  • $license string: Name of the license of its data (e.g. 'CC BY 4.0'). Empty for none.
  • $licenseUrl string: Page of that license. Empty for none.

Source

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.

Source

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 its ELIO_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

  • $latitude float: Latitude.
  • $longitude float: Longitude.
  • $units string: Unit system ('metric'|'imperial').
  • $args array<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.

Source