|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Aweapi\Openapi\Builders; |
|
6
|
|
|
|
|
7
|
|
|
use Aweapi\Openapi\Objects; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
|
|
10
|
|
|
final class PathBuilder implements Objects\PathFactory |
|
11
|
|
|
{ |
|
12
|
|
|
use Properties\OptionalExtensions; |
|
13
|
|
|
|
|
14
|
|
|
private $description; |
|
15
|
|
|
|
|
16
|
|
|
private $operations = [ |
|
17
|
|
|
Objects\Path::METHOD_GET => null, |
|
18
|
|
|
Objects\Path::METHOD_PUT => null, |
|
19
|
|
|
Objects\Path::METHOD_POST => null, |
|
20
|
|
|
Objects\Path::METHOD_DELETE => null, |
|
21
|
|
|
Objects\Path::METHOD_PATCH => null, |
|
22
|
|
|
Objects\Path::METHOD_OPTIONS => null, |
|
23
|
|
|
Objects\Path::METHOD_HEAD => null, |
|
24
|
|
|
Objects\Path::METHOD_TRACE => null, |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
private $parameters; |
|
28
|
|
|
|
|
29
|
|
|
private $reference; |
|
30
|
|
|
|
|
31
|
|
|
private $servers; |
|
32
|
|
|
|
|
33
|
|
|
private $summary; |
|
34
|
|
|
|
|
35
|
7 |
|
public function createPath(): Objects\Path |
|
36
|
|
|
{ |
|
37
|
7 |
|
return new Objects\Path( |
|
38
|
7 |
|
$this->getSummary(), |
|
39
|
7 |
|
$this->getReference() ? $this->getReference()->createReference() : null, |
|
40
|
7 |
|
$this->getDescription(), |
|
41
|
7 |
|
$this->getOperation(Objects\Path::METHOD_GET) |
|
42
|
1 |
|
? $this->getOperation(Objects\Path::METHOD_GET)->createOperation() |
|
43
|
7 |
|
: null, |
|
44
|
7 |
|
$this->getOperation(Objects\Path::METHOD_PUT) |
|
45
|
|
|
? $this->getOperation(Objects\Path::METHOD_PUT)->createOperation() |
|
46
|
7 |
|
: null, |
|
47
|
7 |
|
$this->getOperation(Objects\Path::METHOD_POST) |
|
48
|
|
|
? $this->getOperation(Objects\Path::METHOD_POST)->createOperation() |
|
49
|
7 |
|
: null, |
|
50
|
7 |
|
$this->getOperation(Objects\Path::METHOD_DELETE) |
|
51
|
|
|
? $this->getOperation(Objects\Path::METHOD_DELETE)->createOperation() |
|
52
|
7 |
|
: null, |
|
53
|
7 |
|
$this->getOperation(Objects\Path::METHOD_PATCH) |
|
54
|
|
|
? $this->getOperation(Objects\Path::METHOD_PATCH)->createOperation() |
|
55
|
7 |
|
: null, |
|
56
|
7 |
|
$this->getOperation(Objects\Path::METHOD_OPTIONS) |
|
57
|
1 |
|
? $this->getOperation(Objects\Path::METHOD_OPTIONS)->createOperation() |
|
58
|
7 |
|
: null, |
|
59
|
7 |
|
$this->getOperation(Objects\Path::METHOD_HEAD) |
|
60
|
|
|
? $this->getOperation(Objects\Path::METHOD_HEAD)->createOperation() |
|
61
|
7 |
|
: null, |
|
62
|
7 |
|
$this->getOperation(Objects\Path::METHOD_TRACE) |
|
63
|
|
|
? $this->getOperation(Objects\Path::METHOD_TRACE)->createOperation() |
|
64
|
7 |
|
: null, |
|
65
|
7 |
|
$this->getServers() ? $this->getServers()->createServerCollection() : null, |
|
66
|
7 |
|
$this->getParameters() ? $this->getParameters()->createParameterCollection() : null, |
|
67
|
7 |
|
$this->getExtensions() |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function setDescription(string $description): self |
|
72
|
|
|
{ |
|
73
|
1 |
|
$this->description = $description; |
|
74
|
|
|
|
|
75
|
1 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
2 |
|
public function setOperation(string $method, Objects\OperationFactory $operation): self |
|
79
|
|
|
{ |
|
80
|
2 |
|
$method = mb_strtolower($method); |
|
81
|
|
|
|
|
82
|
2 |
|
if (!array_key_exists($method, $this->operations)) { |
|
83
|
1 |
|
throw new InvalidArgumentException(sprintf('The method "%s" is not supported', $method)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
$this->operations[$method] = $operation; |
|
87
|
|
|
|
|
88
|
1 |
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
public function setParameters(Objects\ParameterCollectionFactory $parameters): self |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->parameters = $parameters; |
|
94
|
|
|
|
|
95
|
1 |
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
4 |
|
public function setReference(Objects\ReferenceFactory $reference): self |
|
99
|
|
|
{ |
|
100
|
4 |
|
$this->reference = $reference; |
|
101
|
|
|
|
|
102
|
4 |
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
public function setServers(Objects\ServerCollectionFactory $servers): self |
|
106
|
|
|
{ |
|
107
|
1 |
|
$this->servers = $servers; |
|
108
|
|
|
|
|
109
|
1 |
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
public function setSummary(string $summary): self |
|
113
|
|
|
{ |
|
114
|
3 |
|
$this->summary = $summary; |
|
115
|
|
|
|
|
116
|
3 |
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
7 |
|
private function getDescription(): ?string |
|
120
|
|
|
{ |
|
121
|
7 |
|
return $this->description; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
7 |
|
private function getOperation(string $method): ?Objects\OperationFactory |
|
125
|
|
|
{ |
|
126
|
7 |
|
return $this->operations[mb_strtolower($method)]; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
7 |
|
private function getParameters(): ?Objects\ParameterCollectionFactory |
|
130
|
|
|
{ |
|
131
|
7 |
|
return $this->parameters; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
7 |
|
private function getReference(): ?Objects\ReferenceFactory |
|
135
|
|
|
{ |
|
136
|
7 |
|
return $this->reference; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
7 |
|
private function getServers(): ?Objects\ServerCollectionFactory |
|
140
|
|
|
{ |
|
141
|
7 |
|
return $this->servers; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
7 |
|
private function getSummary(): ?string |
|
145
|
|
|
{ |
|
146
|
7 |
|
return $this->summary; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|