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