function Endpoint::__construct

Same name in other branches
  1. 9 core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::__construct()
  2. 8.9.x core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::__construct()
  3. 11.x core/modules/media/src/OEmbed/Endpoint.php \Drupal\media\OEmbed\Endpoint::__construct()

Endpoint constructor.

Parameters

string $url: The endpoint URL. May contain a

'{format}';

placeholder.

\Drupal\media\OEmbed\Provider $provider: The provider this endpoint belongs to.

string[] $schemes: List of URL schemes supported by the provider.

string[] $formats: List of supported formats. Can be "json", "xml" or both.

bool $supports_discovery: Whether the provider supports oEmbed discovery.

Throws

\InvalidArgumentException If the endpoint URL is empty.

File

core/modules/media/src/OEmbed/Endpoint.php, line 70

Class

Endpoint
Value object for oEmbed provider endpoints.

Namespace

Drupal\media\OEmbed

Code

public function __construct($url, Provider $provider, array $schemes = [], array $formats = [], $supports_discovery = FALSE) {
    $this->provider = $provider;
    $this->schemes = $schemes;
    $this->formats = $formats = array_map('mb_strtolower', $formats);
    // Assert that only the supported formats are present.
    assert(array_diff($formats, [
        'json',
        'xml',
    ]) == []);
    // Use the first provided format to build the endpoint URL. If no formats
    // are provided, default to JSON.
    $this->url = str_replace('{format}', reset($this->formats) ?: 'json', $url);
    if (!UrlHelper::isValid($this->url, TRUE) || !UrlHelper::isExternal($this->url)) {
        throw new \InvalidArgumentException('oEmbed endpoint must have a valid external URL');
    }
    $this->supportsDiscovery = (bool) $supports_discovery;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.