Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / media / src / OEmbed / Provider.php
1 <?php
2
3 namespace Drupal\media\OEmbed;
4
5 use Drupal\Component\Utility\UrlHelper;
6
7 /**
8  * Value object for oEmbed providers.
9  */
10 class Provider {
11
12   /**
13    * The provider name.
14    *
15    * @var string
16    */
17   protected $name;
18
19   /**
20    * The provider URL.
21    *
22    * @var string
23    */
24   protected $url;
25
26   /**
27    * The provider endpoints.
28    *
29    * @var \Drupal\media\OEmbed\Endpoint[]
30    */
31   protected $endpoints = [];
32
33   /**
34    * Provider constructor.
35    *
36    * @param string $name
37    *   The provider name.
38    * @param string $url
39    *   The provider URL.
40    * @param array[] $endpoints
41    *   List of endpoints this provider exposes.
42    *
43    * @throws \Drupal\media\OEmbed\ProviderException
44    */
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);
48     }
49
50     $this->name = $name;
51     $this->url = $url;
52
53     try {
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']);
57       }
58     }
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.
63     }
64
65     if (empty($this->endpoints)) {
66       throw new ProviderException('Provider @name does not define any valid endpoints.', $this);
67     }
68   }
69
70   /**
71    * Returns the provider name.
72    *
73    * @return string
74    *   Name of the provider.
75    */
76   public function getName() {
77     return $this->name;
78   }
79
80   /**
81    * Returns the provider URL.
82    *
83    * @return string
84    *   URL of the provider.
85    */
86   public function getUrl() {
87     return $this->url;
88   }
89
90   /**
91    * Returns the provider endpoints.
92    *
93    * @return \Drupal\media\OEmbed\Endpoint[]
94    *   List of endpoints this provider exposes.
95    */
96   public function getEndpoints() {
97     return $this->endpoints;
98   }
99
100 }