1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ElevenLabs\Api\Definition; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
|
7
|
|
|
class RequestDefinition implements \Serializable, MessageDefinition |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
private $method; |
11
|
|
|
|
12
|
|
|
/** @var string */ |
13
|
|
|
private $operationId; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
private $pathTemplate; |
17
|
|
|
|
18
|
|
|
/** @var Parameters */ |
19
|
|
|
private $parameters; |
20
|
|
|
|
21
|
|
|
/** @var string[] */ |
22
|
|
|
private $contentTypes; |
23
|
|
|
|
24
|
|
|
/** @var ResponseDefinition[] */ |
25
|
|
|
private $responses; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string[] $contentTypes |
29
|
|
|
* @param ResponseDefinition[] $responses |
30
|
|
|
*/ |
31
|
4 |
|
public function __construct( |
32
|
|
|
string $method, |
33
|
|
|
string $operationId, |
34
|
|
|
string $pathTemplate, |
35
|
|
|
Parameters $parameters, |
36
|
|
|
array $contentTypes, |
37
|
|
|
array $responses |
38
|
|
|
) { |
39
|
4 |
|
$this->method = $method; |
40
|
4 |
|
$this->operationId = $operationId; |
41
|
4 |
|
$this->pathTemplate = $pathTemplate; |
42
|
4 |
|
$this->parameters = $parameters; |
43
|
4 |
|
$this->contentTypes = $contentTypes; |
44
|
4 |
|
foreach ($responses as $response) { |
45
|
2 |
|
$this->addResponseDefinition($response); |
46
|
|
|
} |
47
|
4 |
|
} |
48
|
|
|
|
49
|
|
|
public function getMethod(): string |
50
|
|
|
{ |
51
|
|
|
return $this->method; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getOperationId(): string |
55
|
|
|
{ |
56
|
|
|
return $this->operationId; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getPathTemplate(): string |
60
|
|
|
{ |
61
|
|
|
return $this->pathTemplate; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getRequestParameters(): Parameters |
65
|
|
|
{ |
66
|
|
|
return $this->parameters; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getContentTypes(): array |
70
|
|
|
{ |
71
|
|
|
return $this->contentTypes; |
72
|
|
|
} |
73
|
|
|
|
74
|
3 |
|
public function getResponseDefinition(int $statusCode): ResponseDefinition |
75
|
|
|
{ |
76
|
3 |
|
if (isset($this->responses[$statusCode])) { |
77
|
1 |
|
return $this->responses[$statusCode]; |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
if (isset($this->responses['default'])) { |
81
|
1 |
|
return $this->responses['default']; |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
throw new \InvalidArgumentException( |
85
|
1 |
|
sprintf( |
86
|
1 |
|
'No response definition for %s %s is available for status code %s', |
87
|
1 |
|
$this->method, |
88
|
1 |
|
$this->pathTemplate, |
89
|
1 |
|
$statusCode |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function hasBodySchema(): bool |
95
|
|
|
{ |
96
|
|
|
return $this->parameters->hasBodySchema(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getBodySchema(): ?stdClass |
100
|
|
|
{ |
101
|
|
|
return $this->parameters->getBodySchema(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function hasHeadersSchema(): bool |
105
|
|
|
{ |
106
|
|
|
return $this->parameters->hasHeadersSchema(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getHeadersSchema(): ?stdClass |
110
|
|
|
{ |
111
|
|
|
return $this->parameters->getHeadersSchema(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function hasPathSchema(): bool |
115
|
|
|
{ |
116
|
|
|
return $this->parameters->hasPathSchema(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getPathSchema(): ?stdClass |
120
|
|
|
{ |
121
|
|
|
return $this->parameters->getPathSchema(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function hasQueryParametersSchema(): bool |
125
|
|
|
{ |
126
|
|
|
return $this->parameters->hasQueryParametersSchema(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getQueryParametersSchema(): ?stdClass |
130
|
|
|
{ |
131
|
|
|
return $this->parameters->getQueryParametersSchema(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// Serializable |
135
|
1 |
|
public function serialize() |
136
|
|
|
{ |
137
|
1 |
|
return serialize([ |
138
|
1 |
|
'method' => $this->method, |
139
|
1 |
|
'operationId' => $this->operationId, |
140
|
1 |
|
'pathTemplate' => $this->pathTemplate, |
141
|
1 |
|
'parameters' => $this->parameters, |
142
|
1 |
|
'contentTypes' => $this->contentTypes, |
143
|
1 |
|
'responses' => $this->responses |
144
|
|
|
]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// Serializable |
148
|
1 |
|
public function unserialize($serialized) |
149
|
|
|
{ |
150
|
1 |
|
$data = unserialize($serialized); |
151
|
1 |
|
$this->method = $data['method']; |
152
|
1 |
|
$this->operationId = $data['operationId']; |
153
|
1 |
|
$this->pathTemplate = $data['pathTemplate']; |
154
|
1 |
|
$this->parameters = $data['parameters']; |
155
|
1 |
|
$this->contentTypes = $data['contentTypes']; |
156
|
1 |
|
$this->responses = $data['responses']; |
157
|
1 |
|
} |
158
|
|
|
|
159
|
2 |
|
private function addResponseDefinition(ResponseDefinition $response) |
160
|
|
|
{ |
161
|
2 |
|
$this->responses[$response->getStatusCode()] = $response; |
162
|
2 |
|
} |
163
|
|
|
} |
164
|
|
|
|