-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginConfig.php
55 lines (43 loc) · 1.15 KB
/
PluginConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace GMTA\Velocita\Composer\Config;
use RuntimeException;
use function filter_var;
use function rtrim;
use const FILTER_VALIDATE_URL;
class PluginConfig
{
protected bool $enabled = false;
protected ?string $url;
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}
public function getURL(): ?string
{
return $this->url;
}
public function setURL(?string $url): void
{
if ($url === null) {
$this->url = null;
} else {
$this->url = rtrim($url, '/');
}
}
public function validate(): void
{
// If set, the URL must be valid
if (($this->url !== null) && !filter_var($this->url, FILTER_VALIDATE_URL)) {
throw new RuntimeException('Invalid URL was set for this plugin');
}
// If enabled, a URL must also be set
if ($this->enabled && ($this->url === null)) {
throw new RuntimeException('A URL must be set for this plugin to be enabled');
}
}
}