1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Aweapi\Openapi\Objects; |
6
|
|
|
|
7
|
|
|
use Aweapi\Openapi\Extensions; |
8
|
|
|
use Aweapi\Openapi\ValueObject; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
|
11
|
|
|
final class Link extends ValueObject implements LinkAggregate |
12
|
|
|
{ |
13
|
|
|
use Properties\OptionalDescription; |
14
|
|
|
use Properties\OptionalExtensions; |
15
|
|
|
|
16
|
|
|
private $operationId; |
17
|
|
|
|
18
|
|
|
private $operationRef; |
19
|
|
|
|
20
|
|
|
private $parameters; |
21
|
|
|
|
22
|
|
|
private $requestBody; |
23
|
|
|
|
24
|
|
|
private $server; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param mixed $requestBody |
28
|
|
|
*/ |
29
|
7 |
|
public function __construct( |
30
|
|
|
string $operationId = null, |
31
|
|
|
string $operationRef = null, |
32
|
|
|
string $description = null, |
33
|
|
|
array $parameters = [], |
34
|
|
|
$requestBody = null, |
35
|
|
|
Server $server = null, |
36
|
|
|
Extensions $extensions = null |
37
|
|
|
) { |
38
|
7 |
|
if (!empty($operationId) && !empty($operationRef)) { |
39
|
1 |
|
throw new InvalidArgumentException('The Link operationId and operationRef are mutually exclusive'); |
40
|
|
|
} |
41
|
|
|
|
42
|
6 |
|
if (empty($operationId) && empty($operationRef)) { |
43
|
1 |
|
throw new InvalidArgumentException('The Link must have either operationId or operationRef'); |
44
|
|
|
} |
45
|
|
|
|
46
|
5 |
|
$this->operationId = $operationId; |
47
|
5 |
|
$this->operationRef = $operationRef; |
48
|
5 |
|
$this->description = $description; |
49
|
5 |
|
$this->parameters = $parameters; |
50
|
5 |
|
$this->requestBody = $requestBody; |
51
|
5 |
|
$this->server = $server; |
52
|
5 |
|
$this->extensions = $extensions; |
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
public function getOperationId(): string |
56
|
|
|
{ |
57
|
3 |
|
return $this->operationId; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function getOperationRef(): string |
61
|
|
|
{ |
62
|
1 |
|
return $this->operationRef; |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
public function getParameters(): array |
66
|
|
|
{ |
67
|
4 |
|
return $this->parameters; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
4 |
|
public function getRequestBody() |
74
|
|
|
{ |
75
|
4 |
|
return $this->requestBody; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
public function getServer(): Server |
79
|
|
|
{ |
80
|
1 |
|
return $this->server; |
81
|
|
|
} |
82
|
|
|
|
83
|
4 |
|
public function hasOperationId(): bool |
84
|
|
|
{ |
85
|
4 |
|
return isset($this->operationId); |
86
|
|
|
} |
87
|
|
|
|
88
|
4 |
|
public function hasOperationRef(): bool |
89
|
|
|
{ |
90
|
4 |
|
return isset($this->operationRef); |
91
|
|
|
} |
92
|
|
|
|
93
|
4 |
|
public function hasServer(): bool |
94
|
|
|
{ |
95
|
4 |
|
return isset($this->server); |
96
|
|
|
} |
97
|
|
|
|
98
|
4 |
|
public function jsonSerialize(): ?array |
99
|
|
|
{ |
100
|
4 |
|
return $this->extendedProperties(parent::jsonSerialize()); |
101
|
|
|
} |
102
|
|
|
|
103
|
4 |
|
protected function normalizeOptionalProperties(): array |
104
|
|
|
{ |
105
|
|
|
return [ |
106
|
4 |
|
'operationId' => $this->hasOperationId() ? $this->getOperationId() : null, |
107
|
4 |
|
'operationRef' => $this->hasOperationRef() ? $this->getOperationRef() : null, |
108
|
4 |
|
'description' => $this->getNormalizedDescription(), |
109
|
4 |
|
'parameters' => $this->getParameters(), |
110
|
4 |
|
'requestBody' => $this->getRequestBody(), |
111
|
4 |
|
'server' => $this->hasServer() ? $this->getServer() : null, |
112
|
|
|
]; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|