You are here

public function Provider::__construct in Drupal 8

Same name and namespace in other branches
  1. 9 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) {
  if (!UrlHelper::isValid($url, TRUE) || !UrlHelper::isExternal($url)) {
    throw new ProviderException('Provider @name does not define a valid external URL.', $this);
  }
  $this->name = $name;
  $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);
  }
}