1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package s9e\TextFormatter |
5
|
|
|
* @copyright Copyright (c) The s9e authors |
6
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator\SiteHelpers; |
9
|
|
|
|
10
|
|
|
use function array_keys, strtolower; |
11
|
|
|
|
12
|
|
|
abstract class AbstractConfigurableHostHelper extends AbstractSiteHelper |
13
|
|
|
{ |
14
|
|
|
public function addHost(string $host): void |
15
|
|
|
{ |
16
|
|
|
$this->addHosts([$host]); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function addHosts(array $hosts): void |
20
|
|
|
{ |
21
|
|
|
$siteId = $this->getSiteId(); |
22
|
|
|
if (!isset($this->configurator->registeredVars['MediaEmbed.sites'][$siteId])) |
23
|
|
|
{ |
24
|
|
|
$this->configurator->MediaEmbed->add($siteId); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
foreach ($hosts as $host) |
28
|
|
|
{ |
29
|
|
|
$host = strtolower($host); |
30
|
|
|
$this->configurator->registeredVars['MediaEmbed.hosts'][$host] = $siteId; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Generate a regexp that |
36
|
|
|
*/ |
37
|
|
|
public function getHostRegexp(): string |
38
|
|
|
{ |
39
|
|
|
} |
|
|
|
|
40
|
|
|
|
41
|
|
|
abstract protected function getSiteId(): string; |
42
|
|
|
|
43
|
|
|
public function setHosts(array $hosts): void |
44
|
|
|
{ |
45
|
|
|
$siteId = $this->getSiteId(); |
46
|
|
|
if (!isset($this->configurator->registeredVars['MediaEmbed.sites'][$siteId])) |
47
|
|
|
{ |
48
|
|
|
$this->configurator->MediaEmbed->add($siteId); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Remove previously set hosts for this site |
52
|
|
|
$unsetHosts = array_keys( |
53
|
|
|
(array) $this->configurator->registeredVars['MediaEmbed.hosts'], |
54
|
|
|
$siteId, |
55
|
|
|
true |
56
|
|
|
); |
57
|
|
|
foreach ($unsetHosts as $host) |
58
|
|
|
{ |
59
|
|
|
unset($this->configurator->registeredVars['MediaEmbed.hosts'][$host]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->addHosts($hosts); |
63
|
|
|
} |
64
|
|
|
} |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: