@@ -16,383 +16,383 @@ |
||
16 | 16 | class Swagger extends AbstractDocumentableObject |
17 | 17 | { |
18 | 18 | |
19 | - private $swagger = '2.0'; |
|
20 | - private $host; |
|
21 | - private $basePath; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var TypeRegistry |
|
25 | - */ |
|
26 | - private $typeRegistry; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var Info $Info |
|
30 | - */ |
|
31 | - private $info; |
|
32 | - private $schemes = []; |
|
33 | - private $consumes = []; |
|
34 | - private $produces = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Path[] $Paths |
|
38 | - */ |
|
39 | - private $paths = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var Schema[] $definitions |
|
43 | - */ |
|
44 | - private $definitions = []; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var IParameter[] $parameters |
|
48 | - */ |
|
49 | - private $parameters = []; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var Response[] $responses |
|
53 | - */ |
|
54 | - private $responses = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var Tag[] $Tags |
|
58 | - */ |
|
59 | - private $tags = []; |
|
60 | - |
|
61 | - /** |
|
62 | - * Default tag for new endpoints/operations. Set by the api command. |
|
63 | - * |
|
64 | - * @var Tag |
|
65 | - */ |
|
66 | - private $defaultTag = null; |
|
67 | - private $securityDefinitions = []; |
|
68 | - private $security = []; |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $host |
|
72 | - * @param string $basePath |
|
73 | - * @param TypeRegistry $typeRegistry |
|
74 | - */ |
|
75 | - public function __construct($host = null, $basePath = null, $typeRegistry = null) |
|
76 | - { |
|
77 | - parent::__construct(); |
|
78 | - |
|
79 | - $this->host = $host; |
|
80 | - $this->basePath = $basePath; |
|
81 | - |
|
82 | - $this->info = new Info($this); |
|
83 | - |
|
84 | - $this->typeRegistry = $typeRegistry ?: new TypeRegistry; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @inheritDoc |
|
89 | - */ |
|
90 | - protected function getSwagger() |
|
91 | - { |
|
92 | - return $this; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @inheritDoc |
|
97 | - */ |
|
98 | - protected function getTypeRegistry() |
|
99 | - { |
|
100 | - return $this->typeRegistry; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Return all consumes |
|
105 | - * |
|
106 | - * @return array |
|
107 | - * @todo Deprecate in favour of a getConsume($name); |
|
108 | - */ |
|
109 | - public function getConsumes(): array |
|
110 | - { |
|
111 | - return $this->consumes; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Return the named security if it exists, otherwise return FALSE |
|
116 | - * |
|
117 | - * @param string $name |
|
118 | - * |
|
119 | - * @return boolean|SecurityScheme |
|
120 | - */ |
|
121 | - public function getSecurity($name) |
|
122 | - { |
|
123 | - if (isset($this->securityDefinitions[$name])) { |
|
124 | - return $this->securityDefinitions[$name]; |
|
125 | - } |
|
126 | - |
|
127 | - return false; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $command |
|
132 | - * @param string $data |
|
133 | - * |
|
134 | - * @return AbstractObject|boolean |
|
135 | - * @throws Exception |
|
136 | - * @throws Exception |
|
137 | - * @throws Exception |
|
138 | - * @throws Exception |
|
139 | - * @throws Exception |
|
140 | - * @throws Exception |
|
141 | - * @throws Exception |
|
142 | - * @throws Exception |
|
143 | - * @throws Exception |
|
144 | - */ |
|
145 | - public function handleCommand($command, $data = null) |
|
146 | - { |
|
147 | - switch (strtolower($command)) { |
|
148 | - // pass to Info |
|
149 | - case 'title': |
|
150 | - case 'description': |
|
151 | - case 'version': |
|
152 | - case 'terms': // alias |
|
153 | - case 'tos': // alias |
|
154 | - case 'termsofservice': |
|
155 | - case 'contact': |
|
156 | - case 'license': |
|
157 | - return $this->info->handleCommand($command, $data); |
|
158 | - |
|
159 | - // string[] |
|
160 | - case 'scheme': |
|
161 | - case 'schemes': |
|
162 | - $this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data))); |
|
163 | - |
|
164 | - return $this; |
|
165 | - |
|
166 | - // MIME[] |
|
167 | - case 'consume': |
|
168 | - case 'consumes': |
|
169 | - $this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data))); |
|
170 | - |
|
171 | - return $this; |
|
172 | - |
|
173 | - case 'produce': |
|
174 | - case 'produces': |
|
175 | - $this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data))); |
|
176 | - |
|
177 | - return $this; |
|
178 | - |
|
179 | - case 'model': |
|
180 | - case 'model!': |
|
181 | - case 'definition': |
|
182 | - case 'definition!': |
|
183 | - $name = self::wordShift($data); |
|
184 | - if (empty($name)) { |
|
185 | - throw new Exception('Missing definition name'); |
|
186 | - } |
|
187 | - $typeDef = self::wordShift($data); |
|
188 | - if (empty($typeDef)) { |
|
189 | - $typeDef = 'object'; |
|
190 | - } |
|
191 | - |
|
192 | - $definition = new Schema($this, $typeDef); |
|
193 | - if (substr($command, -1) === '!') { |
|
194 | - $definition->setReadOnly(); |
|
195 | - } |
|
196 | - $this->definitions[$name] = $definition; |
|
197 | - |
|
198 | - return $definition; |
|
199 | - |
|
200 | - case 'path': |
|
201 | - case 'query': |
|
202 | - case 'query?': |
|
203 | - case 'header': |
|
204 | - case 'header?': |
|
205 | - case 'form': |
|
206 | - case 'form?': |
|
207 | - $in = rtrim($command, '?'); |
|
208 | - $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
|
209 | - $this->parameters[$Parameter->getName()] = $Parameter; |
|
210 | - |
|
211 | - return $Parameter; |
|
212 | - |
|
213 | - case 'body': |
|
214 | - case 'body?': |
|
215 | - $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
|
216 | - $this->parameters[$Parameter->getName()] = $Parameter; |
|
217 | - |
|
218 | - return $Parameter; |
|
219 | - |
|
220 | - case 'response': |
|
221 | - $name = self::wordShift($data); |
|
222 | - $definition = self::wordShift($data); |
|
223 | - $description = $data; |
|
224 | - if (empty($description)) { |
|
225 | - throw new Exception('Response definition missing description'); |
|
226 | - } |
|
227 | - $Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description); |
|
228 | - $this->responses[$name] = $Response; |
|
229 | - |
|
230 | - return $Response; |
|
231 | - |
|
232 | - case 'api': // alias |
|
233 | - case 'tag': |
|
234 | - $tagname = self::wordShift($data); |
|
235 | - if (empty($tagname)) { |
|
236 | - throw new Exception('Missing tag name'); |
|
237 | - } |
|
238 | - |
|
239 | - $Tag = null; |
|
240 | - foreach ($this->tags as $T) { |
|
241 | - if ($T->getName() === $tagname) { |
|
242 | - $Tag = $T; |
|
243 | - break; |
|
244 | - } |
|
245 | - } |
|
246 | - if (!$Tag) { |
|
247 | - $Tag = new Tag($this, $tagname, $data); |
|
248 | - $this->tags[] = $Tag; |
|
249 | - } |
|
250 | - |
|
251 | - // backwards compatibility |
|
252 | - if ($command === 'api') { |
|
253 | - $this->defaultTag = $Tag; |
|
254 | - } |
|
255 | - |
|
256 | - return $Tag; |
|
257 | - |
|
258 | - case 'endpoint': |
|
259 | - $path = self::wordShift($data); |
|
260 | - if (false === $path) { |
|
261 | - $path = '/'; |
|
262 | - } else if ($path[0] !== '/') { |
|
263 | - $path = '/' . $path; |
|
264 | - } |
|
265 | - |
|
266 | - $Tag = null; |
|
267 | - if (($tagname = self::wordShift($data)) !== false) { |
|
268 | - foreach ($this->tags as $T) { |
|
269 | - if (strtolower($T->getName()) === strtolower($tagname)) { |
|
270 | - $Tag = $T; |
|
271 | - break; |
|
272 | - } |
|
273 | - } |
|
274 | - if (!$Tag) { |
|
275 | - $Tag = new Tag($this, $tagname, $data); |
|
276 | - $this->tags[] = $Tag; |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - if (!isset($this->paths[$path])) { |
|
281 | - $this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag); |
|
282 | - } |
|
283 | - |
|
284 | - return $this->paths[$path]; |
|
285 | - |
|
286 | - case 'security': |
|
287 | - $name = self::wordShift($data); |
|
288 | - if (empty($name)) { |
|
289 | - throw new Exception('Missing security name'); |
|
290 | - } |
|
291 | - $type = self::wordShift($data); |
|
292 | - if (empty($type)) { |
|
293 | - throw new Exception('Missing security type'); |
|
294 | - } |
|
295 | - $SecurityScheme = new SecurityScheme($this, $type, $data); |
|
296 | - $this->securityDefinitions[$name] = $SecurityScheme; |
|
297 | - |
|
298 | - return $SecurityScheme; |
|
299 | - |
|
300 | - case 'require': |
|
301 | - $name = self::wordShift($data); |
|
302 | - if (empty($name)) { |
|
303 | - throw new Exception('Missing require name'); |
|
304 | - } |
|
305 | - $scopes = self::wordSplit($data); |
|
306 | - sort($scopes); |
|
307 | - $this->security[] = [ |
|
308 | - $name => empty($scopes) ? [] : $scopes, |
|
309 | - ]; |
|
310 | - |
|
311 | - return $this; |
|
312 | - } |
|
313 | - |
|
314 | - return parent::handleCommand($command, $data); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @inheritDoc |
|
319 | - * @throws Exception |
|
320 | - * @throws Exception |
|
321 | - */ |
|
322 | - public function toArray() |
|
323 | - { |
|
324 | - if (empty($this->paths)) { |
|
325 | - throw new Exception('No path defined'); |
|
326 | - } |
|
327 | - |
|
328 | - $schemes = array_unique($this->schemes); |
|
329 | - sort($schemes); |
|
330 | - |
|
331 | - $consumes = array_unique($this->consumes); |
|
332 | - sort($consumes); |
|
333 | - |
|
334 | - $produces = array_unique($this->produces); |
|
335 | - sort($produces); |
|
336 | - |
|
337 | - foreach ($this->security as $security) { |
|
338 | - foreach ($security as $name => $scopes) { |
|
339 | - if (!isset($this->securityDefinitions[$name])) { |
|
340 | - throw new Exception('Required security scheme not defined: \'' . $name . '\''); |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - return self::arrayFilterNull(array_merge([ |
|
346 | - 'swagger' => $this->swagger, |
|
347 | - 'info' => $this->info->toArray(), |
|
348 | - 'host' => empty($this->host) ? null : $this->host, |
|
349 | - 'basePath' => empty($this->basePath) ? null : $this->basePath, |
|
350 | - 'consumes' => $consumes, |
|
351 | - 'produces' => $produces, |
|
352 | - 'schemes' => $schemes, |
|
353 | - 'paths' => self::objectsToArray($this->paths), |
|
354 | - 'definitions' => self::objectsToArray($this->definitions), |
|
355 | - 'parameters' => self::objectsToArray($this->parameters), |
|
356 | - 'responses' => self::objectsToArray($this->responses), |
|
357 | - 'securityDefinitions' => self::objectsToArray($this->securityDefinitions), |
|
358 | - 'security' => $this->security, |
|
359 | - 'tags' => self::objectsToArray($this->tags), |
|
360 | - ], parent::toArray())); |
|
361 | - } |
|
362 | - |
|
363 | - public function __toString() |
|
364 | - { |
|
365 | - return __CLASS__; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Check if an operation with the given id exists. |
|
370 | - * |
|
371 | - * @param string $operationId |
|
372 | - * |
|
373 | - * @return boolean |
|
374 | - */ |
|
375 | - public function hasOperationId($operationId) |
|
376 | - { |
|
377 | - foreach ($this->paths as $path) { |
|
378 | - if ($path->hasOperationId($operationId)) { |
|
379 | - return true; |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - return false; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Check if a definition with the given name exists |
|
388 | - * |
|
389 | - * @param string $name |
|
390 | - * |
|
391 | - * @return boolean |
|
392 | - */ |
|
393 | - public function hasDefinition($name) |
|
394 | - { |
|
395 | - return isset($this->definitions[$name]); |
|
396 | - } |
|
19 | + private $swagger = '2.0'; |
|
20 | + private $host; |
|
21 | + private $basePath; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var TypeRegistry |
|
25 | + */ |
|
26 | + private $typeRegistry; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var Info $Info |
|
30 | + */ |
|
31 | + private $info; |
|
32 | + private $schemes = []; |
|
33 | + private $consumes = []; |
|
34 | + private $produces = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Path[] $Paths |
|
38 | + */ |
|
39 | + private $paths = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var Schema[] $definitions |
|
43 | + */ |
|
44 | + private $definitions = []; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var IParameter[] $parameters |
|
48 | + */ |
|
49 | + private $parameters = []; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var Response[] $responses |
|
53 | + */ |
|
54 | + private $responses = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var Tag[] $Tags |
|
58 | + */ |
|
59 | + private $tags = []; |
|
60 | + |
|
61 | + /** |
|
62 | + * Default tag for new endpoints/operations. Set by the api command. |
|
63 | + * |
|
64 | + * @var Tag |
|
65 | + */ |
|
66 | + private $defaultTag = null; |
|
67 | + private $securityDefinitions = []; |
|
68 | + private $security = []; |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $host |
|
72 | + * @param string $basePath |
|
73 | + * @param TypeRegistry $typeRegistry |
|
74 | + */ |
|
75 | + public function __construct($host = null, $basePath = null, $typeRegistry = null) |
|
76 | + { |
|
77 | + parent::__construct(); |
|
78 | + |
|
79 | + $this->host = $host; |
|
80 | + $this->basePath = $basePath; |
|
81 | + |
|
82 | + $this->info = new Info($this); |
|
83 | + |
|
84 | + $this->typeRegistry = $typeRegistry ?: new TypeRegistry; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @inheritDoc |
|
89 | + */ |
|
90 | + protected function getSwagger() |
|
91 | + { |
|
92 | + return $this; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @inheritDoc |
|
97 | + */ |
|
98 | + protected function getTypeRegistry() |
|
99 | + { |
|
100 | + return $this->typeRegistry; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Return all consumes |
|
105 | + * |
|
106 | + * @return array |
|
107 | + * @todo Deprecate in favour of a getConsume($name); |
|
108 | + */ |
|
109 | + public function getConsumes(): array |
|
110 | + { |
|
111 | + return $this->consumes; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Return the named security if it exists, otherwise return FALSE |
|
116 | + * |
|
117 | + * @param string $name |
|
118 | + * |
|
119 | + * @return boolean|SecurityScheme |
|
120 | + */ |
|
121 | + public function getSecurity($name) |
|
122 | + { |
|
123 | + if (isset($this->securityDefinitions[$name])) { |
|
124 | + return $this->securityDefinitions[$name]; |
|
125 | + } |
|
126 | + |
|
127 | + return false; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $command |
|
132 | + * @param string $data |
|
133 | + * |
|
134 | + * @return AbstractObject|boolean |
|
135 | + * @throws Exception |
|
136 | + * @throws Exception |
|
137 | + * @throws Exception |
|
138 | + * @throws Exception |
|
139 | + * @throws Exception |
|
140 | + * @throws Exception |
|
141 | + * @throws Exception |
|
142 | + * @throws Exception |
|
143 | + * @throws Exception |
|
144 | + */ |
|
145 | + public function handleCommand($command, $data = null) |
|
146 | + { |
|
147 | + switch (strtolower($command)) { |
|
148 | + // pass to Info |
|
149 | + case 'title': |
|
150 | + case 'description': |
|
151 | + case 'version': |
|
152 | + case 'terms': // alias |
|
153 | + case 'tos': // alias |
|
154 | + case 'termsofservice': |
|
155 | + case 'contact': |
|
156 | + case 'license': |
|
157 | + return $this->info->handleCommand($command, $data); |
|
158 | + |
|
159 | + // string[] |
|
160 | + case 'scheme': |
|
161 | + case 'schemes': |
|
162 | + $this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data))); |
|
163 | + |
|
164 | + return $this; |
|
165 | + |
|
166 | + // MIME[] |
|
167 | + case 'consume': |
|
168 | + case 'consumes': |
|
169 | + $this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data))); |
|
170 | + |
|
171 | + return $this; |
|
172 | + |
|
173 | + case 'produce': |
|
174 | + case 'produces': |
|
175 | + $this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data))); |
|
176 | + |
|
177 | + return $this; |
|
178 | + |
|
179 | + case 'model': |
|
180 | + case 'model!': |
|
181 | + case 'definition': |
|
182 | + case 'definition!': |
|
183 | + $name = self::wordShift($data); |
|
184 | + if (empty($name)) { |
|
185 | + throw new Exception('Missing definition name'); |
|
186 | + } |
|
187 | + $typeDef = self::wordShift($data); |
|
188 | + if (empty($typeDef)) { |
|
189 | + $typeDef = 'object'; |
|
190 | + } |
|
191 | + |
|
192 | + $definition = new Schema($this, $typeDef); |
|
193 | + if (substr($command, -1) === '!') { |
|
194 | + $definition->setReadOnly(); |
|
195 | + } |
|
196 | + $this->definitions[$name] = $definition; |
|
197 | + |
|
198 | + return $definition; |
|
199 | + |
|
200 | + case 'path': |
|
201 | + case 'query': |
|
202 | + case 'query?': |
|
203 | + case 'header': |
|
204 | + case 'header?': |
|
205 | + case 'form': |
|
206 | + case 'form?': |
|
207 | + $in = rtrim($command, '?'); |
|
208 | + $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
|
209 | + $this->parameters[$Parameter->getName()] = $Parameter; |
|
210 | + |
|
211 | + return $Parameter; |
|
212 | + |
|
213 | + case 'body': |
|
214 | + case 'body?': |
|
215 | + $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
|
216 | + $this->parameters[$Parameter->getName()] = $Parameter; |
|
217 | + |
|
218 | + return $Parameter; |
|
219 | + |
|
220 | + case 'response': |
|
221 | + $name = self::wordShift($data); |
|
222 | + $definition = self::wordShift($data); |
|
223 | + $description = $data; |
|
224 | + if (empty($description)) { |
|
225 | + throw new Exception('Response definition missing description'); |
|
226 | + } |
|
227 | + $Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description); |
|
228 | + $this->responses[$name] = $Response; |
|
229 | + |
|
230 | + return $Response; |
|
231 | + |
|
232 | + case 'api': // alias |
|
233 | + case 'tag': |
|
234 | + $tagname = self::wordShift($data); |
|
235 | + if (empty($tagname)) { |
|
236 | + throw new Exception('Missing tag name'); |
|
237 | + } |
|
238 | + |
|
239 | + $Tag = null; |
|
240 | + foreach ($this->tags as $T) { |
|
241 | + if ($T->getName() === $tagname) { |
|
242 | + $Tag = $T; |
|
243 | + break; |
|
244 | + } |
|
245 | + } |
|
246 | + if (!$Tag) { |
|
247 | + $Tag = new Tag($this, $tagname, $data); |
|
248 | + $this->tags[] = $Tag; |
|
249 | + } |
|
250 | + |
|
251 | + // backwards compatibility |
|
252 | + if ($command === 'api') { |
|
253 | + $this->defaultTag = $Tag; |
|
254 | + } |
|
255 | + |
|
256 | + return $Tag; |
|
257 | + |
|
258 | + case 'endpoint': |
|
259 | + $path = self::wordShift($data); |
|
260 | + if (false === $path) { |
|
261 | + $path = '/'; |
|
262 | + } else if ($path[0] !== '/') { |
|
263 | + $path = '/' . $path; |
|
264 | + } |
|
265 | + |
|
266 | + $Tag = null; |
|
267 | + if (($tagname = self::wordShift($data)) !== false) { |
|
268 | + foreach ($this->tags as $T) { |
|
269 | + if (strtolower($T->getName()) === strtolower($tagname)) { |
|
270 | + $Tag = $T; |
|
271 | + break; |
|
272 | + } |
|
273 | + } |
|
274 | + if (!$Tag) { |
|
275 | + $Tag = new Tag($this, $tagname, $data); |
|
276 | + $this->tags[] = $Tag; |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + if (!isset($this->paths[$path])) { |
|
281 | + $this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag); |
|
282 | + } |
|
283 | + |
|
284 | + return $this->paths[$path]; |
|
285 | + |
|
286 | + case 'security': |
|
287 | + $name = self::wordShift($data); |
|
288 | + if (empty($name)) { |
|
289 | + throw new Exception('Missing security name'); |
|
290 | + } |
|
291 | + $type = self::wordShift($data); |
|
292 | + if (empty($type)) { |
|
293 | + throw new Exception('Missing security type'); |
|
294 | + } |
|
295 | + $SecurityScheme = new SecurityScheme($this, $type, $data); |
|
296 | + $this->securityDefinitions[$name] = $SecurityScheme; |
|
297 | + |
|
298 | + return $SecurityScheme; |
|
299 | + |
|
300 | + case 'require': |
|
301 | + $name = self::wordShift($data); |
|
302 | + if (empty($name)) { |
|
303 | + throw new Exception('Missing require name'); |
|
304 | + } |
|
305 | + $scopes = self::wordSplit($data); |
|
306 | + sort($scopes); |
|
307 | + $this->security[] = [ |
|
308 | + $name => empty($scopes) ? [] : $scopes, |
|
309 | + ]; |
|
310 | + |
|
311 | + return $this; |
|
312 | + } |
|
313 | + |
|
314 | + return parent::handleCommand($command, $data); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @inheritDoc |
|
319 | + * @throws Exception |
|
320 | + * @throws Exception |
|
321 | + */ |
|
322 | + public function toArray() |
|
323 | + { |
|
324 | + if (empty($this->paths)) { |
|
325 | + throw new Exception('No path defined'); |
|
326 | + } |
|
327 | + |
|
328 | + $schemes = array_unique($this->schemes); |
|
329 | + sort($schemes); |
|
330 | + |
|
331 | + $consumes = array_unique($this->consumes); |
|
332 | + sort($consumes); |
|
333 | + |
|
334 | + $produces = array_unique($this->produces); |
|
335 | + sort($produces); |
|
336 | + |
|
337 | + foreach ($this->security as $security) { |
|
338 | + foreach ($security as $name => $scopes) { |
|
339 | + if (!isset($this->securityDefinitions[$name])) { |
|
340 | + throw new Exception('Required security scheme not defined: \'' . $name . '\''); |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + return self::arrayFilterNull(array_merge([ |
|
346 | + 'swagger' => $this->swagger, |
|
347 | + 'info' => $this->info->toArray(), |
|
348 | + 'host' => empty($this->host) ? null : $this->host, |
|
349 | + 'basePath' => empty($this->basePath) ? null : $this->basePath, |
|
350 | + 'consumes' => $consumes, |
|
351 | + 'produces' => $produces, |
|
352 | + 'schemes' => $schemes, |
|
353 | + 'paths' => self::objectsToArray($this->paths), |
|
354 | + 'definitions' => self::objectsToArray($this->definitions), |
|
355 | + 'parameters' => self::objectsToArray($this->parameters), |
|
356 | + 'responses' => self::objectsToArray($this->responses), |
|
357 | + 'securityDefinitions' => self::objectsToArray($this->securityDefinitions), |
|
358 | + 'security' => $this->security, |
|
359 | + 'tags' => self::objectsToArray($this->tags), |
|
360 | + ], parent::toArray())); |
|
361 | + } |
|
362 | + |
|
363 | + public function __toString() |
|
364 | + { |
|
365 | + return __CLASS__; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Check if an operation with the given id exists. |
|
370 | + * |
|
371 | + * @param string $operationId |
|
372 | + * |
|
373 | + * @return boolean |
|
374 | + */ |
|
375 | + public function hasOperationId($operationId) |
|
376 | + { |
|
377 | + foreach ($this->paths as $path) { |
|
378 | + if ($path->hasOperationId($operationId)) { |
|
379 | + return true; |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + return false; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Check if a definition with the given name exists |
|
388 | + * |
|
389 | + * @param string $name |
|
390 | + * |
|
391 | + * @return boolean |
|
392 | + */ |
|
393 | + public function hasDefinition($name) |
|
394 | + { |
|
395 | + return isset($this->definitions[$name]); |
|
396 | + } |
|
397 | 397 | |
398 | 398 | } |
@@ -14,44 +14,44 @@ |
||
14 | 14 | class ExternalDocumentation extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - private $url; |
|
18 | - private $description; |
|
19 | - |
|
20 | - public function __construct(AbstractObject $parent, $url, $description = null) |
|
21 | - { |
|
22 | - parent::__construct($parent); |
|
23 | - $this->url = $url; |
|
24 | - $this->description = $description; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * @param string $command |
|
29 | - * @param string $data |
|
30 | - * @return AbstractObject|boolean |
|
31 | - */ |
|
32 | - public function handleCommand($command, $data = null) |
|
33 | - { |
|
34 | - switch (strtolower($command)) { |
|
35 | - case 'url': |
|
36 | - case 'description': |
|
37 | - $this->$command = $data; |
|
38 | - return $this; |
|
39 | - } |
|
40 | - |
|
41 | - return parent::handleCommand($command, $data); |
|
42 | - } |
|
43 | - |
|
44 | - public function toArray() |
|
45 | - { |
|
46 | - return self::arrayFilterNull(array_merge(array( |
|
47 | - 'url' => $this->url, |
|
48 | - 'description' => empty($this->description) ? null : $this->description, |
|
49 | - ), parent::toArray())); |
|
50 | - } |
|
51 | - |
|
52 | - public function __toString() |
|
53 | - { |
|
54 | - return __CLASS__ . ' ' . $this->url; |
|
55 | - } |
|
17 | + private $url; |
|
18 | + private $description; |
|
19 | + |
|
20 | + public function __construct(AbstractObject $parent, $url, $description = null) |
|
21 | + { |
|
22 | + parent::__construct($parent); |
|
23 | + $this->url = $url; |
|
24 | + $this->description = $description; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * @param string $command |
|
29 | + * @param string $data |
|
30 | + * @return AbstractObject|boolean |
|
31 | + */ |
|
32 | + public function handleCommand($command, $data = null) |
|
33 | + { |
|
34 | + switch (strtolower($command)) { |
|
35 | + case 'url': |
|
36 | + case 'description': |
|
37 | + $this->$command = $data; |
|
38 | + return $this; |
|
39 | + } |
|
40 | + |
|
41 | + return parent::handleCommand($command, $data); |
|
42 | + } |
|
43 | + |
|
44 | + public function toArray() |
|
45 | + { |
|
46 | + return self::arrayFilterNull(array_merge(array( |
|
47 | + 'url' => $this->url, |
|
48 | + 'description' => empty($this->description) ? null : $this->description, |
|
49 | + ), parent::toArray())); |
|
50 | + } |
|
51 | + |
|
52 | + public function __toString() |
|
53 | + { |
|
54 | + return __CLASS__ . ' ' . $this->url; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -14,38 +14,38 @@ |
||
14 | 14 | abstract class AbstractDocumentableObject extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * External documentation |
|
19 | - * @var ExternalDocumentation |
|
20 | - */ |
|
21 | - private $externalDocs = null; |
|
17 | + /** |
|
18 | + * External documentation |
|
19 | + * @var ExternalDocumentation |
|
20 | + */ |
|
21 | + private $externalDocs = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $command |
|
25 | - * @param string $data |
|
26 | - * @return AbstractObject|boolean |
|
27 | - */ |
|
28 | - public function handleCommand($command, $data = null) |
|
29 | - { |
|
30 | - switch (strtolower($command)) { |
|
31 | - case 'doc': |
|
32 | - case 'docs': |
|
33 | - $url = self::wordShift($data); |
|
34 | - $this->externalDocs = new ExternalDocumentation($this, $url, $data); |
|
35 | - return $this->externalDocs; |
|
36 | - } |
|
23 | + /** |
|
24 | + * @param string $command |
|
25 | + * @param string $data |
|
26 | + * @return AbstractObject|boolean |
|
27 | + */ |
|
28 | + public function handleCommand($command, $data = null) |
|
29 | + { |
|
30 | + switch (strtolower($command)) { |
|
31 | + case 'doc': |
|
32 | + case 'docs': |
|
33 | + $url = self::wordShift($data); |
|
34 | + $this->externalDocs = new ExternalDocumentation($this, $url, $data); |
|
35 | + return $this->externalDocs; |
|
36 | + } |
|
37 | 37 | |
38 | - return parent::handleCommand($command, $data); |
|
39 | - } |
|
38 | + return parent::handleCommand($command, $data); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function toArray() |
|
45 | - { |
|
46 | - return self::arrayFilterNull(array_merge(array( |
|
47 | - 'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null, |
|
48 | - ), parent::toArray())); |
|
49 | - } |
|
41 | + /** |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function toArray() |
|
45 | + { |
|
46 | + return self::arrayFilterNull(array_merge(array( |
|
47 | + 'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null, |
|
48 | + ), parent::toArray())); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -15,50 +15,50 @@ |
||
15 | 15 | class Header extends AbstractObject |
16 | 16 | { |
17 | 17 | |
18 | - private $type; |
|
19 | - private $description; |
|
18 | + private $type; |
|
19 | + private $description; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @throws Exception |
|
23 | - */ |
|
24 | - public function __construct(AbstractObject $parent, $type, $description = null) |
|
25 | - { |
|
26 | - parent::__construct($parent); |
|
21 | + /** |
|
22 | + * @throws Exception |
|
23 | + */ |
|
24 | + public function __construct(AbstractObject $parent, $type, $description = null) |
|
25 | + { |
|
26 | + parent::__construct($parent); |
|
27 | 27 | |
28 | - $this->type = strtolower($type); |
|
29 | - if (!in_array($this->type, array('string', 'number', 'integer', 'boolean', 'array'))) { |
|
30 | - throw new Exception('Header type not valid: \'' . $type . '\''); |
|
31 | - } |
|
28 | + $this->type = strtolower($type); |
|
29 | + if (!in_array($this->type, array('string', 'number', 'integer', 'boolean', 'array'))) { |
|
30 | + throw new Exception('Header type not valid: \'' . $type . '\''); |
|
31 | + } |
|
32 | 32 | |
33 | - $this->description = $description; |
|
34 | - } |
|
33 | + $this->description = $description; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $command |
|
38 | - * @param string $data |
|
39 | - * @return AbstractObject|boolean |
|
40 | - */ |
|
41 | - public function handleCommand($command, $data = null) |
|
42 | - { |
|
43 | - if (strtolower($command) === 'description') { |
|
44 | - $this->description = $data; |
|
45 | - return $this; |
|
46 | - } |
|
36 | + /** |
|
37 | + * @param string $command |
|
38 | + * @param string $data |
|
39 | + * @return AbstractObject|boolean |
|
40 | + */ |
|
41 | + public function handleCommand($command, $data = null) |
|
42 | + { |
|
43 | + if (strtolower($command) === 'description') { |
|
44 | + $this->description = $data; |
|
45 | + return $this; |
|
46 | + } |
|
47 | 47 | |
48 | - return parent::handleCommand($command, $data); |
|
49 | - } |
|
48 | + return parent::handleCommand($command, $data); |
|
49 | + } |
|
50 | 50 | |
51 | - public function toArray() |
|
52 | - { |
|
53 | - return self::arrayFilterNull(array_merge(array( |
|
54 | - 'type' => $this->type, |
|
55 | - 'description' => empty($this->description) ? null : $this->description, |
|
56 | - ), parent::toArray())); |
|
57 | - } |
|
51 | + public function toArray() |
|
52 | + { |
|
53 | + return self::arrayFilterNull(array_merge(array( |
|
54 | + 'type' => $this->type, |
|
55 | + 'description' => empty($this->description) ? null : $this->description, |
|
56 | + ), parent::toArray())); |
|
57 | + } |
|
58 | 58 | |
59 | - public function __toString() |
|
60 | - { |
|
61 | - return __CLASS__ . ' ' . $this->type; |
|
62 | - } |
|
59 | + public function __toString() |
|
60 | + { |
|
61 | + return __CLASS__ . ' ' . $this->type; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -13,25 +13,25 @@ |
||
13 | 13 | class ResponseReference extends AbstractObject |
14 | 14 | { |
15 | 15 | |
16 | - private $reference; |
|
17 | - |
|
18 | - public function __construct(AbstractObject $parent, $reference) |
|
19 | - { |
|
20 | - parent::__construct($parent); |
|
21 | - |
|
22 | - $this->reference = $reference; |
|
23 | - } |
|
24 | - |
|
25 | - public function toArray() |
|
26 | - { |
|
27 | - return self::arrayFilterNull(array( |
|
28 | - '$ref' => '#/responses/' . $this->reference, |
|
29 | - )); |
|
30 | - } |
|
31 | - |
|
32 | - public function __toString() |
|
33 | - { |
|
34 | - return __CLASS__ . ' `' . $this->reference . '`'; |
|
35 | - } |
|
16 | + private $reference; |
|
17 | + |
|
18 | + public function __construct(AbstractObject $parent, $reference) |
|
19 | + { |
|
20 | + parent::__construct($parent); |
|
21 | + |
|
22 | + $this->reference = $reference; |
|
23 | + } |
|
24 | + |
|
25 | + public function toArray() |
|
26 | + { |
|
27 | + return self::arrayFilterNull(array( |
|
28 | + '$ref' => '#/responses/' . $this->reference, |
|
29 | + )); |
|
30 | + } |
|
31 | + |
|
32 | + public function __toString() |
|
33 | + { |
|
34 | + return __CLASS__ . ' `' . $this->reference . '`'; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | } |
@@ -14,49 +14,49 @@ |
||
14 | 14 | class Contact extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - private $name; |
|
18 | - private $url; |
|
19 | - private $email; |
|
20 | - |
|
21 | - public function __construct(AbstractObject $parent, $name = null, $url = null, $email = null) |
|
22 | - { |
|
23 | - parent::__construct($parent); |
|
24 | - |
|
25 | - $this->name = empty($name) ? null : $name; |
|
26 | - $this->url = empty($url) ? null : $url; |
|
27 | - $this->email = empty($email) ? null : $email; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @param string $command |
|
32 | - * @param string $data |
|
33 | - * @return AbstractObject|boolean |
|
34 | - */ |
|
35 | - public function handleCommand($command, $data = null) |
|
36 | - { |
|
37 | - switch (strtolower($command)) { |
|
38 | - case 'name': |
|
39 | - case 'url': |
|
40 | - case 'email': |
|
41 | - $this->$command = $data; |
|
42 | - return $this; |
|
43 | - } |
|
44 | - |
|
45 | - return parent::handleCommand($command, $data); |
|
46 | - } |
|
47 | - |
|
48 | - public function toArray() |
|
49 | - { |
|
50 | - return self::arrayFilterNull(array_merge(array( |
|
51 | - 'name' => $this->name, |
|
52 | - 'url' => $this->url, |
|
53 | - 'email' => $this->email, |
|
54 | - ), parent::toArray())); |
|
55 | - } |
|
56 | - |
|
57 | - public function __toString() |
|
58 | - { |
|
59 | - return __CLASS__ . " {$this->name} <{$this->email}>, {$this->url}"; |
|
60 | - } |
|
17 | + private $name; |
|
18 | + private $url; |
|
19 | + private $email; |
|
20 | + |
|
21 | + public function __construct(AbstractObject $parent, $name = null, $url = null, $email = null) |
|
22 | + { |
|
23 | + parent::__construct($parent); |
|
24 | + |
|
25 | + $this->name = empty($name) ? null : $name; |
|
26 | + $this->url = empty($url) ? null : $url; |
|
27 | + $this->email = empty($email) ? null : $email; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @param string $command |
|
32 | + * @param string $data |
|
33 | + * @return AbstractObject|boolean |
|
34 | + */ |
|
35 | + public function handleCommand($command, $data = null) |
|
36 | + { |
|
37 | + switch (strtolower($command)) { |
|
38 | + case 'name': |
|
39 | + case 'url': |
|
40 | + case 'email': |
|
41 | + $this->$command = $data; |
|
42 | + return $this; |
|
43 | + } |
|
44 | + |
|
45 | + return parent::handleCommand($command, $data); |
|
46 | + } |
|
47 | + |
|
48 | + public function toArray() |
|
49 | + { |
|
50 | + return self::arrayFilterNull(array_merge(array( |
|
51 | + 'name' => $this->name, |
|
52 | + 'url' => $this->url, |
|
53 | + 'email' => $this->email, |
|
54 | + ), parent::toArray())); |
|
55 | + } |
|
56 | + |
|
57 | + public function __toString() |
|
58 | + { |
|
59 | + return __CLASS__ . " {$this->name} <{$this->email}>, {$this->url}"; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -14,9 +14,9 @@ |
||
14 | 14 | class Error extends Response |
15 | 15 | { |
16 | 16 | |
17 | - public function __construct(AbstractObject $parent, $code, $description = null) |
|
18 | - { |
|
19 | - parent::__construct($parent, $code, null, $description); |
|
20 | - } |
|
17 | + public function __construct(AbstractObject $parent, $code, $description = null) |
|
18 | + { |
|
19 | + parent::__construct($parent, $code, null, $description); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | } |
@@ -15,77 +15,77 @@ |
||
15 | 15 | class BodyParameter extends AbstractObject implements IParameter |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string|boolean |
|
20 | - */ |
|
21 | - private $name = ''; |
|
22 | - private $description; |
|
23 | - private $required = false; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var Schema |
|
27 | - */ |
|
28 | - private $schema; |
|
29 | - |
|
30 | - /** |
|
31 | - * @throws Exception |
|
32 | - */ |
|
33 | - public function __construct(AbstractObject $parent, $data, $required = false) |
|
34 | - { |
|
35 | - parent::__construct($parent); |
|
36 | - |
|
37 | - $type = self::wordShift($data); |
|
38 | - if (empty($type)) { |
|
39 | - throw new Exception('No type definition for body parameter'); |
|
40 | - } |
|
41 | - |
|
42 | - $this->name = self::wordShift($data); |
|
43 | - if (empty($this->name)) { |
|
44 | - throw new Exception('No name for body parameter'); |
|
45 | - } |
|
46 | - |
|
47 | - $this->description = $data; |
|
48 | - $this->required = (bool)$required; |
|
49 | - |
|
50 | - $this->schema = new Schema($this, $type); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $command |
|
55 | - * @param string $data |
|
56 | - * @return AbstractObject|boolean |
|
57 | - * @throws Exception |
|
58 | - */ |
|
59 | - public function handleCommand($command, $data = null) |
|
60 | - { |
|
61 | - // Pass through to Type |
|
62 | - $return = $this->schema->handleCommand($command, $data); |
|
63 | - if ($return) { |
|
64 | - return $return; |
|
65 | - } |
|
66 | - |
|
67 | - return parent::handleCommand($command, $data); |
|
68 | - } |
|
69 | - |
|
70 | - public function toArray() |
|
71 | - { |
|
72 | - return self::arrayFilterNull(array_merge(array( |
|
73 | - 'name' => $this->name, |
|
74 | - 'in' => 'body', |
|
75 | - 'description' => empty($this->description) ? null : $this->description, |
|
76 | - 'required' => $this->required ? true : null, |
|
77 | - 'schema' => $this->schema->toArray(), |
|
78 | - ), parent::toArray())); |
|
79 | - } |
|
80 | - |
|
81 | - public function __toString() |
|
82 | - { |
|
83 | - return __CLASS__ . ' ' . $this->name; |
|
84 | - } |
|
85 | - |
|
86 | - public function getName() |
|
87 | - { |
|
88 | - return $this->name; |
|
89 | - } |
|
18 | + /** |
|
19 | + * @var string|boolean |
|
20 | + */ |
|
21 | + private $name = ''; |
|
22 | + private $description; |
|
23 | + private $required = false; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var Schema |
|
27 | + */ |
|
28 | + private $schema; |
|
29 | + |
|
30 | + /** |
|
31 | + * @throws Exception |
|
32 | + */ |
|
33 | + public function __construct(AbstractObject $parent, $data, $required = false) |
|
34 | + { |
|
35 | + parent::__construct($parent); |
|
36 | + |
|
37 | + $type = self::wordShift($data); |
|
38 | + if (empty($type)) { |
|
39 | + throw new Exception('No type definition for body parameter'); |
|
40 | + } |
|
41 | + |
|
42 | + $this->name = self::wordShift($data); |
|
43 | + if (empty($this->name)) { |
|
44 | + throw new Exception('No name for body parameter'); |
|
45 | + } |
|
46 | + |
|
47 | + $this->description = $data; |
|
48 | + $this->required = (bool)$required; |
|
49 | + |
|
50 | + $this->schema = new Schema($this, $type); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $command |
|
55 | + * @param string $data |
|
56 | + * @return AbstractObject|boolean |
|
57 | + * @throws Exception |
|
58 | + */ |
|
59 | + public function handleCommand($command, $data = null) |
|
60 | + { |
|
61 | + // Pass through to Type |
|
62 | + $return = $this->schema->handleCommand($command, $data); |
|
63 | + if ($return) { |
|
64 | + return $return; |
|
65 | + } |
|
66 | + |
|
67 | + return parent::handleCommand($command, $data); |
|
68 | + } |
|
69 | + |
|
70 | + public function toArray() |
|
71 | + { |
|
72 | + return self::arrayFilterNull(array_merge(array( |
|
73 | + 'name' => $this->name, |
|
74 | + 'in' => 'body', |
|
75 | + 'description' => empty($this->description) ? null : $this->description, |
|
76 | + 'required' => $this->required ? true : null, |
|
77 | + 'schema' => $this->schema->toArray(), |
|
78 | + ), parent::toArray())); |
|
79 | + } |
|
80 | + |
|
81 | + public function __toString() |
|
82 | + { |
|
83 | + return __CLASS__ . ' ' . $this->name; |
|
84 | + } |
|
85 | + |
|
86 | + public function getName() |
|
87 | + { |
|
88 | + return $this->name; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
@@ -14,94 +14,94 @@ |
||
14 | 14 | class License extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - // @todo make this a separate resource file? (licenseUrls.json) |
|
18 | - private static $licenses = array( |
|
19 | - 'artistic-1.0' => 'http://opensource.org/licenses/artistic-license-1.0', |
|
20 | - 'artistic-1' => 'http://opensource.org/licenses/artistic-license-1.0', |
|
21 | - 'artistic-2.0' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
22 | - 'artistic-2' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
23 | - 'artistic' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
24 | - 'bsd-new' => 'https://opensource.org/licenses/BSD-3-Clause', |
|
25 | - 'bsd-3' => 'https://opensource.org/licenses/BSD-3-Clause', |
|
26 | - 'bsd-2' => 'https://opensource.org/licenses/BSD-2-Clause', |
|
27 | - 'bsd' => 'https://opensource.org/licenses/BSD-2-Clause', |
|
28 | - 'epl-1.0' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
29 | - 'epl-1' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
30 | - 'epl' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
31 | - 'apache-2.0' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
32 | - 'apache-2' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
33 | - 'apache' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
34 | - 'gpl-1.0' => 'https://www.gnu.org/licenses/gpl-1.0.html', |
|
35 | - 'gpl-1' => 'https://www.gnu.org/licenses/gpl-1.0.html', |
|
36 | - 'gpl-2.0' => 'https://www.gnu.org/licenses/gpl-2.0.html', |
|
37 | - 'gpl-2' => 'https://www.gnu.org/licenses/gpl-2.0.html', |
|
38 | - 'gpl-3.0' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
39 | - 'gpl-3' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
40 | - 'gpl' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
41 | - 'lgpl-2.0' => 'http://www.gnu.org/licenses/lgpl-2.0.html', |
|
42 | - 'lgpl-2.1' => 'http://www.gnu.org/licenses/lgpl-2.1.html', |
|
43 | - 'lgpl-2' => 'http://www.gnu.org/licenses/lgpl-2.1.html', |
|
44 | - 'lgpl-3.0' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
45 | - 'lgpl-3' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
46 | - 'lgpl' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
47 | - 'mit' => 'http://opensource.org/licenses/MIT', |
|
48 | - 'mpl-1.1' => 'https://www.mozilla.org/en-US/MPL/1.1/', |
|
49 | - 'mpl-1' => 'https://www.mozilla.org/en-US/MPL/1.1/', |
|
50 | - 'mpl-2.0' => 'https://www.mozilla.org/en-US/MPL/', |
|
51 | - 'mpl-2' => 'https://www.mozilla.org/en-US/MPL/', |
|
52 | - 'mpl' => 'https://www.mozilla.org/en-US/MPL/', |
|
53 | - 'mspl' => 'https://msdn.microsoft.com/en-us/library/ff648068.aspx', |
|
54 | - ); |
|
55 | - private $name; |
|
56 | - private $url; |
|
17 | + // @todo make this a separate resource file? (licenseUrls.json) |
|
18 | + private static $licenses = array( |
|
19 | + 'artistic-1.0' => 'http://opensource.org/licenses/artistic-license-1.0', |
|
20 | + 'artistic-1' => 'http://opensource.org/licenses/artistic-license-1.0', |
|
21 | + 'artistic-2.0' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
22 | + 'artistic-2' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
23 | + 'artistic' => 'http://opensource.org/licenses/artistic-license-2.0', |
|
24 | + 'bsd-new' => 'https://opensource.org/licenses/BSD-3-Clause', |
|
25 | + 'bsd-3' => 'https://opensource.org/licenses/BSD-3-Clause', |
|
26 | + 'bsd-2' => 'https://opensource.org/licenses/BSD-2-Clause', |
|
27 | + 'bsd' => 'https://opensource.org/licenses/BSD-2-Clause', |
|
28 | + 'epl-1.0' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
29 | + 'epl-1' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
30 | + 'epl' => 'http://www.eclipse.org/legal/epl-v10.html', |
|
31 | + 'apache-2.0' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
32 | + 'apache-2' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
33 | + 'apache' => 'http://www.apache.org/licenses/LICENSE-2.0.html', |
|
34 | + 'gpl-1.0' => 'https://www.gnu.org/licenses/gpl-1.0.html', |
|
35 | + 'gpl-1' => 'https://www.gnu.org/licenses/gpl-1.0.html', |
|
36 | + 'gpl-2.0' => 'https://www.gnu.org/licenses/gpl-2.0.html', |
|
37 | + 'gpl-2' => 'https://www.gnu.org/licenses/gpl-2.0.html', |
|
38 | + 'gpl-3.0' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
39 | + 'gpl-3' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
40 | + 'gpl' => 'http://www.gnu.org/licenses/gpl-3.0.html', |
|
41 | + 'lgpl-2.0' => 'http://www.gnu.org/licenses/lgpl-2.0.html', |
|
42 | + 'lgpl-2.1' => 'http://www.gnu.org/licenses/lgpl-2.1.html', |
|
43 | + 'lgpl-2' => 'http://www.gnu.org/licenses/lgpl-2.1.html', |
|
44 | + 'lgpl-3.0' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
45 | + 'lgpl-3' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
46 | + 'lgpl' => 'http://www.gnu.org/licenses/lgpl-3.0.html', |
|
47 | + 'mit' => 'http://opensource.org/licenses/MIT', |
|
48 | + 'mpl-1.1' => 'https://www.mozilla.org/en-US/MPL/1.1/', |
|
49 | + 'mpl-1' => 'https://www.mozilla.org/en-US/MPL/1.1/', |
|
50 | + 'mpl-2.0' => 'https://www.mozilla.org/en-US/MPL/', |
|
51 | + 'mpl-2' => 'https://www.mozilla.org/en-US/MPL/', |
|
52 | + 'mpl' => 'https://www.mozilla.org/en-US/MPL/', |
|
53 | + 'mspl' => 'https://msdn.microsoft.com/en-us/library/ff648068.aspx', |
|
54 | + ); |
|
55 | + private $name; |
|
56 | + private $url; |
|
57 | 57 | |
58 | - public function __construct(AbstractObject $parent, $name, $url = null) |
|
59 | - { |
|
60 | - parent::__construct($parent); |
|
58 | + public function __construct(AbstractObject $parent, $name, $url = null) |
|
59 | + { |
|
60 | + parent::__construct($parent); |
|
61 | 61 | |
62 | - $this->name = empty($name) ? null : $name; |
|
62 | + $this->name = empty($name) ? null : $name; |
|
63 | 63 | |
64 | - if (!empty($url)) { |
|
65 | - $this->url = $url; |
|
66 | - } elseif (!empty(self::$licenses[strtolower($name)])) { |
|
67 | - $this->url = self::$licenses[strtolower($name)]; |
|
68 | - } |
|
69 | - } |
|
64 | + if (!empty($url)) { |
|
65 | + $this->url = $url; |
|
66 | + } elseif (!empty(self::$licenses[strtolower($name)])) { |
|
67 | + $this->url = self::$licenses[strtolower($name)]; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param string $command |
|
73 | - * @param string $data |
|
74 | - * @return AbstractObject|boolean |
|
75 | - */ |
|
76 | - public function handleCommand($command, $data = null) |
|
77 | - { |
|
78 | - switch (strtolower($command)) { |
|
79 | - case 'name': |
|
80 | - $this->name = $data; |
|
81 | - if (empty($this->url) && !empty(self::$licenses[strtolower($data)])) { |
|
82 | - $this->url = self::$licenses[strtolower($data)]; |
|
83 | - } |
|
84 | - return $this; |
|
71 | + /** |
|
72 | + * @param string $command |
|
73 | + * @param string $data |
|
74 | + * @return AbstractObject|boolean |
|
75 | + */ |
|
76 | + public function handleCommand($command, $data = null) |
|
77 | + { |
|
78 | + switch (strtolower($command)) { |
|
79 | + case 'name': |
|
80 | + $this->name = $data; |
|
81 | + if (empty($this->url) && !empty(self::$licenses[strtolower($data)])) { |
|
82 | + $this->url = self::$licenses[strtolower($data)]; |
|
83 | + } |
|
84 | + return $this; |
|
85 | 85 | |
86 | - case 'url': |
|
87 | - $this->url = $data; |
|
88 | - return $this; |
|
89 | - } |
|
86 | + case 'url': |
|
87 | + $this->url = $data; |
|
88 | + return $this; |
|
89 | + } |
|
90 | 90 | |
91 | - return parent::handleCommand($command, $data); |
|
92 | - } |
|
91 | + return parent::handleCommand($command, $data); |
|
92 | + } |
|
93 | 93 | |
94 | - public function toArray() |
|
95 | - { |
|
96 | - return self::arrayFilterNull(array_merge(array( |
|
97 | - 'name' => $this->name, |
|
98 | - 'url' => $this->url, |
|
99 | - ), parent::toArray())); |
|
100 | - } |
|
94 | + public function toArray() |
|
95 | + { |
|
96 | + return self::arrayFilterNull(array_merge(array( |
|
97 | + 'name' => $this->name, |
|
98 | + 'url' => $this->url, |
|
99 | + ), parent::toArray())); |
|
100 | + } |
|
101 | 101 | |
102 | - public function __toString() |
|
103 | - { |
|
104 | - return __CLASS__ . " {$this->name}, {$this->url}"; |
|
105 | - } |
|
102 | + public function __toString() |
|
103 | + { |
|
104 | + return __CLASS__ . " {$this->name}, {$this->url}"; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |