@@ -5,129 +5,129 @@ discard block |
||
5 | 5 | class PreprocessorTest extends \SwaggerGen_TestCase |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::__construct |
|
10 | - */ |
|
11 | - public function testConstructor_Empty() |
|
12 | - { |
|
13 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
14 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
19 | - */ |
|
20 | - public function testPreprocess_Ifdef_NotDefined() |
|
21 | - { |
|
22 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
23 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
24 | - $out = $object->preprocess(' |
|
8 | + /** |
|
9 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::__construct |
|
10 | + */ |
|
11 | + public function testConstructor_Empty() |
|
12 | + { |
|
13 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
14 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
19 | + */ |
|
20 | + public function testPreprocess_Ifdef_NotDefined() |
|
21 | + { |
|
22 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
23 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
24 | + $out = $object->preprocess(' |
|
25 | 25 | ifdef test |
26 | 26 | whatever |
27 | 27 | endif |
28 | 28 | '); |
29 | 29 | |
30 | - $this->assertEquals(' |
|
30 | + $this->assertEquals(' |
|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | 34 | ', $out); |
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
39 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
40 | - */ |
|
41 | - public function testPreprocess_Ifdef_Defined() |
|
42 | - { |
|
43 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
44 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
45 | - $object->define('test'); |
|
46 | - $out = $object->preprocess(' |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
39 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
40 | + */ |
|
41 | + public function testPreprocess_Ifdef_Defined() |
|
42 | + { |
|
43 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
44 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
45 | + $object->define('test'); |
|
46 | + $out = $object->preprocess(' |
|
47 | 47 | ifdef test |
48 | 48 | whatever |
49 | 49 | endif |
50 | 50 | '); |
51 | 51 | |
52 | - $this->assertEquals(' |
|
52 | + $this->assertEquals(' |
|
53 | 53 | |
54 | 54 | whatever |
55 | 55 | |
56 | 56 | ', $out); |
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
61 | - */ |
|
62 | - public function testPreprocess_Ifndef_NotDefined() |
|
63 | - { |
|
64 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
65 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
66 | - $out = $object->preprocess(' |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
61 | + */ |
|
62 | + public function testPreprocess_Ifndef_NotDefined() |
|
63 | + { |
|
64 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
65 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
66 | + $out = $object->preprocess(' |
|
67 | 67 | ifndef test |
68 | 68 | whatever |
69 | 69 | endif |
70 | 70 | '); |
71 | 71 | |
72 | - $this->assertEquals(' |
|
72 | + $this->assertEquals(' |
|
73 | 73 | |
74 | 74 | whatever |
75 | 75 | |
76 | 76 | ', $out); |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
81 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
82 | - */ |
|
83 | - public function testPreprocess_Ifndef_Defined() |
|
84 | - { |
|
85 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
86 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
87 | - $object->define('test'); |
|
88 | - $out = $object->preprocess(' |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
81 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
82 | + */ |
|
83 | + public function testPreprocess_Ifndef_Defined() |
|
84 | + { |
|
85 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
86 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
87 | + $object->define('test'); |
|
88 | + $out = $object->preprocess(' |
|
89 | 89 | ifndef test |
90 | 90 | whatever |
91 | 91 | endif |
92 | 92 | '); |
93 | 93 | |
94 | - $this->assertEquals(' |
|
94 | + $this->assertEquals(' |
|
95 | 95 | |
96 | 96 | |
97 | 97 | |
98 | 98 | ', $out); |
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
103 | - */ |
|
104 | - public function testPreprocess_Define() |
|
105 | - { |
|
106 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
107 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
108 | - $out = $object->preprocess(' |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
103 | + */ |
|
104 | + public function testPreprocess_Define() |
|
105 | + { |
|
106 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
107 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
108 | + $out = $object->preprocess(' |
|
109 | 109 | define test |
110 | 110 | ifndef test |
111 | 111 | whatever |
112 | 112 | endif |
113 | 113 | '); |
114 | 114 | |
115 | - $this->assertEquals(' |
|
115 | + $this->assertEquals(' |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | 120 | ', $out); |
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
125 | - */ |
|
126 | - public function testPreprocess_Undef() |
|
127 | - { |
|
128 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
129 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
130 | - $out = $object->preprocess(' |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
125 | + */ |
|
126 | + public function testPreprocess_Undef() |
|
127 | + { |
|
128 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
129 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
130 | + $out = $object->preprocess(' |
|
131 | 131 | define test |
132 | 132 | undef test |
133 | 133 | ifdef test |
@@ -135,133 +135,133 @@ discard block |
||
135 | 135 | endif |
136 | 136 | '); |
137 | 137 | |
138 | - $this->assertEquals(' |
|
138 | + $this->assertEquals(' |
|
139 | 139 | |
140 | 140 | |
141 | 141 | |
142 | 142 | |
143 | 143 | |
144 | 144 | ', $out); |
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
149 | - */ |
|
150 | - public function testPreprocess_If_NotDefined() |
|
151 | - { |
|
152 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
153 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
154 | - $out = $object->preprocess(' |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
149 | + */ |
|
150 | + public function testPreprocess_If_NotDefined() |
|
151 | + { |
|
152 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
153 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
154 | + $out = $object->preprocess(' |
|
155 | 155 | if test red |
156 | 156 | whatever |
157 | 157 | endif |
158 | 158 | '); |
159 | 159 | |
160 | - $this->assertEquals(' |
|
160 | + $this->assertEquals(' |
|
161 | 161 | |
162 | 162 | |
163 | 163 | |
164 | 164 | ', $out); |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
169 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
170 | - */ |
|
171 | - public function testPreprocess_If_AnyValue() |
|
172 | - { |
|
173 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
174 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
175 | - $object->define('test', 'green'); |
|
176 | - $out = $object->preprocess(' |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
169 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
170 | + */ |
|
171 | + public function testPreprocess_If_AnyValue() |
|
172 | + { |
|
173 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
174 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
175 | + $object->define('test', 'green'); |
|
176 | + $out = $object->preprocess(' |
|
177 | 177 | if test |
178 | 178 | whatever |
179 | 179 | endif |
180 | 180 | '); |
181 | 181 | |
182 | - $this->assertEquals(' |
|
182 | + $this->assertEquals(' |
|
183 | 183 | |
184 | 184 | whatever |
185 | 185 | |
186 | 186 | ', $out); |
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
191 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
192 | - */ |
|
193 | - public function testPreprocess_If_NoValue() |
|
194 | - { |
|
195 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
196 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
197 | - $object->define('test'); |
|
198 | - $out = $object->preprocess(' |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
191 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
192 | + */ |
|
193 | + public function testPreprocess_If_NoValue() |
|
194 | + { |
|
195 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
196 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
197 | + $object->define('test'); |
|
198 | + $out = $object->preprocess(' |
|
199 | 199 | if test red |
200 | 200 | whatever |
201 | 201 | endif |
202 | 202 | '); |
203 | 203 | |
204 | - $this->assertEquals(' |
|
204 | + $this->assertEquals(' |
|
205 | 205 | |
206 | 206 | |
207 | 207 | |
208 | 208 | ', $out); |
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
213 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
214 | - */ |
|
215 | - public function testPreprocess_If_Mismatch() |
|
216 | - { |
|
217 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
218 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
219 | - $object->define('test', 'green'); |
|
220 | - $out = $object->preprocess(' |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
213 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
214 | + */ |
|
215 | + public function testPreprocess_If_Mismatch() |
|
216 | + { |
|
217 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
218 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
219 | + $object->define('test', 'green'); |
|
220 | + $out = $object->preprocess(' |
|
221 | 221 | if test red |
222 | 222 | whatever |
223 | 223 | endif |
224 | 224 | '); |
225 | 225 | |
226 | - $this->assertEquals(' |
|
226 | + $this->assertEquals(' |
|
227 | 227 | |
228 | 228 | |
229 | 229 | |
230 | 230 | ', $out); |
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
235 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
236 | - */ |
|
237 | - public function testPreprocess_If_Match() |
|
238 | - { |
|
239 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
240 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
241 | - $object->define('test', 'red'); |
|
242 | - $out = $object->preprocess(' |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
235 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
236 | + */ |
|
237 | + public function testPreprocess_If_Match() |
|
238 | + { |
|
239 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
240 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
241 | + $object->define('test', 'red'); |
|
242 | + $out = $object->preprocess(' |
|
243 | 243 | if test red |
244 | 244 | whatever |
245 | 245 | endif |
246 | 246 | '); |
247 | 247 | |
248 | - $this->assertEquals(' |
|
248 | + $this->assertEquals(' |
|
249 | 249 | |
250 | 250 | whatever |
251 | 251 | |
252 | 252 | ', $out); |
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
257 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
258 | - */ |
|
259 | - public function testPreprocess_Else_Match() |
|
260 | - { |
|
261 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
262 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
263 | - $object->define('test', 'blue'); |
|
264 | - $out = $object->preprocess(' |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
257 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
258 | + */ |
|
259 | + public function testPreprocess_Else_Match() |
|
260 | + { |
|
261 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
262 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
263 | + $object->define('test', 'blue'); |
|
264 | + $out = $object->preprocess(' |
|
265 | 265 | if test red |
266 | 266 | whatever |
267 | 267 | else |
@@ -269,25 +269,25 @@ discard block |
||
269 | 269 | endif |
270 | 270 | '); |
271 | 271 | |
272 | - $this->assertEquals(' |
|
272 | + $this->assertEquals(' |
|
273 | 273 | |
274 | 274 | |
275 | 275 | |
276 | 276 | otherwise |
277 | 277 | |
278 | 278 | ', $out); |
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
283 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
284 | - */ |
|
285 | - public function testPreprocess_Elif_Match() |
|
286 | - { |
|
287 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
288 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
289 | - $object->define('test', 'blue'); |
|
290 | - $out = $object->preprocess(' |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
283 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
284 | + */ |
|
285 | + public function testPreprocess_Elif_Match() |
|
286 | + { |
|
287 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
288 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
289 | + $object->define('test', 'blue'); |
|
290 | + $out = $object->preprocess(' |
|
291 | 291 | if test red |
292 | 292 | whatever |
293 | 293 | elif test green |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | endif |
298 | 298 | '); |
299 | 299 | |
300 | - $this->assertEquals(' |
|
300 | + $this->assertEquals(' |
|
301 | 301 | |
302 | 302 | |
303 | 303 | |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | otherwise |
307 | 307 | |
308 | 308 | ', $out); |
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
313 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
314 | - */ |
|
315 | - public function testPreprocess_Elif_NoValue() |
|
316 | - { |
|
317 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
318 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
319 | - $object->define('test', 'blue'); |
|
320 | - $out = $object->preprocess(' |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
313 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
314 | + */ |
|
315 | + public function testPreprocess_Elif_NoValue() |
|
316 | + { |
|
317 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
318 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
319 | + $object->define('test', 'blue'); |
|
320 | + $out = $object->preprocess(' |
|
321 | 321 | if test red |
322 | 322 | whatever |
323 | 323 | elif test green |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | endif |
328 | 328 | '); |
329 | 329 | |
330 | - $this->assertEquals(' |
|
330 | + $this->assertEquals(' |
|
331 | 331 | |
332 | 332 | |
333 | 333 | |
@@ -336,76 +336,76 @@ discard block |
||
336 | 336 | otherwise |
337 | 337 | |
338 | 338 | ', $out); |
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
343 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::undefine |
|
344 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
345 | - */ |
|
346 | - public function testPreprocess_Undefine() |
|
347 | - { |
|
348 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
349 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
350 | - $object->define('test'); |
|
351 | - $object->undefine('test'); |
|
352 | - $out = $object->preprocess(' |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
343 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::undefine |
|
344 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
345 | + */ |
|
346 | + public function testPreprocess_Undefine() |
|
347 | + { |
|
348 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
349 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
350 | + $object->define('test'); |
|
351 | + $object->undefine('test'); |
|
352 | + $out = $object->preprocess(' |
|
353 | 353 | ifdef test |
354 | 354 | whatever |
355 | 355 | endif |
356 | 356 | '); |
357 | 357 | |
358 | - $this->assertEquals(' |
|
358 | + $this->assertEquals(' |
|
359 | 359 | |
360 | 360 | |
361 | 361 | |
362 | 362 | ', $out); |
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
367 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::resetDefines |
|
368 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
369 | - */ |
|
370 | - public function testPreprocess_ResetDefines() |
|
371 | - { |
|
372 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
373 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
374 | - $object->define('test'); |
|
375 | - $object->resetDefines(); |
|
376 | - $out = $object->preprocess(' |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::define |
|
367 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::resetDefines |
|
368 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
369 | + */ |
|
370 | + public function testPreprocess_ResetDefines() |
|
371 | + { |
|
372 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
373 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
374 | + $object->define('test'); |
|
375 | + $object->resetDefines(); |
|
376 | + $out = $object->preprocess(' |
|
377 | 377 | ifdef test |
378 | 378 | whatever |
379 | 379 | endif |
380 | 380 | '); |
381 | 381 | |
382 | - $this->assertEquals(' |
|
382 | + $this->assertEquals(' |
|
383 | 383 | |
384 | 384 | |
385 | 385 | |
386 | 386 | ', $out); |
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::addDefines |
|
391 | - * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
392 | - */ |
|
393 | - public function testPreprocess_AddDefines() |
|
394 | - { |
|
395 | - $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
396 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
397 | - $object->addDefines(['test' => true]); |
|
398 | - $out = $object->preprocess(' |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::addDefines |
|
391 | + * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess |
|
392 | + */ |
|
393 | + public function testPreprocess_AddDefines() |
|
394 | + { |
|
395 | + $object = new \SwaggerGen\Parser\Text\Preprocessor(); |
|
396 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object); |
|
397 | + $object->addDefines(['test' => true]); |
|
398 | + $out = $object->preprocess(' |
|
399 | 399 | ifdef test |
400 | 400 | whatever |
401 | 401 | endif |
402 | 402 | '); |
403 | 403 | |
404 | - $this->assertEquals(' |
|
404 | + $this->assertEquals(' |
|
405 | 405 | |
406 | 406 | whatever |
407 | 407 | |
408 | 408 | ', $out); |
409 | - } |
|
409 | + } |
|
410 | 410 | |
411 | 411 | } |
@@ -15,28 +15,28 @@ |
||
15 | 15 | class StatementException extends \Exception |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var Statement |
|
20 | - */ |
|
21 | - private $statement; |
|
22 | - |
|
23 | - /** |
|
24 | - * |
|
25 | - * @param string $message |
|
26 | - * @param int $code |
|
27 | - * @param Throwable $previous |
|
28 | - * @param Statement $statement |
|
29 | - */ |
|
30 | - public function __construct($message = "", $code = 0, $previous = null, $statement = null) |
|
31 | - { |
|
32 | - $this->statement = $statement; |
|
33 | - |
|
34 | - parent::__construct($message, $code, $previous); |
|
35 | - } |
|
36 | - |
|
37 | - public function getStatement() |
|
38 | - { |
|
39 | - return $this->statement; |
|
40 | - } |
|
18 | + /** |
|
19 | + * @var Statement |
|
20 | + */ |
|
21 | + private $statement; |
|
22 | + |
|
23 | + /** |
|
24 | + * |
|
25 | + * @param string $message |
|
26 | + * @param int $code |
|
27 | + * @param Throwable $previous |
|
28 | + * @param Statement $statement |
|
29 | + */ |
|
30 | + public function __construct($message = "", $code = 0, $previous = null, $statement = null) |
|
31 | + { |
|
32 | + $this->statement = $statement; |
|
33 | + |
|
34 | + parent::__construct($message, $code, $previous); |
|
35 | + } |
|
36 | + |
|
37 | + public function getStatement() |
|
38 | + { |
|
39 | + return $this->statement; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -38,217 +38,217 @@ |
||
38 | 38 | class SwaggerGen |
39 | 39 | { |
40 | 40 | |
41 | - const FORMAT_ARRAY = ''; |
|
42 | - const FORMAT_JSON = 'json'; |
|
43 | - const FORMAT_JSON_PRETTY = 'json+'; |
|
44 | - const FORMAT_YAML = 'yaml'; |
|
45 | - |
|
46 | - private $host; |
|
47 | - private $basePath; |
|
48 | - private $dirs; |
|
49 | - private $defines = []; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var TypeRegistry |
|
53 | - */ |
|
54 | - private $typeRegistry; |
|
55 | - |
|
56 | - /** |
|
57 | - * Create a new SwaggerGen instance |
|
58 | - * |
|
59 | - * @param string $host |
|
60 | - * @param string $basePath |
|
61 | - * @param string[] $dirs |
|
62 | - * @param TypeRegistry $typeRegistry |
|
63 | - */ |
|
64 | - public function __construct($host = '', $basePath = '', $dirs = [], $typeRegistry = null) |
|
65 | - { |
|
66 | - $this->host = $host; |
|
67 | - $this->basePath = $basePath; |
|
68 | - $this->dirs = $dirs; |
|
69 | - $this->typeRegistry = $typeRegistry; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Set a new type registry |
|
74 | - * |
|
75 | - * @param TypeRegistry $typeRegistry |
|
76 | - */ |
|
77 | - public function setTypeRegistry($typeRegistry = null) |
|
78 | - { |
|
79 | - $this->typeRegistry = $typeRegistry; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $name |
|
84 | - */ |
|
85 | - public function define($name, $value = 1) |
|
86 | - { |
|
87 | - $this->defines[$name] = $value; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $name |
|
92 | - */ |
|
93 | - public function undefine($name) |
|
94 | - { |
|
95 | - unset($this->defines[$name]); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $file |
|
100 | - * @param string[] $dirs |
|
101 | - * @return Statement[] |
|
102 | - * @throws Exception |
|
103 | - */ |
|
104 | - private function parsePhpFile(string $file, array $dirs): array |
|
105 | - { |
|
106 | - $Parser = new Parser(); |
|
107 | - return $Parser->parse($file, $dirs, $this->defines); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param string $file |
|
112 | - * @param string[] $dirs |
|
113 | - * @return Statement[] |
|
114 | - */ |
|
115 | - private function parseTextFile($file, $dirs) |
|
116 | - { |
|
117 | - $Parser = new TextParser(); |
|
118 | - return $Parser->parse($file, $dirs, $this->defines); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $text |
|
123 | - * @param string[] $dirs |
|
124 | - * @return Statement[] |
|
125 | - */ |
|
126 | - private function parseText(string $text, array $dirs): array |
|
127 | - { |
|
128 | - $Parser = new TextParser(); |
|
129 | - return $Parser->parseText($text, $dirs, $this->defines); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Creates Swagger\Swagger object and populates it with statements |
|
134 | - * |
|
135 | - * This effectively converts the linear list of statements into parse-tree |
|
136 | - * like structure, performing some checks (like rejecting unknown |
|
137 | - * subcommands) during the process. Returned Swagger\Swagger object is |
|
138 | - * ready for serialization with {@see Swagger\Swagger::toArray} |
|
139 | - * |
|
140 | - * @param string $host |
|
141 | - * @param string $basePath |
|
142 | - * @param Statement[] $statements |
|
143 | - * @return Swagger |
|
144 | - * @throws StatementException |
|
145 | - */ |
|
146 | - public function parseStatements($host, $basePath, $statements) |
|
147 | - { |
|
148 | - $swagger = new Swagger($host, $basePath, $this->typeRegistry); |
|
149 | - |
|
150 | - $stack = array($swagger); |
|
151 | - /* @var AbstractObject[] $stack */ |
|
152 | - foreach ($statements as $statement) { |
|
153 | - try { |
|
154 | - $top = end($stack); |
|
155 | - |
|
156 | - do { |
|
157 | - $result = $top->handleCommand($statement->getCommand(), $statement->getData()); |
|
158 | - |
|
159 | - if ($result) { |
|
160 | - if ($result !== $top) { |
|
161 | - // Remove all similar classes from array first! |
|
162 | - $classname = get_class($result); |
|
163 | - $stack = array_filter($stack, function ($class) use ($classname) { |
|
164 | - return !(is_a($class, $classname)); |
|
165 | - }); |
|
166 | - |
|
167 | - $stack[] = $result; |
|
168 | - } |
|
169 | - } else { |
|
170 | - $top = prev($stack); |
|
171 | - } |
|
172 | - } while (!$result && $top); |
|
173 | - } catch (Exception $e) { |
|
174 | - throw new StatementException($e->getMessage(), $e->getCode(), $e, $statement); |
|
175 | - } |
|
176 | - |
|
177 | - if (!$result && !$top) { |
|
178 | - $messages = array("Unsupported or unknown command: {$statement->getCommand()} {$statement->getData()}"); |
|
179 | - |
|
180 | - $stacktrace = []; |
|
181 | - foreach ($stack as $object) { |
|
182 | - $stacktrace[] = (string)$object; |
|
183 | - } |
|
184 | - $messages[] = join(', ' . PHP_EOL, $stacktrace); |
|
185 | - |
|
186 | - throw new StatementException(join('. ', $messages), 0, null, $statement); |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - return $swagger; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get Swagger 2.x output |
|
195 | - * |
|
196 | - * @param string[] $files |
|
197 | - * @param string[] $dirs |
|
198 | - * @param string $format |
|
199 | - * @return array|false|string |
|
200 | - * @throws Exception |
|
201 | - * @throws StatementException |
|
202 | - */ |
|
203 | - public function getSwagger(array $files, array $dirs = [], string $format = self::FORMAT_ARRAY) |
|
204 | - { |
|
205 | - $dirs = array_merge($this->dirs, $dirs); |
|
206 | - |
|
207 | - $statements = []; |
|
208 | - foreach ($files as $file) { |
|
209 | - switch (pathinfo($file, PATHINFO_EXTENSION)) { |
|
210 | - case 'php': |
|
211 | - $fileStatements = $this->parsePhpFile($file, $dirs); |
|
212 | - break; |
|
213 | - |
|
214 | - case 'txt': |
|
215 | - $fileStatements = $this->parseTextFile($file, $dirs); |
|
216 | - break; |
|
217 | - |
|
218 | - default: |
|
219 | - $fileStatements = $this->parseText($file, $dirs); |
|
220 | - break; |
|
221 | - } |
|
222 | - |
|
223 | - $statements = array_merge($statements, $fileStatements); |
|
224 | - } |
|
225 | - |
|
226 | - $output = $this->parseStatements($this->host, $this->basePath, $statements)->toArray(); |
|
227 | - |
|
228 | - switch ($format) { |
|
229 | - case self::FORMAT_JSON: |
|
230 | - $output = json_encode($output); |
|
231 | - break; |
|
232 | - |
|
233 | - case self::FORMAT_JSON_PRETTY: |
|
234 | - $flags = (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); // Since PHP 5.4.0 |
|
235 | - $output = json_encode($output, $flags); |
|
236 | - break; |
|
237 | - |
|
238 | - case self::FORMAT_YAML: |
|
239 | - if (!function_exists('yaml_emit')) { |
|
240 | - throw new Exception('YAML extension not installed.'); |
|
241 | - } |
|
242 | - array_walk_recursive($output, function (&$value) { |
|
243 | - if (is_object($value)) { |
|
244 | - $value = (array)$value; |
|
245 | - } |
|
246 | - }); |
|
247 | - $output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK); |
|
248 | - break; |
|
249 | - } |
|
250 | - |
|
251 | - return $output; |
|
252 | - } |
|
41 | + const FORMAT_ARRAY = ''; |
|
42 | + const FORMAT_JSON = 'json'; |
|
43 | + const FORMAT_JSON_PRETTY = 'json+'; |
|
44 | + const FORMAT_YAML = 'yaml'; |
|
45 | + |
|
46 | + private $host; |
|
47 | + private $basePath; |
|
48 | + private $dirs; |
|
49 | + private $defines = []; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var TypeRegistry |
|
53 | + */ |
|
54 | + private $typeRegistry; |
|
55 | + |
|
56 | + /** |
|
57 | + * Create a new SwaggerGen instance |
|
58 | + * |
|
59 | + * @param string $host |
|
60 | + * @param string $basePath |
|
61 | + * @param string[] $dirs |
|
62 | + * @param TypeRegistry $typeRegistry |
|
63 | + */ |
|
64 | + public function __construct($host = '', $basePath = '', $dirs = [], $typeRegistry = null) |
|
65 | + { |
|
66 | + $this->host = $host; |
|
67 | + $this->basePath = $basePath; |
|
68 | + $this->dirs = $dirs; |
|
69 | + $this->typeRegistry = $typeRegistry; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Set a new type registry |
|
74 | + * |
|
75 | + * @param TypeRegistry $typeRegistry |
|
76 | + */ |
|
77 | + public function setTypeRegistry($typeRegistry = null) |
|
78 | + { |
|
79 | + $this->typeRegistry = $typeRegistry; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $name |
|
84 | + */ |
|
85 | + public function define($name, $value = 1) |
|
86 | + { |
|
87 | + $this->defines[$name] = $value; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $name |
|
92 | + */ |
|
93 | + public function undefine($name) |
|
94 | + { |
|
95 | + unset($this->defines[$name]); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $file |
|
100 | + * @param string[] $dirs |
|
101 | + * @return Statement[] |
|
102 | + * @throws Exception |
|
103 | + */ |
|
104 | + private function parsePhpFile(string $file, array $dirs): array |
|
105 | + { |
|
106 | + $Parser = new Parser(); |
|
107 | + return $Parser->parse($file, $dirs, $this->defines); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param string $file |
|
112 | + * @param string[] $dirs |
|
113 | + * @return Statement[] |
|
114 | + */ |
|
115 | + private function parseTextFile($file, $dirs) |
|
116 | + { |
|
117 | + $Parser = new TextParser(); |
|
118 | + return $Parser->parse($file, $dirs, $this->defines); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $text |
|
123 | + * @param string[] $dirs |
|
124 | + * @return Statement[] |
|
125 | + */ |
|
126 | + private function parseText(string $text, array $dirs): array |
|
127 | + { |
|
128 | + $Parser = new TextParser(); |
|
129 | + return $Parser->parseText($text, $dirs, $this->defines); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Creates Swagger\Swagger object and populates it with statements |
|
134 | + * |
|
135 | + * This effectively converts the linear list of statements into parse-tree |
|
136 | + * like structure, performing some checks (like rejecting unknown |
|
137 | + * subcommands) during the process. Returned Swagger\Swagger object is |
|
138 | + * ready for serialization with {@see Swagger\Swagger::toArray} |
|
139 | + * |
|
140 | + * @param string $host |
|
141 | + * @param string $basePath |
|
142 | + * @param Statement[] $statements |
|
143 | + * @return Swagger |
|
144 | + * @throws StatementException |
|
145 | + */ |
|
146 | + public function parseStatements($host, $basePath, $statements) |
|
147 | + { |
|
148 | + $swagger = new Swagger($host, $basePath, $this->typeRegistry); |
|
149 | + |
|
150 | + $stack = array($swagger); |
|
151 | + /* @var AbstractObject[] $stack */ |
|
152 | + foreach ($statements as $statement) { |
|
153 | + try { |
|
154 | + $top = end($stack); |
|
155 | + |
|
156 | + do { |
|
157 | + $result = $top->handleCommand($statement->getCommand(), $statement->getData()); |
|
158 | + |
|
159 | + if ($result) { |
|
160 | + if ($result !== $top) { |
|
161 | + // Remove all similar classes from array first! |
|
162 | + $classname = get_class($result); |
|
163 | + $stack = array_filter($stack, function ($class) use ($classname) { |
|
164 | + return !(is_a($class, $classname)); |
|
165 | + }); |
|
166 | + |
|
167 | + $stack[] = $result; |
|
168 | + } |
|
169 | + } else { |
|
170 | + $top = prev($stack); |
|
171 | + } |
|
172 | + } while (!$result && $top); |
|
173 | + } catch (Exception $e) { |
|
174 | + throw new StatementException($e->getMessage(), $e->getCode(), $e, $statement); |
|
175 | + } |
|
176 | + |
|
177 | + if (!$result && !$top) { |
|
178 | + $messages = array("Unsupported or unknown command: {$statement->getCommand()} {$statement->getData()}"); |
|
179 | + |
|
180 | + $stacktrace = []; |
|
181 | + foreach ($stack as $object) { |
|
182 | + $stacktrace[] = (string)$object; |
|
183 | + } |
|
184 | + $messages[] = join(', ' . PHP_EOL, $stacktrace); |
|
185 | + |
|
186 | + throw new StatementException(join('. ', $messages), 0, null, $statement); |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + return $swagger; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get Swagger 2.x output |
|
195 | + * |
|
196 | + * @param string[] $files |
|
197 | + * @param string[] $dirs |
|
198 | + * @param string $format |
|
199 | + * @return array|false|string |
|
200 | + * @throws Exception |
|
201 | + * @throws StatementException |
|
202 | + */ |
|
203 | + public function getSwagger(array $files, array $dirs = [], string $format = self::FORMAT_ARRAY) |
|
204 | + { |
|
205 | + $dirs = array_merge($this->dirs, $dirs); |
|
206 | + |
|
207 | + $statements = []; |
|
208 | + foreach ($files as $file) { |
|
209 | + switch (pathinfo($file, PATHINFO_EXTENSION)) { |
|
210 | + case 'php': |
|
211 | + $fileStatements = $this->parsePhpFile($file, $dirs); |
|
212 | + break; |
|
213 | + |
|
214 | + case 'txt': |
|
215 | + $fileStatements = $this->parseTextFile($file, $dirs); |
|
216 | + break; |
|
217 | + |
|
218 | + default: |
|
219 | + $fileStatements = $this->parseText($file, $dirs); |
|
220 | + break; |
|
221 | + } |
|
222 | + |
|
223 | + $statements = array_merge($statements, $fileStatements); |
|
224 | + } |
|
225 | + |
|
226 | + $output = $this->parseStatements($this->host, $this->basePath, $statements)->toArray(); |
|
227 | + |
|
228 | + switch ($format) { |
|
229 | + case self::FORMAT_JSON: |
|
230 | + $output = json_encode($output); |
|
231 | + break; |
|
232 | + |
|
233 | + case self::FORMAT_JSON_PRETTY: |
|
234 | + $flags = (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); // Since PHP 5.4.0 |
|
235 | + $output = json_encode($output, $flags); |
|
236 | + break; |
|
237 | + |
|
238 | + case self::FORMAT_YAML: |
|
239 | + if (!function_exists('yaml_emit')) { |
|
240 | + throw new Exception('YAML extension not installed.'); |
|
241 | + } |
|
242 | + array_walk_recursive($output, function (&$value) { |
|
243 | + if (is_object($value)) { |
|
244 | + $value = (array)$value; |
|
245 | + } |
|
246 | + }); |
|
247 | + $output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK); |
|
248 | + break; |
|
249 | + } |
|
250 | + |
|
251 | + return $output; |
|
252 | + } |
|
253 | 253 | |
254 | 254 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | if ($result !== $top) { |
161 | 161 | // Remove all similar classes from array first! |
162 | 162 | $classname = get_class($result); |
163 | - $stack = array_filter($stack, function ($class) use ($classname) { |
|
163 | + $stack = array_filter($stack, function($class) use ($classname) { |
|
164 | 164 | return !(is_a($class, $classname)); |
165 | 165 | }); |
166 | 166 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $stacktrace = []; |
181 | 181 | foreach ($stack as $object) { |
182 | - $stacktrace[] = (string)$object; |
|
182 | + $stacktrace[] = (string) $object; |
|
183 | 183 | } |
184 | 184 | $messages[] = join(', ' . PHP_EOL, $stacktrace); |
185 | 185 | |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | if (!function_exists('yaml_emit')) { |
240 | 240 | throw new Exception('YAML extension not installed.'); |
241 | 241 | } |
242 | - array_walk_recursive($output, function (&$value) { |
|
242 | + array_walk_recursive($output, function(&$value) { |
|
243 | 243 | if (is_object($value)) { |
244 | - $value = (array)$value; |
|
244 | + $value = (array) $value; |
|
245 | 245 | } |
246 | 246 | }); |
247 | 247 | $output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK); |
@@ -14,61 +14,61 @@ |
||
14 | 14 | class Statement |
15 | 15 | { |
16 | 16 | |
17 | - private $command; |
|
18 | - private $data; |
|
19 | - private $file; |
|
20 | - private $line; |
|
17 | + private $command; |
|
18 | + private $data; |
|
19 | + private $file; |
|
20 | + private $line; |
|
21 | 21 | |
22 | - public function __construct($command, $data = null, $file = null, $line = null) |
|
23 | - { |
|
24 | - $this->command = $command; |
|
25 | - $this->data = $data; |
|
26 | - $this->file = $file; |
|
27 | - $this->line = $line; |
|
28 | - } |
|
22 | + public function __construct($command, $data = null, $file = null, $line = null) |
|
23 | + { |
|
24 | + $this->command = $command; |
|
25 | + $this->data = $data; |
|
26 | + $this->file = $file; |
|
27 | + $this->line = $line; |
|
28 | + } |
|
29 | 29 | |
30 | - public function __toString() |
|
31 | - { |
|
32 | - $message = "Command '{$this->command}'"; |
|
33 | - $message .= $this->data ? " with data '{$this->data}'" : ' without data'; |
|
34 | - $message .= $this->file ? " from static text" : " in file '{$this->file}' on line {$this->line}"; |
|
35 | - return $message; |
|
36 | - } |
|
30 | + public function __toString() |
|
31 | + { |
|
32 | + $message = "Command '{$this->command}'"; |
|
33 | + $message .= $this->data ? " with data '{$this->data}'" : ' without data'; |
|
34 | + $message .= $this->file ? " from static text" : " in file '{$this->file}' on line {$this->line}"; |
|
35 | + return $message; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the command part of this statement |
|
40 | - * @return string single word, without spaces |
|
41 | - */ |
|
42 | - public function getCommand() |
|
43 | - { |
|
44 | - return $this->command; |
|
45 | - } |
|
38 | + /** |
|
39 | + * Get the command part of this statement |
|
40 | + * @return string single word, without spaces |
|
41 | + */ |
|
42 | + public function getCommand() |
|
43 | + { |
|
44 | + return $this->command; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get the data of this statement |
|
49 | - * @return string may contain spaces |
|
50 | - */ |
|
51 | - public function getData() |
|
52 | - { |
|
53 | - return $this->data; |
|
54 | - } |
|
47 | + /** |
|
48 | + * Get the data of this statement |
|
49 | + * @return string may contain spaces |
|
50 | + */ |
|
51 | + public function getData() |
|
52 | + { |
|
53 | + return $this->data; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get the file (if available) where this statement was parsed from |
|
58 | - * @return string|null the full filename or null of from static text |
|
59 | - */ |
|
60 | - public function getFile() |
|
61 | - { |
|
62 | - return $this->file; |
|
63 | - } |
|
56 | + /** |
|
57 | + * Get the file (if available) where this statement was parsed from |
|
58 | + * @return string|null the full filename or null of from static text |
|
59 | + */ |
|
60 | + public function getFile() |
|
61 | + { |
|
62 | + return $this->file; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get the line number where this statement was found |
|
67 | - * @return int|null the line number |
|
68 | - */ |
|
69 | - public function getLine() |
|
70 | - { |
|
71 | - return $this->line; |
|
72 | - } |
|
65 | + /** |
|
66 | + * Get the line number where this statement was found |
|
67 | + * @return int|null the line number |
|
68 | + */ |
|
69 | + public function getLine() |
|
70 | + { |
|
71 | + return $this->line; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -13,47 +13,47 @@ |
||
13 | 13 | class Tag extends AbstractDocumentableObject |
14 | 14 | { |
15 | 15 | |
16 | - private $name; |
|
17 | - private $description; |
|
18 | - |
|
19 | - public function __construct(AbstractObject $parent, $name, $description = null) |
|
20 | - { |
|
21 | - parent::__construct($parent); |
|
22 | - $this->name = $name; |
|
23 | - $this->description = $description; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string $command |
|
28 | - * @param string $data |
|
29 | - * @return AbstractObject|boolean |
|
30 | - */ |
|
31 | - public function handleCommand($command, $data = null) |
|
32 | - { |
|
33 | - if (strtolower($command) === 'description') { |
|
34 | - $this->description = $data; |
|
35 | - return $this; |
|
36 | - } |
|
37 | - |
|
38 | - return parent::handleCommand($command, $data); |
|
39 | - } |
|
40 | - |
|
41 | - public function toArray() |
|
42 | - { |
|
43 | - return self::arrayFilterNull(array_merge(array( |
|
44 | - 'name' => $this->name, |
|
45 | - 'description' => empty($this->description) ? null : $this->description, |
|
46 | - ), parent::toArray())); |
|
47 | - } |
|
48 | - |
|
49 | - public function getName() |
|
50 | - { |
|
51 | - return $this->name; |
|
52 | - } |
|
53 | - |
|
54 | - public function __toString() |
|
55 | - { |
|
56 | - return __CLASS__ . ' ' . $this->name; |
|
57 | - } |
|
16 | + private $name; |
|
17 | + private $description; |
|
18 | + |
|
19 | + public function __construct(AbstractObject $parent, $name, $description = null) |
|
20 | + { |
|
21 | + parent::__construct($parent); |
|
22 | + $this->name = $name; |
|
23 | + $this->description = $description; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string $command |
|
28 | + * @param string $data |
|
29 | + * @return AbstractObject|boolean |
|
30 | + */ |
|
31 | + public function handleCommand($command, $data = null) |
|
32 | + { |
|
33 | + if (strtolower($command) === 'description') { |
|
34 | + $this->description = $data; |
|
35 | + return $this; |
|
36 | + } |
|
37 | + |
|
38 | + return parent::handleCommand($command, $data); |
|
39 | + } |
|
40 | + |
|
41 | + public function toArray() |
|
42 | + { |
|
43 | + return self::arrayFilterNull(array_merge(array( |
|
44 | + 'name' => $this->name, |
|
45 | + 'description' => empty($this->description) ? null : $this->description, |
|
46 | + ), parent::toArray())); |
|
47 | + } |
|
48 | + |
|
49 | + public function getName() |
|
50 | + { |
|
51 | + return $this->name; |
|
52 | + } |
|
53 | + |
|
54 | + public function __toString() |
|
55 | + { |
|
56 | + return __CLASS__ . ' ' . $this->name; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -15,147 +15,147 @@ |
||
15 | 15 | class Parameter extends AbstractObject implements IParameter |
16 | 16 | { |
17 | 17 | |
18 | - private static $classTypes = array( |
|
19 | - 'integer' => 'Integer', |
|
20 | - 'int' => 'Integer', |
|
21 | - 'int32' => 'Integer', |
|
22 | - 'int64' => 'Integer', |
|
23 | - 'long' => 'Integer', |
|
24 | - 'float' => 'Number', |
|
25 | - 'double' => 'Number', |
|
26 | - 'string' => 'String', |
|
27 | - 'byte' => 'String', |
|
28 | - 'binary' => 'String', |
|
29 | - 'password' => 'String', |
|
30 | - 'enum' => 'String', |
|
31 | - 'uuid' => 'StringUuid', |
|
32 | - 'boolean' => 'Boolean', |
|
33 | - 'bool' => 'Boolean', |
|
34 | - 'array' => 'Array', |
|
35 | - 'csv' => 'Array', |
|
36 | - 'ssv' => 'Array', |
|
37 | - 'tsv' => 'Array', |
|
38 | - 'pipes' => 'Array', |
|
39 | - 'multi' => 'Array', |
|
40 | - 'date' => 'Date', |
|
41 | - 'datetime' => 'Date', |
|
42 | - 'date-time' => 'Date', |
|
43 | - 'file' => 'File', |
|
44 | - ); |
|
45 | - private $name = ''; |
|
46 | - private $in; |
|
47 | - private $description; |
|
48 | - private $required = false; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var Type\AbstractType |
|
52 | - */ |
|
53 | - private $Type; |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns true if the "multi" array collectionFormat is allowed for this |
|
57 | - * parameter. |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function isMulti(): bool |
|
61 | - { |
|
62 | - return in_array($this->in, array('query', 'form')); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Return true if the parameter is of type 'formData' |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isForm(): bool |
|
70 | - { |
|
71 | - return $this->in === 'form'; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @throws Exception |
|
76 | - */ |
|
77 | - public function __construct(AbstractObject $parent, $in, $data, $required = false) |
|
78 | - { |
|
79 | - parent::__construct($parent); |
|
80 | - |
|
81 | - if ($in !== 'path' && $in !== 'form' && $in !== 'query' && $in !== 'header') { |
|
82 | - throw new Exception("Invalid in for parameter: '{$in}'"); |
|
83 | - } |
|
84 | - $this->in = $in; |
|
85 | - |
|
86 | - $definition = self::wordShift($data); |
|
87 | - if (empty($definition)) { |
|
88 | - throw new Exception('No type definition for parameter'); |
|
89 | - } |
|
90 | - |
|
91 | - $name = self::wordShift($data); |
|
92 | - if (empty($name)) { |
|
93 | - throw new Exception('No name for parameter'); |
|
94 | - } else { |
|
95 | - $this->name = $name; |
|
96 | - } |
|
97 | - |
|
98 | - $this->description = $data; |
|
99 | - $this->required = (bool)$required; |
|
100 | - |
|
101 | - // Parse regex |
|
102 | - $match = array(); |
|
103 | - if (preg_match('/^([a-z][a-z0-9]*)/i', $definition, $match) === 1) { |
|
104 | - $format = strtolower($match[1]); |
|
105 | - } elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) { |
|
106 | - $format = 'array'; |
|
107 | - } elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) { |
|
108 | - $format = 'object'; |
|
109 | - } else { |
|
110 | - throw new Exception('Unparseable parameter format definition: \'' . $definition . '\''); |
|
111 | - } |
|
112 | - |
|
113 | - if ($this->getTypeRegistry()->has($format)) { |
|
114 | - $class = $this->getTypeRegistry()->get($format); |
|
115 | - $this->Type = new $class($this, $definition); |
|
116 | - } elseif (isset(self::$classTypes[$format])) { |
|
117 | - $type = self::$classTypes[$format]; |
|
118 | - $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type"; |
|
119 | - $this->Type = new $class($this, $definition); |
|
120 | - } else { |
|
121 | - throw new Exception("Type format not recognized: '{$format}'"); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $command |
|
127 | - * @param string $data |
|
128 | - * @return AbstractObject|boolean |
|
129 | - * @throws Exception |
|
130 | - */ |
|
131 | - public function handleCommand($command, $data = null) |
|
132 | - { |
|
133 | - // Pass through to Type |
|
134 | - if ($this->Type && $this->Type->handleCommand($command, $data)) { |
|
135 | - return $this; |
|
136 | - } |
|
137 | - |
|
138 | - return parent::handleCommand($command, $data); |
|
139 | - } |
|
140 | - |
|
141 | - public function toArray() |
|
142 | - { |
|
143 | - return self::arrayFilterNull(array_merge(array( |
|
144 | - 'name' => $this->name, |
|
145 | - 'in' => $this->in === 'form' ? 'formData' : $this->in, |
|
146 | - 'description' => empty($this->description) ? null : $this->description, |
|
147 | - 'required' => $this->in === 'path' || $this->required ? true : null, |
|
148 | - ), $this->Type->toArray(), parent::toArray())); |
|
149 | - } |
|
150 | - |
|
151 | - public function __toString() |
|
152 | - { |
|
153 | - return __CLASS__ . " {$this->name} {$this->in}"; |
|
154 | - } |
|
155 | - |
|
156 | - public function getName() |
|
157 | - { |
|
158 | - return $this->name; |
|
159 | - } |
|
18 | + private static $classTypes = array( |
|
19 | + 'integer' => 'Integer', |
|
20 | + 'int' => 'Integer', |
|
21 | + 'int32' => 'Integer', |
|
22 | + 'int64' => 'Integer', |
|
23 | + 'long' => 'Integer', |
|
24 | + 'float' => 'Number', |
|
25 | + 'double' => 'Number', |
|
26 | + 'string' => 'String', |
|
27 | + 'byte' => 'String', |
|
28 | + 'binary' => 'String', |
|
29 | + 'password' => 'String', |
|
30 | + 'enum' => 'String', |
|
31 | + 'uuid' => 'StringUuid', |
|
32 | + 'boolean' => 'Boolean', |
|
33 | + 'bool' => 'Boolean', |
|
34 | + 'array' => 'Array', |
|
35 | + 'csv' => 'Array', |
|
36 | + 'ssv' => 'Array', |
|
37 | + 'tsv' => 'Array', |
|
38 | + 'pipes' => 'Array', |
|
39 | + 'multi' => 'Array', |
|
40 | + 'date' => 'Date', |
|
41 | + 'datetime' => 'Date', |
|
42 | + 'date-time' => 'Date', |
|
43 | + 'file' => 'File', |
|
44 | + ); |
|
45 | + private $name = ''; |
|
46 | + private $in; |
|
47 | + private $description; |
|
48 | + private $required = false; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var Type\AbstractType |
|
52 | + */ |
|
53 | + private $Type; |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns true if the "multi" array collectionFormat is allowed for this |
|
57 | + * parameter. |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function isMulti(): bool |
|
61 | + { |
|
62 | + return in_array($this->in, array('query', 'form')); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Return true if the parameter is of type 'formData' |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isForm(): bool |
|
70 | + { |
|
71 | + return $this->in === 'form'; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @throws Exception |
|
76 | + */ |
|
77 | + public function __construct(AbstractObject $parent, $in, $data, $required = false) |
|
78 | + { |
|
79 | + parent::__construct($parent); |
|
80 | + |
|
81 | + if ($in !== 'path' && $in !== 'form' && $in !== 'query' && $in !== 'header') { |
|
82 | + throw new Exception("Invalid in for parameter: '{$in}'"); |
|
83 | + } |
|
84 | + $this->in = $in; |
|
85 | + |
|
86 | + $definition = self::wordShift($data); |
|
87 | + if (empty($definition)) { |
|
88 | + throw new Exception('No type definition for parameter'); |
|
89 | + } |
|
90 | + |
|
91 | + $name = self::wordShift($data); |
|
92 | + if (empty($name)) { |
|
93 | + throw new Exception('No name for parameter'); |
|
94 | + } else { |
|
95 | + $this->name = $name; |
|
96 | + } |
|
97 | + |
|
98 | + $this->description = $data; |
|
99 | + $this->required = (bool)$required; |
|
100 | + |
|
101 | + // Parse regex |
|
102 | + $match = array(); |
|
103 | + if (preg_match('/^([a-z][a-z0-9]*)/i', $definition, $match) === 1) { |
|
104 | + $format = strtolower($match[1]); |
|
105 | + } elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) { |
|
106 | + $format = 'array'; |
|
107 | + } elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) { |
|
108 | + $format = 'object'; |
|
109 | + } else { |
|
110 | + throw new Exception('Unparseable parameter format definition: \'' . $definition . '\''); |
|
111 | + } |
|
112 | + |
|
113 | + if ($this->getTypeRegistry()->has($format)) { |
|
114 | + $class = $this->getTypeRegistry()->get($format); |
|
115 | + $this->Type = new $class($this, $definition); |
|
116 | + } elseif (isset(self::$classTypes[$format])) { |
|
117 | + $type = self::$classTypes[$format]; |
|
118 | + $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type"; |
|
119 | + $this->Type = new $class($this, $definition); |
|
120 | + } else { |
|
121 | + throw new Exception("Type format not recognized: '{$format}'"); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $command |
|
127 | + * @param string $data |
|
128 | + * @return AbstractObject|boolean |
|
129 | + * @throws Exception |
|
130 | + */ |
|
131 | + public function handleCommand($command, $data = null) |
|
132 | + { |
|
133 | + // Pass through to Type |
|
134 | + if ($this->Type && $this->Type->handleCommand($command, $data)) { |
|
135 | + return $this; |
|
136 | + } |
|
137 | + |
|
138 | + return parent::handleCommand($command, $data); |
|
139 | + } |
|
140 | + |
|
141 | + public function toArray() |
|
142 | + { |
|
143 | + return self::arrayFilterNull(array_merge(array( |
|
144 | + 'name' => $this->name, |
|
145 | + 'in' => $this->in === 'form' ? 'formData' : $this->in, |
|
146 | + 'description' => empty($this->description) ? null : $this->description, |
|
147 | + 'required' => $this->in === 'path' || $this->required ? true : null, |
|
148 | + ), $this->Type->toArray(), parent::toArray())); |
|
149 | + } |
|
150 | + |
|
151 | + public function __toString() |
|
152 | + { |
|
153 | + return __CLASS__ . " {$this->name} {$this->in}"; |
|
154 | + } |
|
155 | + |
|
156 | + public function getName() |
|
157 | + { |
|
158 | + return $this->name; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | } |
@@ -96,7 +96,7 @@ |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | $this->description = $data; |
99 | - $this->required = (bool)$required; |
|
99 | + $this->required = (bool) $required; |
|
100 | 100 | |
101 | 101 | // Parse regex |
102 | 102 | $match = array(); |
@@ -115,7 +115,7 @@ |
||
115 | 115 | $this->Type = new $class($this, $definition); |
116 | 116 | } elseif (isset(self::$classTypes[$format])) { |
117 | 117 | $type = self::$classTypes[$format]; |
118 | - $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type"; |
|
118 | + $class = "\\SwaggerGen\\Swagger\\Type\\{$type}type"; |
|
119 | 119 | $this->Type = new $class($this, $definition); |
120 | 120 | } else { |
121 | 121 | throw new Exception("Type format not recognized: '{$format}'"); |
@@ -16,177 +16,177 @@ |
||
16 | 16 | class Response extends AbstractObject |
17 | 17 | { |
18 | 18 | |
19 | - const OK = 200; |
|
20 | - const CREATED = 201; |
|
21 | - const ACCEPTED = 202; |
|
22 | - const NON_AUTHORITATIVE_INFORMATION = 203; |
|
23 | - const NO_CONTENT = 204; |
|
24 | - const RESET_CONTENT = 205; |
|
25 | - const PARTIAL_CONTENT = 206; |
|
26 | - const BAD_REQUEST = 400; |
|
27 | - const UNAUTHORIZED = 401; |
|
28 | - const PAYMENT_REQUIRED = 402; |
|
29 | - const FORBIDDEN = 403; |
|
30 | - const NOT_FOUND = 404; |
|
31 | - const METHOD_NOT_ALLOWED = 405; |
|
32 | - const NOT_ACCEPTABLE = 406; |
|
33 | - const PROXY_AUTHENTICATION_REQUIRED = 407; |
|
34 | - const REQUEST_TIMEOUT = 408; |
|
35 | - const CONFLICT = 409; |
|
36 | - const GONE = 410; |
|
37 | - const LENGTH_REQUIRED = 411; |
|
38 | - const PRECONDITION_FAILED = 412; |
|
39 | - const REQUEST_ENTITY_TOO_LARGE = 413; |
|
40 | - const REQUEST_URI_TOO_LONG = 414; |
|
41 | - const UNSUPPORTED_MEDIA_TYPE = 415; |
|
42 | - const REQUESTED_RANGE_NOT_SATISFIABLE = 416; |
|
43 | - const EXPECTATION_FAILED = 417; |
|
44 | - const UNPROCESSABLE_ENTITY = 422; |
|
45 | - const TOO_MANY_REQUESTS = 429; |
|
46 | - const INTERNAL_SERVER_ERROR = 500; |
|
47 | - const NOT_IMPLEMENTED = 501; // When method is supported for none of the resources |
|
48 | - |
|
49 | - protected static $httpCodes = array( |
|
50 | - self::OK => 'OK', |
|
51 | - self::CREATED => 'Created', |
|
52 | - self::ACCEPTED => 'Accepted', |
|
53 | - self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information', |
|
54 | - self::NO_CONTENT => 'No Content', |
|
55 | - self::RESET_CONTENT => 'Reset Content', |
|
56 | - self::PARTIAL_CONTENT => 'Partial Content', |
|
57 | - self::BAD_REQUEST => 'Bad Request', |
|
58 | - self::UNAUTHORIZED => 'Unauthorized', |
|
59 | - self::PAYMENT_REQUIRED => 'Payment Required', |
|
60 | - self::FORBIDDEN => 'Forbidden', |
|
61 | - self::NOT_FOUND => 'Not Found', |
|
62 | - self::METHOD_NOT_ALLOWED => 'Method Not Allowed', |
|
63 | - self::NOT_ACCEPTABLE => 'Not Acceptable', |
|
64 | - self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', |
|
65 | - self::REQUEST_TIMEOUT => 'Request Timeout', |
|
66 | - self::CONFLICT => 'Conflict', |
|
67 | - self::GONE => 'Gone', |
|
68 | - self::LENGTH_REQUIRED => 'Length Required', |
|
69 | - self::PRECONDITION_FAILED => 'Precondition Failed', |
|
70 | - self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large', |
|
71 | - self::REQUEST_URI_TOO_LONG => 'Request-URI Too Long', |
|
72 | - self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', |
|
73 | - self::REQUESTED_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', |
|
74 | - self::EXPECTATION_FAILED => 'Expectation Failed', |
|
75 | - self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity', |
|
76 | - self::TOO_MANY_REQUESTS => 'Too Many Requests', |
|
77 | - self::INTERNAL_SERVER_ERROR => 'Internal Server Error', |
|
78 | - self::NOT_IMPLEMENTED => 'Not Implemented', |
|
79 | - ); |
|
80 | - private $description = ''; |
|
81 | - private $schema; |
|
82 | - |
|
83 | - /** |
|
84 | - * @var Header[] |
|
85 | - */ |
|
86 | - private $Headers = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * JSON examples |
|
90 | - * @var array |
|
91 | - */ |
|
92 | - private $examples = array(); |
|
93 | - |
|
94 | - public static function getCode($search) |
|
95 | - { |
|
96 | - static $lookup = null; |
|
97 | - |
|
98 | - if (is_numeric($search)) { |
|
99 | - return intval($search); |
|
100 | - } |
|
101 | - |
|
102 | - // build static lookup table |
|
103 | - if (!$lookup) { |
|
104 | - $lookup = array(); |
|
105 | - foreach (self::$httpCodes as $code => $text) { |
|
106 | - $lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code; |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - $search = preg_replace('/[^a-z]+/', '', strtolower($search)); |
|
111 | - return $lookup[$search] ?? null; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @throws Exception |
|
116 | - */ |
|
117 | - public function __construct(AbstractObject $parent, $code, $definition = null, $description = null) |
|
118 | - { |
|
119 | - parent::__construct($parent); |
|
120 | - |
|
121 | - if ($definition) { |
|
122 | - $this->schema = new Schema($this, $definition); |
|
123 | - } |
|
124 | - |
|
125 | - if (!empty($description)) { |
|
126 | - $this->description = $description; |
|
127 | - } elseif (isset(self::$httpCodes[$code])) { |
|
128 | - $this->description = self::$httpCodes[$code]; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $command |
|
134 | - * @param string $data |
|
135 | - * @return AbstractObject|boolean |
|
136 | - * @throws Exception |
|
137 | - * @throws Exception |
|
138 | - * @throws Exception |
|
139 | - * @throws Exception |
|
140 | - * @throws Exception |
|
141 | - */ |
|
142 | - public function handleCommand($command, $data = null) |
|
143 | - { |
|
144 | - switch (strtolower($command)) { |
|
145 | - case 'header': |
|
146 | - $type = self::wordShift($data); |
|
147 | - if (empty($type)) { |
|
148 | - throw new Exception('Missing type for header'); |
|
149 | - } |
|
150 | - $name = self::wordShift($data); |
|
151 | - if (empty($name)) { |
|
152 | - throw new Exception('Missing name for header type \'' . $type . '\''); |
|
153 | - } |
|
154 | - $Header = new Header($this, $type, $data); |
|
155 | - $this->Headers[$name] = $Header; |
|
156 | - return $Header; |
|
157 | - |
|
158 | - case 'example': |
|
159 | - $name = self::wordShift($data); |
|
160 | - if (empty($name)) { |
|
161 | - throw new Exception('Missing name for example'); |
|
162 | - } |
|
163 | - if ($data === '') { |
|
164 | - throw new Exception('Missing content for example `' . $name . '`'); |
|
165 | - } |
|
166 | - $json = preg_replace_callback('/([^{}:]+)/', function ($match) { |
|
167 | - json_decode($match[1]); |
|
168 | - return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]); |
|
169 | - }, trim($data)); |
|
170 | - $this->examples[$name] = json_decode($json, true); |
|
171 | - return $this; |
|
172 | - } |
|
173 | - |
|
174 | - return parent::handleCommand($command, $data); |
|
175 | - } |
|
176 | - |
|
177 | - public function toArray() |
|
178 | - { |
|
179 | - return self::arrayFilterNull(array_merge(array( |
|
180 | - 'description' => $this->description, |
|
181 | - 'schema' => $this->schema ? $this->schema->toArray() : null, |
|
182 | - 'headers' => self::objectsToArray($this->Headers), |
|
183 | - 'examples' => $this->examples, |
|
184 | - ), parent::toArray())); |
|
185 | - } |
|
186 | - |
|
187 | - public function __toString() |
|
188 | - { |
|
189 | - return __CLASS__; |
|
190 | - } |
|
19 | + const OK = 200; |
|
20 | + const CREATED = 201; |
|
21 | + const ACCEPTED = 202; |
|
22 | + const NON_AUTHORITATIVE_INFORMATION = 203; |
|
23 | + const NO_CONTENT = 204; |
|
24 | + const RESET_CONTENT = 205; |
|
25 | + const PARTIAL_CONTENT = 206; |
|
26 | + const BAD_REQUEST = 400; |
|
27 | + const UNAUTHORIZED = 401; |
|
28 | + const PAYMENT_REQUIRED = 402; |
|
29 | + const FORBIDDEN = 403; |
|
30 | + const NOT_FOUND = 404; |
|
31 | + const METHOD_NOT_ALLOWED = 405; |
|
32 | + const NOT_ACCEPTABLE = 406; |
|
33 | + const PROXY_AUTHENTICATION_REQUIRED = 407; |
|
34 | + const REQUEST_TIMEOUT = 408; |
|
35 | + const CONFLICT = 409; |
|
36 | + const GONE = 410; |
|
37 | + const LENGTH_REQUIRED = 411; |
|
38 | + const PRECONDITION_FAILED = 412; |
|
39 | + const REQUEST_ENTITY_TOO_LARGE = 413; |
|
40 | + const REQUEST_URI_TOO_LONG = 414; |
|
41 | + const UNSUPPORTED_MEDIA_TYPE = 415; |
|
42 | + const REQUESTED_RANGE_NOT_SATISFIABLE = 416; |
|
43 | + const EXPECTATION_FAILED = 417; |
|
44 | + const UNPROCESSABLE_ENTITY = 422; |
|
45 | + const TOO_MANY_REQUESTS = 429; |
|
46 | + const INTERNAL_SERVER_ERROR = 500; |
|
47 | + const NOT_IMPLEMENTED = 501; // When method is supported for none of the resources |
|
48 | + |
|
49 | + protected static $httpCodes = array( |
|
50 | + self::OK => 'OK', |
|
51 | + self::CREATED => 'Created', |
|
52 | + self::ACCEPTED => 'Accepted', |
|
53 | + self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information', |
|
54 | + self::NO_CONTENT => 'No Content', |
|
55 | + self::RESET_CONTENT => 'Reset Content', |
|
56 | + self::PARTIAL_CONTENT => 'Partial Content', |
|
57 | + self::BAD_REQUEST => 'Bad Request', |
|
58 | + self::UNAUTHORIZED => 'Unauthorized', |
|
59 | + self::PAYMENT_REQUIRED => 'Payment Required', |
|
60 | + self::FORBIDDEN => 'Forbidden', |
|
61 | + self::NOT_FOUND => 'Not Found', |
|
62 | + self::METHOD_NOT_ALLOWED => 'Method Not Allowed', |
|
63 | + self::NOT_ACCEPTABLE => 'Not Acceptable', |
|
64 | + self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', |
|
65 | + self::REQUEST_TIMEOUT => 'Request Timeout', |
|
66 | + self::CONFLICT => 'Conflict', |
|
67 | + self::GONE => 'Gone', |
|
68 | + self::LENGTH_REQUIRED => 'Length Required', |
|
69 | + self::PRECONDITION_FAILED => 'Precondition Failed', |
|
70 | + self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large', |
|
71 | + self::REQUEST_URI_TOO_LONG => 'Request-URI Too Long', |
|
72 | + self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', |
|
73 | + self::REQUESTED_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', |
|
74 | + self::EXPECTATION_FAILED => 'Expectation Failed', |
|
75 | + self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity', |
|
76 | + self::TOO_MANY_REQUESTS => 'Too Many Requests', |
|
77 | + self::INTERNAL_SERVER_ERROR => 'Internal Server Error', |
|
78 | + self::NOT_IMPLEMENTED => 'Not Implemented', |
|
79 | + ); |
|
80 | + private $description = ''; |
|
81 | + private $schema; |
|
82 | + |
|
83 | + /** |
|
84 | + * @var Header[] |
|
85 | + */ |
|
86 | + private $Headers = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * JSON examples |
|
90 | + * @var array |
|
91 | + */ |
|
92 | + private $examples = array(); |
|
93 | + |
|
94 | + public static function getCode($search) |
|
95 | + { |
|
96 | + static $lookup = null; |
|
97 | + |
|
98 | + if (is_numeric($search)) { |
|
99 | + return intval($search); |
|
100 | + } |
|
101 | + |
|
102 | + // build static lookup table |
|
103 | + if (!$lookup) { |
|
104 | + $lookup = array(); |
|
105 | + foreach (self::$httpCodes as $code => $text) { |
|
106 | + $lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code; |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + $search = preg_replace('/[^a-z]+/', '', strtolower($search)); |
|
111 | + return $lookup[$search] ?? null; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @throws Exception |
|
116 | + */ |
|
117 | + public function __construct(AbstractObject $parent, $code, $definition = null, $description = null) |
|
118 | + { |
|
119 | + parent::__construct($parent); |
|
120 | + |
|
121 | + if ($definition) { |
|
122 | + $this->schema = new Schema($this, $definition); |
|
123 | + } |
|
124 | + |
|
125 | + if (!empty($description)) { |
|
126 | + $this->description = $description; |
|
127 | + } elseif (isset(self::$httpCodes[$code])) { |
|
128 | + $this->description = self::$httpCodes[$code]; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $command |
|
134 | + * @param string $data |
|
135 | + * @return AbstractObject|boolean |
|
136 | + * @throws Exception |
|
137 | + * @throws Exception |
|
138 | + * @throws Exception |
|
139 | + * @throws Exception |
|
140 | + * @throws Exception |
|
141 | + */ |
|
142 | + public function handleCommand($command, $data = null) |
|
143 | + { |
|
144 | + switch (strtolower($command)) { |
|
145 | + case 'header': |
|
146 | + $type = self::wordShift($data); |
|
147 | + if (empty($type)) { |
|
148 | + throw new Exception('Missing type for header'); |
|
149 | + } |
|
150 | + $name = self::wordShift($data); |
|
151 | + if (empty($name)) { |
|
152 | + throw new Exception('Missing name for header type \'' . $type . '\''); |
|
153 | + } |
|
154 | + $Header = new Header($this, $type, $data); |
|
155 | + $this->Headers[$name] = $Header; |
|
156 | + return $Header; |
|
157 | + |
|
158 | + case 'example': |
|
159 | + $name = self::wordShift($data); |
|
160 | + if (empty($name)) { |
|
161 | + throw new Exception('Missing name for example'); |
|
162 | + } |
|
163 | + if ($data === '') { |
|
164 | + throw new Exception('Missing content for example `' . $name . '`'); |
|
165 | + } |
|
166 | + $json = preg_replace_callback('/([^{}:]+)/', function ($match) { |
|
167 | + json_decode($match[1]); |
|
168 | + return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]); |
|
169 | + }, trim($data)); |
|
170 | + $this->examples[$name] = json_decode($json, true); |
|
171 | + return $this; |
|
172 | + } |
|
173 | + |
|
174 | + return parent::handleCommand($command, $data); |
|
175 | + } |
|
176 | + |
|
177 | + public function toArray() |
|
178 | + { |
|
179 | + return self::arrayFilterNull(array_merge(array( |
|
180 | + 'description' => $this->description, |
|
181 | + 'schema' => $this->schema ? $this->schema->toArray() : null, |
|
182 | + 'headers' => self::objectsToArray($this->Headers), |
|
183 | + 'examples' => $this->examples, |
|
184 | + ), parent::toArray())); |
|
185 | + } |
|
186 | + |
|
187 | + public function __toString() |
|
188 | + { |
|
189 | + return __CLASS__; |
|
190 | + } |
|
191 | 191 | |
192 | 192 | } |
@@ -163,7 +163,7 @@ |
||
163 | 163 | if ($data === '') { |
164 | 164 | throw new Exception('Missing content for example `' . $name . '`'); |
165 | 165 | } |
166 | - $json = preg_replace_callback('/([^{}:]+)/', function ($match) { |
|
166 | + $json = preg_replace_callback('/([^{}:]+)/', function($match) { |
|
167 | 167 | json_decode($match[1]); |
168 | 168 | return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]); |
169 | 169 | }, trim($data)); |
@@ -16,132 +16,132 @@ |
||
16 | 16 | class SecurityScheme extends AbstractObject |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * 'basic', 'apikey' or 'oauth2' |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $type; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $description; |
|
29 | - private $name; |
|
30 | - private $in; |
|
31 | - private $flow; |
|
32 | - private $authorizationUrl; |
|
33 | - private $tokenUrl; |
|
34 | - |
|
35 | - /** |
|
36 | - * Map of scope-name => description |
|
37 | - * @var [] |
|
38 | - */ |
|
39 | - private $scopes = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * Create a new SecurityScheme object |
|
43 | - * @param AbstractObject $parent |
|
44 | - * @param string $type |
|
45 | - * @param string $data |
|
46 | - * @throws Exception |
|
47 | - */ |
|
48 | - public function __construct(AbstractObject $parent, $type, $data = null) |
|
49 | - { |
|
50 | - parent::__construct($parent); |
|
51 | - |
|
52 | - if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) { |
|
53 | - throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'"); |
|
54 | - } |
|
55 | - $this->type = strtolower($type); |
|
56 | - |
|
57 | - switch ($this->type) { |
|
58 | - case 'basic': |
|
59 | - $this->description = $data; |
|
60 | - break; |
|
61 | - |
|
62 | - case 'apikey': |
|
63 | - $this->name = self::wordShift($data); |
|
64 | - |
|
65 | - $in = strtolower(self::wordShift($data)); |
|
66 | - if (!in_array($in, array('query', 'header'))) { |
|
67 | - throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'"); |
|
68 | - } |
|
69 | - $this->in = $in; |
|
70 | - |
|
71 | - $this->description = $data; |
|
72 | - break; |
|
73 | - |
|
74 | - case 'oauth2': |
|
75 | - $flow = strtolower(self::wordShift($data)); |
|
76 | - if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) { |
|
77 | - throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'"); |
|
78 | - } |
|
79 | - $this->flow = $flow; |
|
80 | - |
|
81 | - if (in_array($flow, array('implicit', 'accesscode'))) { |
|
82 | - $authUrl = self::wordShift($data); |
|
83 | - if (!filter_var($authUrl, FILTER_VALIDATE_URL)) { |
|
84 | - throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'"); |
|
85 | - } |
|
86 | - $this->authorizationUrl = $authUrl; |
|
87 | - } |
|
88 | - |
|
89 | - if (in_array($flow, array('password', 'application', 'accesscode'))) { |
|
90 | - $tokenUrl = self::wordShift($data); |
|
91 | - if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) { |
|
92 | - throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'"); |
|
93 | - } |
|
94 | - $this->tokenUrl = $tokenUrl; |
|
95 | - } |
|
96 | - |
|
97 | - $this->description = $data; |
|
98 | - break; |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $command |
|
104 | - * @param string $data |
|
105 | - * @return AbstractObject|boolean |
|
106 | - * @throws Exception |
|
107 | - */ |
|
108 | - public function handleCommand($command, $data = null) |
|
109 | - { |
|
110 | - switch (strtolower($command)) { |
|
111 | - case 'description': |
|
112 | - $this->description = $data; |
|
113 | - return $this; |
|
114 | - |
|
115 | - case 'scope': |
|
116 | - if ($this->type !== 'oauth2') { |
|
117 | - throw new Exception("Cannot set scope on type '{$this->type}'"); |
|
118 | - } |
|
119 | - |
|
120 | - $name = self::wordShift($data); |
|
121 | - $this->scopes[$name] = $data; |
|
122 | - return $this; |
|
123 | - } |
|
124 | - |
|
125 | - return parent::handleCommand($command, $data); |
|
126 | - } |
|
127 | - |
|
128 | - public function toArray() |
|
129 | - { |
|
130 | - return self::arrayFilterNull(array_merge(array( |
|
131 | - 'type' => $this->type === 'apikey' ? 'apiKey' : $this->type, |
|
132 | - 'description' => empty($this->description) ? null : $this->description, |
|
133 | - 'name' => $this->name, |
|
134 | - 'in' => $this->in, |
|
135 | - 'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow, |
|
136 | - 'authorizationUrl' => $this->authorizationUrl, |
|
137 | - 'tokenUrl' => $this->tokenUrl, |
|
138 | - 'scopes' => $this->scopes, |
|
139 | - ), parent::toArray())); |
|
140 | - } |
|
141 | - |
|
142 | - public function __toString() |
|
143 | - { |
|
144 | - return __CLASS__ . ' ' . $this->type; |
|
145 | - } |
|
19 | + /** |
|
20 | + * 'basic', 'apikey' or 'oauth2' |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $type; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $description; |
|
29 | + private $name; |
|
30 | + private $in; |
|
31 | + private $flow; |
|
32 | + private $authorizationUrl; |
|
33 | + private $tokenUrl; |
|
34 | + |
|
35 | + /** |
|
36 | + * Map of scope-name => description |
|
37 | + * @var [] |
|
38 | + */ |
|
39 | + private $scopes = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * Create a new SecurityScheme object |
|
43 | + * @param AbstractObject $parent |
|
44 | + * @param string $type |
|
45 | + * @param string $data |
|
46 | + * @throws Exception |
|
47 | + */ |
|
48 | + public function __construct(AbstractObject $parent, $type, $data = null) |
|
49 | + { |
|
50 | + parent::__construct($parent); |
|
51 | + |
|
52 | + if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) { |
|
53 | + throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'"); |
|
54 | + } |
|
55 | + $this->type = strtolower($type); |
|
56 | + |
|
57 | + switch ($this->type) { |
|
58 | + case 'basic': |
|
59 | + $this->description = $data; |
|
60 | + break; |
|
61 | + |
|
62 | + case 'apikey': |
|
63 | + $this->name = self::wordShift($data); |
|
64 | + |
|
65 | + $in = strtolower(self::wordShift($data)); |
|
66 | + if (!in_array($in, array('query', 'header'))) { |
|
67 | + throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'"); |
|
68 | + } |
|
69 | + $this->in = $in; |
|
70 | + |
|
71 | + $this->description = $data; |
|
72 | + break; |
|
73 | + |
|
74 | + case 'oauth2': |
|
75 | + $flow = strtolower(self::wordShift($data)); |
|
76 | + if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) { |
|
77 | + throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'"); |
|
78 | + } |
|
79 | + $this->flow = $flow; |
|
80 | + |
|
81 | + if (in_array($flow, array('implicit', 'accesscode'))) { |
|
82 | + $authUrl = self::wordShift($data); |
|
83 | + if (!filter_var($authUrl, FILTER_VALIDATE_URL)) { |
|
84 | + throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'"); |
|
85 | + } |
|
86 | + $this->authorizationUrl = $authUrl; |
|
87 | + } |
|
88 | + |
|
89 | + if (in_array($flow, array('password', 'application', 'accesscode'))) { |
|
90 | + $tokenUrl = self::wordShift($data); |
|
91 | + if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) { |
|
92 | + throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'"); |
|
93 | + } |
|
94 | + $this->tokenUrl = $tokenUrl; |
|
95 | + } |
|
96 | + |
|
97 | + $this->description = $data; |
|
98 | + break; |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $command |
|
104 | + * @param string $data |
|
105 | + * @return AbstractObject|boolean |
|
106 | + * @throws Exception |
|
107 | + */ |
|
108 | + public function handleCommand($command, $data = null) |
|
109 | + { |
|
110 | + switch (strtolower($command)) { |
|
111 | + case 'description': |
|
112 | + $this->description = $data; |
|
113 | + return $this; |
|
114 | + |
|
115 | + case 'scope': |
|
116 | + if ($this->type !== 'oauth2') { |
|
117 | + throw new Exception("Cannot set scope on type '{$this->type}'"); |
|
118 | + } |
|
119 | + |
|
120 | + $name = self::wordShift($data); |
|
121 | + $this->scopes[$name] = $data; |
|
122 | + return $this; |
|
123 | + } |
|
124 | + |
|
125 | + return parent::handleCommand($command, $data); |
|
126 | + } |
|
127 | + |
|
128 | + public function toArray() |
|
129 | + { |
|
130 | + return self::arrayFilterNull(array_merge(array( |
|
131 | + 'type' => $this->type === 'apikey' ? 'apiKey' : $this->type, |
|
132 | + 'description' => empty($this->description) ? null : $this->description, |
|
133 | + 'name' => $this->name, |
|
134 | + 'in' => $this->in, |
|
135 | + 'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow, |
|
136 | + 'authorizationUrl' => $this->authorizationUrl, |
|
137 | + 'tokenUrl' => $this->tokenUrl, |
|
138 | + 'scopes' => $this->scopes, |
|
139 | + ), parent::toArray())); |
|
140 | + } |
|
141 | + |
|
142 | + public function __toString() |
|
143 | + { |
|
144 | + return __CLASS__ . ' ' . $this->type; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
@@ -82,7 +82,7 @@ |
||
82 | 82 | public function toArray() |
83 | 83 | { |
84 | 84 | $methods = self::$methods; |
85 | - uksort($this->operations, function ($a, $b) use ($methods) { |
|
85 | + uksort($this->operations, function($a, $b) use ($methods) { |
|
86 | 86 | return array_search($a, $methods) - array_search($b, $methods); |
87 | 87 | }); |
88 | 88 |
@@ -16,102 +16,102 @@ |
||
16 | 16 | class Path extends AbstractObject |
17 | 17 | { |
18 | 18 | |
19 | - private static $methods = array( |
|
20 | - 'get', |
|
21 | - 'put', |
|
22 | - 'post', |
|
23 | - 'delete', |
|
24 | - 'options', |
|
25 | - 'head', |
|
26 | - 'patch', |
|
27 | - ); |
|
28 | - |
|
29 | - /** |
|
30 | - * @var Operation[] $operation |
|
31 | - */ |
|
32 | - private $operations = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Tag|null $tag ; |
|
36 | - */ |
|
37 | - private $tag; |
|
38 | - |
|
39 | - public function __construct(AbstractObject $parent, ?Tag $Tag = null) |
|
40 | - { |
|
41 | - parent::__construct($parent); |
|
42 | - $this->tag = $Tag; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $command |
|
47 | - * @param string $data |
|
48 | - * @return AbstractObject|boolean |
|
49 | - * @throws Exception |
|
50 | - */ |
|
51 | - public function handleCommand($command, $data = null) |
|
52 | - { |
|
53 | - switch (strtolower($command)) { |
|
54 | - case 'method': // alias |
|
55 | - case 'operation': |
|
56 | - $method = strtolower(self::wordShift($data)); |
|
57 | - |
|
58 | - if (!in_array($method, self::$methods)) { |
|
59 | - throw new Exception('Unrecognized operation method \'' . $method . '\''); |
|
60 | - } |
|
61 | - |
|
62 | - if (isset($this->operations[$method])) { |
|
63 | - $Operation = $this->operations[$method]; |
|
64 | - } else { |
|
65 | - $summary = $data; |
|
66 | - $Operation = new Operation($this, $summary, $this->tag); |
|
67 | - $this->operations[$method] = $Operation; |
|
68 | - } |
|
69 | - |
|
70 | - return $Operation; |
|
71 | - |
|
72 | - case 'description': |
|
73 | - if ($this->tag) { |
|
74 | - return $this->tag->handleCommand($command, $data); |
|
75 | - } |
|
76 | - break; |
|
77 | - } |
|
78 | - |
|
79 | - return parent::handleCommand($command, $data); |
|
80 | - } |
|
81 | - |
|
82 | - public function toArray() |
|
83 | - { |
|
84 | - $methods = self::$methods; |
|
85 | - uksort($this->operations, function ($a, $b) use ($methods) { |
|
86 | - return array_search($a, $methods) - array_search($b, $methods); |
|
87 | - }); |
|
88 | - |
|
89 | - return self::arrayFilterNull(array_merge( |
|
90 | - self::objectsToArray($this->operations) |
|
91 | - , parent::toArray())); |
|
92 | - } |
|
93 | - |
|
94 | - public function __toString() |
|
95 | - { |
|
96 | - end($this->operations); |
|
97 | - return __CLASS__ . ' ' . key($this->operations); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Check if an operation with the given id is registered to this Path. |
|
102 | - * |
|
103 | - * @param string $operationId |
|
104 | - * @return boolean |
|
105 | - */ |
|
106 | - public function hasOperationId($operationId) |
|
107 | - { |
|
108 | - foreach ($this->operations as $operation) { |
|
109 | - if ($operation->getId() === $operationId) { |
|
110 | - return true; |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - return false; |
|
115 | - } |
|
19 | + private static $methods = array( |
|
20 | + 'get', |
|
21 | + 'put', |
|
22 | + 'post', |
|
23 | + 'delete', |
|
24 | + 'options', |
|
25 | + 'head', |
|
26 | + 'patch', |
|
27 | + ); |
|
28 | + |
|
29 | + /** |
|
30 | + * @var Operation[] $operation |
|
31 | + */ |
|
32 | + private $operations = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Tag|null $tag ; |
|
36 | + */ |
|
37 | + private $tag; |
|
38 | + |
|
39 | + public function __construct(AbstractObject $parent, ?Tag $Tag = null) |
|
40 | + { |
|
41 | + parent::__construct($parent); |
|
42 | + $this->tag = $Tag; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $command |
|
47 | + * @param string $data |
|
48 | + * @return AbstractObject|boolean |
|
49 | + * @throws Exception |
|
50 | + */ |
|
51 | + public function handleCommand($command, $data = null) |
|
52 | + { |
|
53 | + switch (strtolower($command)) { |
|
54 | + case 'method': // alias |
|
55 | + case 'operation': |
|
56 | + $method = strtolower(self::wordShift($data)); |
|
57 | + |
|
58 | + if (!in_array($method, self::$methods)) { |
|
59 | + throw new Exception('Unrecognized operation method \'' . $method . '\''); |
|
60 | + } |
|
61 | + |
|
62 | + if (isset($this->operations[$method])) { |
|
63 | + $Operation = $this->operations[$method]; |
|
64 | + } else { |
|
65 | + $summary = $data; |
|
66 | + $Operation = new Operation($this, $summary, $this->tag); |
|
67 | + $this->operations[$method] = $Operation; |
|
68 | + } |
|
69 | + |
|
70 | + return $Operation; |
|
71 | + |
|
72 | + case 'description': |
|
73 | + if ($this->tag) { |
|
74 | + return $this->tag->handleCommand($command, $data); |
|
75 | + } |
|
76 | + break; |
|
77 | + } |
|
78 | + |
|
79 | + return parent::handleCommand($command, $data); |
|
80 | + } |
|
81 | + |
|
82 | + public function toArray() |
|
83 | + { |
|
84 | + $methods = self::$methods; |
|
85 | + uksort($this->operations, function ($a, $b) use ($methods) { |
|
86 | + return array_search($a, $methods) - array_search($b, $methods); |
|
87 | + }); |
|
88 | + |
|
89 | + return self::arrayFilterNull(array_merge( |
|
90 | + self::objectsToArray($this->operations) |
|
91 | + , parent::toArray())); |
|
92 | + } |
|
93 | + |
|
94 | + public function __toString() |
|
95 | + { |
|
96 | + end($this->operations); |
|
97 | + return __CLASS__ . ' ' . key($this->operations); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Check if an operation with the given id is registered to this Path. |
|
102 | + * |
|
103 | + * @param string $operationId |
|
104 | + * @return boolean |
|
105 | + */ |
|
106 | + public function hasOperationId($operationId) |
|
107 | + { |
|
108 | + foreach ($this->operations as $operation) { |
|
109 | + if ($operation->getId() === $operationId) { |
|
110 | + return true; |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + return false; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |