3 namespace Drupal\media\OEmbed;
5 use Drupal\Component\Utility\UrlHelper;
8 * Value object for oEmbed providers.
27 * The provider endpoints.
29 * @var \Drupal\media\OEmbed\Endpoint[]
31 protected $endpoints = [];
34 * Provider constructor.
40 * @param array[] $endpoints
41 * List of endpoints this provider exposes.
43 * @throws \Drupal\media\OEmbed\ProviderException
45 public function __construct($name, $url, array $endpoints) {
46 if (!UrlHelper::isValid($url, TRUE) || !UrlHelper::isExternal($url)) {
47 throw new ProviderException('Provider @name does not define a valid external URL.', $this);
54 foreach ($endpoints as $endpoint) {
55 $endpoint += ['formats' => [], 'schemes' => [], 'discovery' => FALSE];
56 $this->endpoints[] = new Endpoint($endpoint['url'], $this, $endpoint['schemes'], $endpoint['formats'], $endpoint['discovery']);
59 catch (\InvalidArgumentException $e) {
60 // Just skip all the invalid endpoints.
61 // @todo Log the exception message to help with debugging in
62 // https://www.drupal.org/project/drupal/issues/2972846.
65 if (empty($this->endpoints)) {
66 throw new ProviderException('Provider @name does not define any valid endpoints.', $this);
71 * Returns the provider name.
74 * Name of the provider.
76 public function getName() {
81 * Returns the provider URL.
84 * URL of the provider.
86 public function getUrl() {
91 * Returns the provider endpoints.
93 * @return \Drupal\media\OEmbed\Endpoint[]
94 * List of endpoints this provider exposes.
96 public function getEndpoints() {
97 return $this->endpoints;