@@ -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(): array |
|
83 | - { |
|
84 | - $methods = self::$methods; |
|
85 | - uksort($this->operations, static 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(): array |
|
83 | + { |
|
84 | + $methods = self::$methods; |
|
85 | + uksort($this->operations, static 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 | } |
@@ -82,7 +82,7 @@ |
||
82 | 82 | public function toArray(): array |
83 | 83 | { |
84 | 84 | $methods = self::$methods; |
85 | - uksort($this->operations, static function ($a, $b) use ($methods) { |
|
85 | + uksort($this->operations, static function($a, $b) use ($methods) { |
|
86 | 86 | return array_search($a, $methods) - array_search($b, $methods); |
87 | 87 | }); |
88 | 88 |
@@ -14,106 +14,106 @@ |
||
14 | 14 | class Info extends AbstractObject |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - private $title = 'undefined'; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $description; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - private $termsofservice; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var Contact |
|
34 | - */ |
|
35 | - private $contact; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var License |
|
39 | - */ |
|
40 | - private $license; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string|integer|float |
|
44 | - */ |
|
45 | - private $version = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param string $command |
|
49 | - * @param string $data |
|
50 | - * @return AbstractObject|boolean |
|
51 | - */ |
|
52 | - public function handleCommand($command, $data = null) |
|
53 | - { |
|
54 | - switch (strtolower($command)) { |
|
55 | - case 'title': |
|
56 | - case 'description': |
|
57 | - case 'termsofservice': |
|
58 | - case 'version': |
|
59 | - $this->$command = $data; |
|
60 | - return $this; |
|
61 | - |
|
62 | - case 'terms': // alias |
|
63 | - case 'tos': // alias |
|
64 | - $this->termsofservice = $data; |
|
65 | - return $this; |
|
66 | - |
|
67 | - case 'contact': |
|
68 | - $name = array(); |
|
69 | - $url = null; |
|
70 | - $email = null; |
|
71 | - foreach (self::wordSplit($data) as $word) { |
|
72 | - if (filter_var($word, FILTER_VALIDATE_URL)) { |
|
73 | - $url = $word; |
|
74 | - } elseif (filter_var($word, FILTER_VALIDATE_EMAIL)) { |
|
75 | - $email = $word; |
|
76 | - } else { |
|
77 | - $name[] = $word; |
|
78 | - } |
|
79 | - } |
|
80 | - $name = implode(' ', array_filter($name)); |
|
81 | - $this->contact = new Contact($this, $name, $url, $email); |
|
82 | - return $this->contact; |
|
83 | - |
|
84 | - case 'license': |
|
85 | - $name = array(); |
|
86 | - $url = null; |
|
87 | - foreach (self::wordSplit($data) as $word) { |
|
88 | - if (filter_var($word, FILTER_VALIDATE_URL)) { |
|
89 | - $url = $word; |
|
90 | - } else { |
|
91 | - $name[] = $word; |
|
92 | - } |
|
93 | - } |
|
94 | - $name = implode(' ', array_filter($name)); |
|
95 | - $this->license = new License($this, $name, $url); |
|
96 | - return $this->license; |
|
97 | - } |
|
98 | - |
|
99 | - return parent::handleCommand($command, $data); |
|
100 | - } |
|
101 | - |
|
102 | - public function toArray(): array |
|
103 | - { |
|
104 | - return self::arrayFilterNull(array_merge(array( |
|
105 | - 'title' => $this->title, |
|
106 | - 'description' => $this->description, |
|
107 | - 'termsOfService' => $this->termsofservice, |
|
108 | - 'contact' => $this->contact ? $this->contact->toArray() : null, |
|
109 | - 'license' => $this->license ? $this->license->toArray() : null, |
|
110 | - 'version' => (string)$this->version, |
|
111 | - ), parent::toArray())); |
|
112 | - } |
|
113 | - |
|
114 | - public function __toString() |
|
115 | - { |
|
116 | - return __CLASS__ . ' \'' . $this->title . '\''; |
|
117 | - } |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + private $title = 'undefined'; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $description; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + private $termsofservice; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var Contact |
|
34 | + */ |
|
35 | + private $contact; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var License |
|
39 | + */ |
|
40 | + private $license; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string|integer|float |
|
44 | + */ |
|
45 | + private $version = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param string $command |
|
49 | + * @param string $data |
|
50 | + * @return AbstractObject|boolean |
|
51 | + */ |
|
52 | + public function handleCommand($command, $data = null) |
|
53 | + { |
|
54 | + switch (strtolower($command)) { |
|
55 | + case 'title': |
|
56 | + case 'description': |
|
57 | + case 'termsofservice': |
|
58 | + case 'version': |
|
59 | + $this->$command = $data; |
|
60 | + return $this; |
|
61 | + |
|
62 | + case 'terms': // alias |
|
63 | + case 'tos': // alias |
|
64 | + $this->termsofservice = $data; |
|
65 | + return $this; |
|
66 | + |
|
67 | + case 'contact': |
|
68 | + $name = array(); |
|
69 | + $url = null; |
|
70 | + $email = null; |
|
71 | + foreach (self::wordSplit($data) as $word) { |
|
72 | + if (filter_var($word, FILTER_VALIDATE_URL)) { |
|
73 | + $url = $word; |
|
74 | + } elseif (filter_var($word, FILTER_VALIDATE_EMAIL)) { |
|
75 | + $email = $word; |
|
76 | + } else { |
|
77 | + $name[] = $word; |
|
78 | + } |
|
79 | + } |
|
80 | + $name = implode(' ', array_filter($name)); |
|
81 | + $this->contact = new Contact($this, $name, $url, $email); |
|
82 | + return $this->contact; |
|
83 | + |
|
84 | + case 'license': |
|
85 | + $name = array(); |
|
86 | + $url = null; |
|
87 | + foreach (self::wordSplit($data) as $word) { |
|
88 | + if (filter_var($word, FILTER_VALIDATE_URL)) { |
|
89 | + $url = $word; |
|
90 | + } else { |
|
91 | + $name[] = $word; |
|
92 | + } |
|
93 | + } |
|
94 | + $name = implode(' ', array_filter($name)); |
|
95 | + $this->license = new License($this, $name, $url); |
|
96 | + return $this->license; |
|
97 | + } |
|
98 | + |
|
99 | + return parent::handleCommand($command, $data); |
|
100 | + } |
|
101 | + |
|
102 | + public function toArray(): array |
|
103 | + { |
|
104 | + return self::arrayFilterNull(array_merge(array( |
|
105 | + 'title' => $this->title, |
|
106 | + 'description' => $this->description, |
|
107 | + 'termsOfService' => $this->termsofservice, |
|
108 | + 'contact' => $this->contact ? $this->contact->toArray() : null, |
|
109 | + 'license' => $this->license ? $this->license->toArray() : null, |
|
110 | + 'version' => (string)$this->version, |
|
111 | + ), parent::toArray())); |
|
112 | + } |
|
113 | + |
|
114 | + public function __toString() |
|
115 | + { |
|
116 | + return __CLASS__ . ' \'' . $this->title . '\''; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -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(): array |
|
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(): array |
|
45 | + { |
|
46 | + return self::arrayFilterNull(array_merge(array( |
|
47 | + 'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null, |
|
48 | + ), parent::toArray())); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -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(): array |
|
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(): array |
|
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,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(): array |
|
95 | - { |
|
96 | - return self::arrayFilterNull(array_merge(array( |
|
97 | - 'name' => $this->name, |
|
98 | - 'url' => $this->url, |
|
99 | - ), parent::toArray())); |
|
100 | - } |
|
94 | + public function toArray(): array |
|
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 | } |
@@ -13,30 +13,30 @@ |
||
13 | 13 | class ParameterReference extends AbstractObject implements IParameter |
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(): array |
|
26 | - { |
|
27 | - return self::arrayFilterNull(array( |
|
28 | - '$ref' => '#/parameters/' . $this->reference, |
|
29 | - )); |
|
30 | - } |
|
31 | - |
|
32 | - public function __toString() |
|
33 | - { |
|
34 | - return __CLASS__ . ' `' . $this->reference . '`'; |
|
35 | - } |
|
36 | - |
|
37 | - public function getName() |
|
38 | - { |
|
39 | - return $this->reference; |
|
40 | - } |
|
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(): array |
|
26 | + { |
|
27 | + return self::arrayFilterNull(array( |
|
28 | + '$ref' => '#/parameters/' . $this->reference, |
|
29 | + )); |
|
30 | + } |
|
31 | + |
|
32 | + public function __toString() |
|
33 | + { |
|
34 | + return __CLASS__ . ' `' . $this->reference . '`'; |
|
35 | + } |
|
36 | + |
|
37 | + public function getName() |
|
38 | + { |
|
39 | + return $this->reference; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -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(): array |
|
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(): array |
|
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 | } |
@@ -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 | - } |
|
95 | - |
|
96 | - $this->name = $name; |
|
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('/^(\[)(?:.*?)\]$/', $definition, $match) === 1) { |
|
106 | - $format = 'array'; |
|
107 | - } elseif (preg_match('/^(\{)(?:.*?)\}$/', $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(): array |
|
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 | + } |
|
95 | + |
|
96 | + $this->name = $name; |
|
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('/^(\[)(?:.*?)\]$/', $definition, $match) === 1) { |
|
106 | + $format = 'array'; |
|
107 | + } elseif (preg_match('/^(\{)(?:.*?)\}$/', $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(): array |
|
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 | $this->name = $name; |
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(); |
@@ -16,230 +16,230 @@ |
||
16 | 16 | class Operation extends AbstractDocumentableObject |
17 | 17 | { |
18 | 18 | |
19 | - private $tags = array(); |
|
20 | - private $summary; |
|
21 | - private $description; |
|
22 | - private $consumes = array(); |
|
23 | - private $produces = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * @var IParameter[] |
|
27 | - */ |
|
28 | - private $parameters = array(); |
|
29 | - private $responses = array(); |
|
30 | - private $schemes = array(); |
|
31 | - private $deprecated = false; |
|
32 | - private $security = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $operationId = null; |
|
38 | - |
|
39 | - public function getConsumes(): array |
|
40 | - { |
|
41 | - return $this->consumes; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param string $summary |
|
46 | - */ |
|
47 | - public function __construct(AbstractObject $parent, $summary = null, Tag $tag = null) |
|
48 | - { |
|
49 | - parent::__construct($parent); |
|
50 | - $this->summary = $summary; |
|
51 | - if ($tag) { |
|
52 | - $this->tags[] = $tag->getName(); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $command |
|
58 | - * @param string $data |
|
59 | - * @return AbstractObject|boolean |
|
60 | - * @throws Exception |
|
61 | - * @throws Exception |
|
62 | - * @throws Exception |
|
63 | - * @throws Exception |
|
64 | - * @throws Exception |
|
65 | - * @throws Exception |
|
66 | - * @throws Exception |
|
67 | - */ |
|
68 | - public function handleCommand($command, $data = null) |
|
69 | - { |
|
70 | - switch (strtolower($command)) { |
|
71 | - // string |
|
72 | - case 'summary': |
|
73 | - case 'description': |
|
74 | - $this->$command = $data; |
|
75 | - return $this; |
|
76 | - |
|
77 | - // string[] |
|
78 | - case 'tags': |
|
79 | - case 'schemes': |
|
80 | - $this->$command = array_merge($this->$command, self::wordSplit($data)); |
|
81 | - return $this; |
|
82 | - |
|
83 | - // MIME[] |
|
84 | - case 'consumes': |
|
85 | - case 'produces': |
|
86 | - $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data))); |
|
87 | - return $this; |
|
88 | - |
|
89 | - // boolean |
|
90 | - case 'deprecated': |
|
91 | - $this->deprecated = true; |
|
92 | - return $this; |
|
93 | - |
|
94 | - case 'error': |
|
95 | - $code = self::wordShift($data); |
|
96 | - $reasoncode = Response::getCode($code); |
|
97 | - if ($reasoncode === null) { |
|
98 | - throw new Exception("Invalid error code: '$code'"); |
|
99 | - } |
|
100 | - $description = $data; |
|
101 | - $Error = new Error($this, $reasoncode, $description); |
|
102 | - $this->responses[$reasoncode] = $Error; |
|
103 | - return $Error; |
|
104 | - |
|
105 | - case 'errors': |
|
106 | - foreach (self::wordSplit($data) as $code) { |
|
107 | - $reasoncode = Response::getCode($code); |
|
108 | - if ($reasoncode === null) { |
|
109 | - throw new Exception("Invalid error code: '$code'"); |
|
110 | - } |
|
111 | - $this->responses[$reasoncode] = new Error($this, $reasoncode); |
|
112 | - } |
|
113 | - return $this; |
|
114 | - |
|
115 | - case 'path': |
|
116 | - case 'query': |
|
117 | - case 'query?': |
|
118 | - case 'header': |
|
119 | - case 'header?': |
|
120 | - case 'form': |
|
121 | - case 'form?': |
|
122 | - $in = rtrim($command, '?'); |
|
123 | - $parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
|
124 | - $this->parameters[$parameter->getName()] = $parameter; |
|
125 | - return $parameter; |
|
126 | - |
|
127 | - case 'body': |
|
128 | - case 'body?': |
|
129 | - $parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
|
130 | - $this->parameters[$parameter->getName()] = $parameter; |
|
131 | - return $parameter; |
|
132 | - |
|
133 | - case 'param': |
|
134 | - case 'parameter': |
|
135 | - $parameter = new ParameterReference($this, $data); |
|
136 | - $this->parameters[$parameter->getName()] = $parameter; |
|
137 | - return $this; |
|
138 | - |
|
139 | - case 'response': |
|
140 | - $code = self::wordShift($data); |
|
141 | - $reasoncode = Response::getCode($code); |
|
142 | - if ($reasoncode === null) { |
|
143 | - $reference = $code; |
|
144 | - $code = self::wordShift($data); |
|
145 | - $reasoncode = Response::getCode($code); |
|
146 | - if ($reasoncode === null) { |
|
147 | - throw new Exception("Invalid response code: '$reference'"); |
|
148 | - } |
|
149 | - $this->responses[$reasoncode] = new ResponseReference($this, $reference); |
|
150 | - return $this; |
|
151 | - } |
|
152 | - |
|
153 | - $definition = self::wordShift($data); |
|
154 | - $description = $data; |
|
155 | - $Response = new Response($this, $reasoncode, $definition, $description); |
|
156 | - $this->responses[$reasoncode] = $Response; |
|
157 | - return $Response; |
|
158 | - |
|
159 | - case 'require': |
|
160 | - $name = self::wordShift($data); |
|
161 | - if (empty($name)) { |
|
162 | - throw new Exception('Empty security requirement name'); |
|
163 | - } |
|
164 | - $scopes = self::wordSplit($data); |
|
165 | - sort($scopes); |
|
166 | - $this->security[] = array( |
|
167 | - $name => empty($scopes) ? array() : $scopes, |
|
168 | - ); |
|
169 | - return $this; |
|
170 | - |
|
171 | - case 'id': |
|
172 | - $operationId = self::trim($data); |
|
173 | - if ($this->getSwagger()->hasOperationId($operationId)) { |
|
174 | - throw new Exception("Duplicate operation id '{$operationId}'"); |
|
175 | - } |
|
176 | - $this->operationId = $operationId; |
|
177 | - return $this; |
|
178 | - } |
|
179 | - |
|
180 | - return parent::handleCommand($command, $data); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @throws Exception |
|
185 | - */ |
|
186 | - public function toArray(): array |
|
187 | - { |
|
188 | - if (empty($this->responses)) { |
|
189 | - throw new Exception('No response defined for operation'); |
|
190 | - } |
|
191 | - ksort($this->responses); |
|
192 | - |
|
193 | - $tags = array_unique($this->tags); |
|
194 | - sort($tags); |
|
195 | - |
|
196 | - $schemes = array_unique($this->schemes); |
|
197 | - sort($schemes); |
|
198 | - |
|
199 | - $consumes = array_unique($this->consumes); |
|
200 | - sort($consumes); |
|
201 | - |
|
202 | - $produces = array_unique($this->produces); |
|
203 | - sort($produces); |
|
204 | - |
|
205 | - foreach ($this->security as $security) { |
|
206 | - foreach ($security as $name => $scope) { |
|
207 | - if ($this->getSwagger()->getSecurity($name) === false) { |
|
208 | - throw new Exception("Required security scheme not defined: '{$name}'"); |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - $parameters = $this->parameters ? array_values($this->parameters) : null; |
|
214 | - |
|
215 | - return self::arrayFilterNull(array_merge(array( |
|
216 | - 'deprecated' => $this->deprecated ? true : null, |
|
217 | - 'tags' => $tags, |
|
218 | - 'summary' => empty($this->summary) ? null : $this->summary, |
|
219 | - 'description' => empty($this->description) ? null : $this->description, |
|
220 | - 'operationId' => $this->operationId, |
|
221 | - 'consumes' => $consumes, |
|
222 | - 'produces' => $produces, |
|
223 | - 'parameters' => $parameters ? self::objectsToArray($parameters) : null, |
|
224 | - 'schemes' => $schemes, |
|
225 | - 'responses' => $this->responses ? self::objectsToArray($this->responses) : null, |
|
226 | - 'security' => $this->security, |
|
227 | - ), parent::toArray())); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Return the operation ID |
|
232 | - * |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function getId() |
|
236 | - { |
|
237 | - return $this->operationId; |
|
238 | - } |
|
239 | - |
|
240 | - public function __toString() |
|
241 | - { |
|
242 | - return __CLASS__ . ' ' . $this->summary; |
|
243 | - } |
|
19 | + private $tags = array(); |
|
20 | + private $summary; |
|
21 | + private $description; |
|
22 | + private $consumes = array(); |
|
23 | + private $produces = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * @var IParameter[] |
|
27 | + */ |
|
28 | + private $parameters = array(); |
|
29 | + private $responses = array(); |
|
30 | + private $schemes = array(); |
|
31 | + private $deprecated = false; |
|
32 | + private $security = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $operationId = null; |
|
38 | + |
|
39 | + public function getConsumes(): array |
|
40 | + { |
|
41 | + return $this->consumes; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param string $summary |
|
46 | + */ |
|
47 | + public function __construct(AbstractObject $parent, $summary = null, Tag $tag = null) |
|
48 | + { |
|
49 | + parent::__construct($parent); |
|
50 | + $this->summary = $summary; |
|
51 | + if ($tag) { |
|
52 | + $this->tags[] = $tag->getName(); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $command |
|
58 | + * @param string $data |
|
59 | + * @return AbstractObject|boolean |
|
60 | + * @throws Exception |
|
61 | + * @throws Exception |
|
62 | + * @throws Exception |
|
63 | + * @throws Exception |
|
64 | + * @throws Exception |
|
65 | + * @throws Exception |
|
66 | + * @throws Exception |
|
67 | + */ |
|
68 | + public function handleCommand($command, $data = null) |
|
69 | + { |
|
70 | + switch (strtolower($command)) { |
|
71 | + // string |
|
72 | + case 'summary': |
|
73 | + case 'description': |
|
74 | + $this->$command = $data; |
|
75 | + return $this; |
|
76 | + |
|
77 | + // string[] |
|
78 | + case 'tags': |
|
79 | + case 'schemes': |
|
80 | + $this->$command = array_merge($this->$command, self::wordSplit($data)); |
|
81 | + return $this; |
|
82 | + |
|
83 | + // MIME[] |
|
84 | + case 'consumes': |
|
85 | + case 'produces': |
|
86 | + $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data))); |
|
87 | + return $this; |
|
88 | + |
|
89 | + // boolean |
|
90 | + case 'deprecated': |
|
91 | + $this->deprecated = true; |
|
92 | + return $this; |
|
93 | + |
|
94 | + case 'error': |
|
95 | + $code = self::wordShift($data); |
|
96 | + $reasoncode = Response::getCode($code); |
|
97 | + if ($reasoncode === null) { |
|
98 | + throw new Exception("Invalid error code: '$code'"); |
|
99 | + } |
|
100 | + $description = $data; |
|
101 | + $Error = new Error($this, $reasoncode, $description); |
|
102 | + $this->responses[$reasoncode] = $Error; |
|
103 | + return $Error; |
|
104 | + |
|
105 | + case 'errors': |
|
106 | + foreach (self::wordSplit($data) as $code) { |
|
107 | + $reasoncode = Response::getCode($code); |
|
108 | + if ($reasoncode === null) { |
|
109 | + throw new Exception("Invalid error code: '$code'"); |
|
110 | + } |
|
111 | + $this->responses[$reasoncode] = new Error($this, $reasoncode); |
|
112 | + } |
|
113 | + return $this; |
|
114 | + |
|
115 | + case 'path': |
|
116 | + case 'query': |
|
117 | + case 'query?': |
|
118 | + case 'header': |
|
119 | + case 'header?': |
|
120 | + case 'form': |
|
121 | + case 'form?': |
|
122 | + $in = rtrim($command, '?'); |
|
123 | + $parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?'); |
|
124 | + $this->parameters[$parameter->getName()] = $parameter; |
|
125 | + return $parameter; |
|
126 | + |
|
127 | + case 'body': |
|
128 | + case 'body?': |
|
129 | + $parameter = new BodyParameter($this, $data, substr($command, -1) !== '?'); |
|
130 | + $this->parameters[$parameter->getName()] = $parameter; |
|
131 | + return $parameter; |
|
132 | + |
|
133 | + case 'param': |
|
134 | + case 'parameter': |
|
135 | + $parameter = new ParameterReference($this, $data); |
|
136 | + $this->parameters[$parameter->getName()] = $parameter; |
|
137 | + return $this; |
|
138 | + |
|
139 | + case 'response': |
|
140 | + $code = self::wordShift($data); |
|
141 | + $reasoncode = Response::getCode($code); |
|
142 | + if ($reasoncode === null) { |
|
143 | + $reference = $code; |
|
144 | + $code = self::wordShift($data); |
|
145 | + $reasoncode = Response::getCode($code); |
|
146 | + if ($reasoncode === null) { |
|
147 | + throw new Exception("Invalid response code: '$reference'"); |
|
148 | + } |
|
149 | + $this->responses[$reasoncode] = new ResponseReference($this, $reference); |
|
150 | + return $this; |
|
151 | + } |
|
152 | + |
|
153 | + $definition = self::wordShift($data); |
|
154 | + $description = $data; |
|
155 | + $Response = new Response($this, $reasoncode, $definition, $description); |
|
156 | + $this->responses[$reasoncode] = $Response; |
|
157 | + return $Response; |
|
158 | + |
|
159 | + case 'require': |
|
160 | + $name = self::wordShift($data); |
|
161 | + if (empty($name)) { |
|
162 | + throw new Exception('Empty security requirement name'); |
|
163 | + } |
|
164 | + $scopes = self::wordSplit($data); |
|
165 | + sort($scopes); |
|
166 | + $this->security[] = array( |
|
167 | + $name => empty($scopes) ? array() : $scopes, |
|
168 | + ); |
|
169 | + return $this; |
|
170 | + |
|
171 | + case 'id': |
|
172 | + $operationId = self::trim($data); |
|
173 | + if ($this->getSwagger()->hasOperationId($operationId)) { |
|
174 | + throw new Exception("Duplicate operation id '{$operationId}'"); |
|
175 | + } |
|
176 | + $this->operationId = $operationId; |
|
177 | + return $this; |
|
178 | + } |
|
179 | + |
|
180 | + return parent::handleCommand($command, $data); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @throws Exception |
|
185 | + */ |
|
186 | + public function toArray(): array |
|
187 | + { |
|
188 | + if (empty($this->responses)) { |
|
189 | + throw new Exception('No response defined for operation'); |
|
190 | + } |
|
191 | + ksort($this->responses); |
|
192 | + |
|
193 | + $tags = array_unique($this->tags); |
|
194 | + sort($tags); |
|
195 | + |
|
196 | + $schemes = array_unique($this->schemes); |
|
197 | + sort($schemes); |
|
198 | + |
|
199 | + $consumes = array_unique($this->consumes); |
|
200 | + sort($consumes); |
|
201 | + |
|
202 | + $produces = array_unique($this->produces); |
|
203 | + sort($produces); |
|
204 | + |
|
205 | + foreach ($this->security as $security) { |
|
206 | + foreach ($security as $name => $scope) { |
|
207 | + if ($this->getSwagger()->getSecurity($name) === false) { |
|
208 | + throw new Exception("Required security scheme not defined: '{$name}'"); |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + $parameters = $this->parameters ? array_values($this->parameters) : null; |
|
214 | + |
|
215 | + return self::arrayFilterNull(array_merge(array( |
|
216 | + 'deprecated' => $this->deprecated ? true : null, |
|
217 | + 'tags' => $tags, |
|
218 | + 'summary' => empty($this->summary) ? null : $this->summary, |
|
219 | + 'description' => empty($this->description) ? null : $this->description, |
|
220 | + 'operationId' => $this->operationId, |
|
221 | + 'consumes' => $consumes, |
|
222 | + 'produces' => $produces, |
|
223 | + 'parameters' => $parameters ? self::objectsToArray($parameters) : null, |
|
224 | + 'schemes' => $schemes, |
|
225 | + 'responses' => $this->responses ? self::objectsToArray($this->responses) : null, |
|
226 | + 'security' => $this->security, |
|
227 | + ), parent::toArray())); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Return the operation ID |
|
232 | + * |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function getId() |
|
236 | + { |
|
237 | + return $this->operationId; |
|
238 | + } |
|
239 | + |
|
240 | + public function __toString() |
|
241 | + { |
|
242 | + return __CLASS__ . ' ' . $this->summary; |
|
243 | + } |
|
244 | 244 | |
245 | 245 | } |