@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public static function arrayFilterNull($array) |
135 | 135 | { |
136 | - return array_filter($array, function ($value) { |
|
136 | + return array_filter($array, function($value) { |
|
137 | 137 | return $value !== null && $value !== array(); |
138 | 138 | }); |
139 | 139 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public static function objectsToArray($array) |
147 | 147 | { |
148 | - return array_map(function (AbstractObject $item) { |
|
148 | + return array_map(function(AbstractObject $item) { |
|
149 | 149 | return $item->toArray(); |
150 | 150 | }, $array); |
151 | 151 | } |
@@ -16,162 +16,162 @@ |
||
16 | 16 | abstract class AbstractObject |
17 | 17 | { |
18 | 18 | |
19 | - private static $mime_types = array( |
|
20 | - 'fileform' => 'multipart/form-data', |
|
21 | - 'form' => 'application/x-www-form-urlencoded', |
|
22 | - 'json' => 'application/json', |
|
23 | - 'text' => 'text/plain', |
|
24 | - 'utf8' => 'text/plain; charset=utf-8', |
|
25 | - 'yml' => 'application/x-yaml', |
|
26 | - 'yaml' => 'application/x-yaml', |
|
27 | - 'php' => 'text/x-php', |
|
28 | - 'xml' => 'text/xml', |
|
29 | - ); |
|
30 | - |
|
31 | - /** |
|
32 | - * @var AbstractObject |
|
33 | - */ |
|
34 | - private $parent; |
|
35 | - |
|
36 | - /** |
|
37 | - * Map of extensions and their (trimmed) values |
|
38 | - * @var string[] |
|
39 | - */ |
|
40 | - private $extensions = array(); |
|
41 | - |
|
42 | - public function __construct(?AbstractObject $parent = null) |
|
43 | - { |
|
44 | - $this->parent = $parent; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @return AbstractObject |
|
49 | - */ |
|
50 | - protected function getParent() |
|
51 | - { |
|
52 | - return $this->parent; |
|
53 | - } |
|
54 | - |
|
55 | - protected function getParentClass($classname) |
|
56 | - { |
|
57 | - if (is_a($this, $classname)) { |
|
58 | - return $this; |
|
59 | - } |
|
60 | - return $this->parent->getParentClass($classname); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @return Swagger |
|
65 | - */ |
|
66 | - protected function getSwagger() |
|
67 | - { |
|
68 | - return $this->parent->getSwagger(); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return TypeRegistry |
|
73 | - */ |
|
74 | - protected function getTypeRegistry() |
|
75 | - { |
|
76 | - return $this->parent->getTypeRegistry(); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $command |
|
81 | - * @param string $data |
|
82 | - * @return AbstractObject|boolean |
|
83 | - */ |
|
84 | - public function handleCommand($command, $data = null) |
|
85 | - { |
|
86 | - if (strtolower(substr($command, 0, 2)) === 'x-') { |
|
87 | - $this->extensions[$command] = empty($data) ? $data : trim($data); |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - return false; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function toArray() |
|
98 | - { |
|
99 | - return $this->extensions; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Translate consumes from shortcuts |
|
104 | - * @param String[] $mimeTypes |
|
105 | - * @return String[] |
|
106 | - */ |
|
107 | - protected static function translateMimeTypes($mimeTypes) |
|
108 | - { |
|
109 | - foreach ($mimeTypes as &$mimeType) { |
|
110 | - if (isset(self::$mime_types[strtolower($mimeType)])) { |
|
111 | - $mimeType = self::$mime_types[strtolower($mimeType)]; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - return $mimeTypes; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Trim whitespace from a multibyte string |
|
120 | - * @param string $string |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public static function trim($string) |
|
124 | - { |
|
125 | - return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Filter all items from an array where the value is either null or an |
|
130 | - * empty array. |
|
131 | - * @param array $array |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - public static function arrayFilterNull($array) |
|
135 | - { |
|
136 | - return array_filter($array, function ($value) { |
|
137 | - return $value !== null && $value !== array(); |
|
138 | - }); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Recursively call toArray() on all objects to return an array |
|
143 | - * @param array $array |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - public static function objectsToArray($array) |
|
147 | - { |
|
148 | - return array_map(function (AbstractObject $item) { |
|
149 | - return $item->toArray(); |
|
150 | - }, $array); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Shifts the first word off a text line and returns it |
|
155 | - * @param string $data |
|
156 | - * @return string|bool Either the first word or false if no more words available |
|
157 | - */ |
|
158 | - public static function wordShift(&$data) |
|
159 | - { |
|
160 | - if (preg_match('~^\s*(\S+)\s*(.*)$~s', $data, $matches) === 1) { |
|
161 | - $data = $matches[2]; |
|
162 | - return $matches[1]; |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Splits a text line in all it's words |
|
169 | - * @param string $data |
|
170 | - * @return string[] |
|
171 | - */ |
|
172 | - public static function wordSplit($data): array |
|
173 | - { |
|
174 | - return array_values(preg_grep('~\S~', preg_split('~\s+~', $data))); |
|
175 | - } |
|
19 | + private static $mime_types = array( |
|
20 | + 'fileform' => 'multipart/form-data', |
|
21 | + 'form' => 'application/x-www-form-urlencoded', |
|
22 | + 'json' => 'application/json', |
|
23 | + 'text' => 'text/plain', |
|
24 | + 'utf8' => 'text/plain; charset=utf-8', |
|
25 | + 'yml' => 'application/x-yaml', |
|
26 | + 'yaml' => 'application/x-yaml', |
|
27 | + 'php' => 'text/x-php', |
|
28 | + 'xml' => 'text/xml', |
|
29 | + ); |
|
30 | + |
|
31 | + /** |
|
32 | + * @var AbstractObject |
|
33 | + */ |
|
34 | + private $parent; |
|
35 | + |
|
36 | + /** |
|
37 | + * Map of extensions and their (trimmed) values |
|
38 | + * @var string[] |
|
39 | + */ |
|
40 | + private $extensions = array(); |
|
41 | + |
|
42 | + public function __construct(?AbstractObject $parent = null) |
|
43 | + { |
|
44 | + $this->parent = $parent; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @return AbstractObject |
|
49 | + */ |
|
50 | + protected function getParent() |
|
51 | + { |
|
52 | + return $this->parent; |
|
53 | + } |
|
54 | + |
|
55 | + protected function getParentClass($classname) |
|
56 | + { |
|
57 | + if (is_a($this, $classname)) { |
|
58 | + return $this; |
|
59 | + } |
|
60 | + return $this->parent->getParentClass($classname); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @return Swagger |
|
65 | + */ |
|
66 | + protected function getSwagger() |
|
67 | + { |
|
68 | + return $this->parent->getSwagger(); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return TypeRegistry |
|
73 | + */ |
|
74 | + protected function getTypeRegistry() |
|
75 | + { |
|
76 | + return $this->parent->getTypeRegistry(); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $command |
|
81 | + * @param string $data |
|
82 | + * @return AbstractObject|boolean |
|
83 | + */ |
|
84 | + public function handleCommand($command, $data = null) |
|
85 | + { |
|
86 | + if (strtolower(substr($command, 0, 2)) === 'x-') { |
|
87 | + $this->extensions[$command] = empty($data) ? $data : trim($data); |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + return false; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function toArray() |
|
98 | + { |
|
99 | + return $this->extensions; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Translate consumes from shortcuts |
|
104 | + * @param String[] $mimeTypes |
|
105 | + * @return String[] |
|
106 | + */ |
|
107 | + protected static function translateMimeTypes($mimeTypes) |
|
108 | + { |
|
109 | + foreach ($mimeTypes as &$mimeType) { |
|
110 | + if (isset(self::$mime_types[strtolower($mimeType)])) { |
|
111 | + $mimeType = self::$mime_types[strtolower($mimeType)]; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + return $mimeTypes; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Trim whitespace from a multibyte string |
|
120 | + * @param string $string |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public static function trim($string) |
|
124 | + { |
|
125 | + return mb_ereg_replace('^\s*([\s\S]*?)\s*$', '\1', $string); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Filter all items from an array where the value is either null or an |
|
130 | + * empty array. |
|
131 | + * @param array $array |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + public static function arrayFilterNull($array) |
|
135 | + { |
|
136 | + return array_filter($array, function ($value) { |
|
137 | + return $value !== null && $value !== array(); |
|
138 | + }); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Recursively call toArray() on all objects to return an array |
|
143 | + * @param array $array |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + public static function objectsToArray($array) |
|
147 | + { |
|
148 | + return array_map(function (AbstractObject $item) { |
|
149 | + return $item->toArray(); |
|
150 | + }, $array); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Shifts the first word off a text line and returns it |
|
155 | + * @param string $data |
|
156 | + * @return string|bool Either the first word or false if no more words available |
|
157 | + */ |
|
158 | + public static function wordShift(&$data) |
|
159 | + { |
|
160 | + if (preg_match('~^\s*(\S+)\s*(.*)$~s', $data, $matches) === 1) { |
|
161 | + $data = $matches[2]; |
|
162 | + return $matches[1]; |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Splits a text line in all it's words |
|
169 | + * @param string $data |
|
170 | + * @return string[] |
|
171 | + */ |
|
172 | + public static function wordSplit($data): array |
|
173 | + { |
|
174 | + return array_values(preg_grep('~\S~', preg_split('~\s+~', $data))); |
|
175 | + } |
|
176 | 176 | |
177 | 177 | } |
@@ -17,88 +17,88 @@ |
||
17 | 17 | class Schema extends AbstractDocumentableObject implements IDefinition |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - private $description; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $title = null; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
33 | - private $readOnly = null; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var AbstractType |
|
37 | - */ |
|
38 | - private $type; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string $description |
|
42 | - * @throws Exception |
|
43 | - */ |
|
44 | - public function __construct(AbstractObject $parent, $definition = 'object', $description = null) |
|
45 | - { |
|
46 | - parent::__construct($parent); |
|
47 | - |
|
48 | - // Check if definition set |
|
49 | - if ($this->getSwagger()->hasDefinition($definition)) { |
|
50 | - $this->type = new Type\ReferenceObjectType($this, $definition); |
|
51 | - } else { |
|
52 | - $this->type = Type\AbstractType::typeFactory($this, $definition); |
|
53 | - } |
|
54 | - |
|
55 | - $this->description = $description; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $command |
|
60 | - * @param string $data |
|
61 | - * @return AbstractObject|boolean |
|
62 | - * @throws Exception |
|
63 | - */ |
|
64 | - public function handleCommand($command, $data = null) |
|
65 | - { |
|
66 | - // Pass through to Type |
|
67 | - if ($this->type && $this->type->handleCommand($command, $data)) { |
|
68 | - return $this; |
|
69 | - } |
|
70 | - |
|
71 | - // handle all the rest manually |
|
72 | - switch (strtolower($command)) { |
|
73 | - case 'description': |
|
74 | - $this->description = $data; |
|
75 | - return $this; |
|
76 | - |
|
77 | - case 'title': |
|
78 | - $this->title = $data; |
|
79 | - return $this; |
|
80 | - } |
|
81 | - |
|
82 | - return parent::handleCommand($command, $data); |
|
83 | - } |
|
84 | - |
|
85 | - public function toArray() |
|
86 | - { |
|
87 | - return self::arrayFilterNull(array_merge($this->type->toArray(), array( |
|
88 | - 'title' => empty($this->title) ? null : $this->title, |
|
89 | - 'description' => empty($this->description) ? null : $this->description, |
|
90 | - 'readOnly' => $this->readOnly |
|
91 | - ), parent::toArray())); |
|
92 | - } |
|
93 | - |
|
94 | - public function __toString() |
|
95 | - { |
|
96 | - return __CLASS__; |
|
97 | - } |
|
98 | - |
|
99 | - public function setReadOnly() |
|
100 | - { |
|
101 | - $this->readOnly = true; |
|
102 | - } |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + private $description; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $title = null; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | + private $readOnly = null; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var AbstractType |
|
37 | + */ |
|
38 | + private $type; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string $description |
|
42 | + * @throws Exception |
|
43 | + */ |
|
44 | + public function __construct(AbstractObject $parent, $definition = 'object', $description = null) |
|
45 | + { |
|
46 | + parent::__construct($parent); |
|
47 | + |
|
48 | + // Check if definition set |
|
49 | + if ($this->getSwagger()->hasDefinition($definition)) { |
|
50 | + $this->type = new Type\ReferenceObjectType($this, $definition); |
|
51 | + } else { |
|
52 | + $this->type = Type\AbstractType::typeFactory($this, $definition); |
|
53 | + } |
|
54 | + |
|
55 | + $this->description = $description; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $command |
|
60 | + * @param string $data |
|
61 | + * @return AbstractObject|boolean |
|
62 | + * @throws Exception |
|
63 | + */ |
|
64 | + public function handleCommand($command, $data = null) |
|
65 | + { |
|
66 | + // Pass through to Type |
|
67 | + if ($this->type && $this->type->handleCommand($command, $data)) { |
|
68 | + return $this; |
|
69 | + } |
|
70 | + |
|
71 | + // handle all the rest manually |
|
72 | + switch (strtolower($command)) { |
|
73 | + case 'description': |
|
74 | + $this->description = $data; |
|
75 | + return $this; |
|
76 | + |
|
77 | + case 'title': |
|
78 | + $this->title = $data; |
|
79 | + return $this; |
|
80 | + } |
|
81 | + |
|
82 | + return parent::handleCommand($command, $data); |
|
83 | + } |
|
84 | + |
|
85 | + public function toArray() |
|
86 | + { |
|
87 | + return self::arrayFilterNull(array_merge($this->type->toArray(), array( |
|
88 | + 'title' => empty($this->title) ? null : $this->title, |
|
89 | + 'description' => empty($this->description) ? null : $this->description, |
|
90 | + 'readOnly' => $this->readOnly |
|
91 | + ), parent::toArray())); |
|
92 | + } |
|
93 | + |
|
94 | + public function __toString() |
|
95 | + { |
|
96 | + return __CLASS__; |
|
97 | + } |
|
98 | + |
|
99 | + public function setReadOnly() |
|
100 | + { |
|
101 | + $this->readOnly = true; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
@@ -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 | } |