1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Apie\OpenapiSchema\Spec; |
5
|
|
|
|
6
|
|
|
use Apie\CommonValueObjects\Url; |
7
|
|
|
use Apie\OpenapiSchema\Concerns\CompositeValueObjectWithExtension; |
8
|
|
|
use Apie\OpenapiSchema\Exceptions\MissingPlaceholderVariables; |
9
|
|
|
use Apie\OpenapiSchema\Map\ServerVariableObjectList; |
10
|
|
|
use Apie\OpenapiSchema\ValueObjects\UrlsWithPlaceholders; |
11
|
|
|
use Apie\ValueObjects\ValueObjectCompareInterface; |
12
|
|
|
use Apie\ValueObjects\ValueObjectInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @see https://swagger.io/specification/#server-object |
16
|
|
|
*/ |
17
|
|
|
class Server implements ValueObjectInterface |
18
|
|
|
{ |
19
|
|
|
use CompositeValueObjectWithExtension; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var UrlsWithPlaceholders |
23
|
|
|
*/ |
24
|
|
|
private $url; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string|null |
28
|
|
|
*/ |
29
|
|
|
private $description; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ServerVariableObjectList|null |
33
|
|
|
*/ |
34
|
|
|
private $variables; |
35
|
|
|
|
36
|
|
|
public function __construct(UrlsWithPlaceholders $url) |
37
|
|
|
{ |
38
|
|
|
$this->url = $url; |
39
|
|
|
$this->validateProperties(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getUrl(): UrlsWithPlaceholders |
43
|
|
|
{ |
44
|
|
|
return $this->url; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return string|null |
49
|
|
|
*/ |
50
|
|
|
public function getDescription(): ?string |
51
|
|
|
{ |
52
|
|
|
return $this->description; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return ServerVariableObjectList|null |
57
|
|
|
*/ |
58
|
|
|
public function getVariables(): ?ServerVariableObjectList |
59
|
|
|
{ |
60
|
|
|
return $this->variables; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function validateProperties(): void |
64
|
|
|
{ |
65
|
|
|
$placeholders = $this->url->getPlaceholders(); |
66
|
|
|
if (!$this->variables && $placeholders) { |
67
|
|
|
throw new MissingPlaceholderVariables($placeholders); |
68
|
|
|
} |
69
|
|
|
$missing = []; |
70
|
|
|
foreach ($placeholders as $placeholder) { |
71
|
|
|
if (!isset($this->variables[$placeholder])) { |
72
|
|
|
$missing[] = $placeholder; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
if (!empty($missing)) { |
76
|
|
|
throw new MissingPlaceholderVariables($missing); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |