function Provider::__construct

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

Provider constructor.

Parameters

string $name: The provider name.

string $url: The provider URL.

array[] $endpoints: List of endpoints this provider exposes.

Throws

\Drupal\media\OEmbed\ProviderException

File

core/modules/media/src/OEmbed/Provider.php, line 45

Class

Provider
Value object for oEmbed providers.

Namespace

Drupal\media\OEmbed

Code

public function __construct($name, $url, array $endpoints) {
    $this->name = $name;
    if (!UrlHelper::isValid($url, TRUE) || !UrlHelper::isExternal($url)) {
        throw new ProviderException('Provider @name does not define a valid external URL.', $this);
    }
    $this->url = $url;
    try {
        foreach ($endpoints as $endpoint) {
            $endpoint += [
                'formats' => [],
                'schemes' => [],
                'discovery' => FALSE,
            ];
            $this->endpoints[] = new Endpoint($endpoint['url'], $this, $endpoint['schemes'], $endpoint['formats'], $endpoint['discovery']);
        }
    } catch (\InvalidArgumentException $e) {
        // Just skip all the invalid endpoints.
        // @todo Log the exception message to help with debugging in
        // https://www.drupal.org/project/drupal/issues/2972846.
    }
    if (empty($this->endpoints)) {
        throw new ProviderException('Provider @name does not define any valid endpoints.', $this);
    }
}

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