@@ -15,48 +15,48 @@ |
||
15 | 15 | class ReferenceObjectType extends AbstractType |
16 | 16 | { |
17 | 17 | |
18 | - private $reference = null; |
|
19 | - |
|
20 | - public function toArray(): array |
|
21 | - { |
|
22 | - return self::arrayFilterNull(array_merge(array( |
|
23 | - '$ref' => '#/definitions/' . $this->reference, |
|
24 | - ), parent::toArray())); |
|
25 | - } |
|
26 | - |
|
27 | - public function __toString() |
|
28 | - { |
|
29 | - return __CLASS__ . ' ' . $this->reference; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @throws Exception |
|
34 | - */ |
|
35 | - protected function parseDefinition($definition) |
|
36 | - { |
|
37 | - $definition = self::trim($definition); |
|
38 | - |
|
39 | - $match = []; |
|
40 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
41 | - throw new Exception('Unparseable string definition: \'' . $definition . '\''); |
|
42 | - } |
|
43 | - |
|
44 | - $type = strtolower($match[1]); |
|
45 | - |
|
46 | - $reference = null; |
|
47 | - if ($type === 'refobject') { |
|
48 | - if (isset($match[2])) { |
|
49 | - $reference = $match[2]; |
|
50 | - } |
|
51 | - } else { |
|
52 | - $reference = $match[1]; |
|
53 | - } |
|
54 | - |
|
55 | - if (empty($reference)) { |
|
56 | - throw new Exception('Referenced object name missing: \'' . $definition . '\''); |
|
57 | - } |
|
58 | - |
|
59 | - $this->reference = $reference; |
|
60 | - } |
|
18 | + private $reference = null; |
|
19 | + |
|
20 | + public function toArray(): array |
|
21 | + { |
|
22 | + return self::arrayFilterNull(array_merge(array( |
|
23 | + '$ref' => '#/definitions/' . $this->reference, |
|
24 | + ), parent::toArray())); |
|
25 | + } |
|
26 | + |
|
27 | + public function __toString() |
|
28 | + { |
|
29 | + return __CLASS__ . ' ' . $this->reference; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @throws Exception |
|
34 | + */ |
|
35 | + protected function parseDefinition($definition) |
|
36 | + { |
|
37 | + $definition = self::trim($definition); |
|
38 | + |
|
39 | + $match = []; |
|
40 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
41 | + throw new Exception('Unparseable string definition: \'' . $definition . '\''); |
|
42 | + } |
|
43 | + |
|
44 | + $type = strtolower($match[1]); |
|
45 | + |
|
46 | + $reference = null; |
|
47 | + if ($type === 'refobject') { |
|
48 | + if (isset($match[2])) { |
|
49 | + $reference = $match[2]; |
|
50 | + } |
|
51 | + } else { |
|
52 | + $reference = $match[1]; |
|
53 | + } |
|
54 | + |
|
55 | + if (empty($reference)) { |
|
56 | + throw new Exception('Referenced object name missing: \'' . $definition . '\''); |
|
57 | + } |
|
58 | + |
|
59 | + $this->reference = $reference; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -15,286 +15,286 @@ |
||
15 | 15 | class ObjectType extends AbstractType |
16 | 16 | { |
17 | 17 | |
18 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | - const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?'; |
|
20 | - const REGEX_PROP_START = '/^'; |
|
21 | - const REGEX_PROP_NAME = '([^?!:]+)'; |
|
22 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
23 | - const REGEX_PROP_REQUIRED = '([\?!])?'; |
|
24 | - const REGEX_PROP_ASSIGN = ':'; |
|
25 | - const REGEX_PROP_DEFINITION = '(.+)'; |
|
26 | - /** @noinspection PhpRegExpUnsupportedModifierInspection |
|
27 | - * @noinspection PhpRegExpInvalidDelimiterInspection |
|
28 | - */ |
|
29 | - const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?'; |
|
30 | - const REGEX_PROP_END = '$/'; |
|
18 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | + const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?'; |
|
20 | + const REGEX_PROP_START = '/^'; |
|
21 | + const REGEX_PROP_NAME = '([^?!:]+)'; |
|
22 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
23 | + const REGEX_PROP_REQUIRED = '([\?!])?'; |
|
24 | + const REGEX_PROP_ASSIGN = ':'; |
|
25 | + const REGEX_PROP_DEFINITION = '(.+)'; |
|
26 | + /** @noinspection PhpRegExpUnsupportedModifierInspection |
|
27 | + * @noinspection PhpRegExpInvalidDelimiterInspection |
|
28 | + */ |
|
29 | + const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?'; |
|
30 | + const REGEX_PROP_END = '$/'; |
|
31 | 31 | |
32 | - private $minProperties = null; |
|
33 | - private $maxProperties = null; |
|
34 | - private $discriminator = null; |
|
35 | - private $additionalProperties = null; |
|
36 | - private $required = []; |
|
32 | + private $minProperties = null; |
|
33 | + private $maxProperties = null; |
|
34 | + private $discriminator = null; |
|
35 | + private $additionalProperties = null; |
|
36 | + private $required = []; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var Property[] |
|
40 | - */ |
|
41 | - private $properties = []; |
|
38 | + /** |
|
39 | + * @var Property[] |
|
40 | + */ |
|
41 | + private $properties = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var Property |
|
45 | - */ |
|
46 | - private $mostRecentProperty = null; |
|
43 | + /** |
|
44 | + * @var Property |
|
45 | + */ |
|
46 | + private $mostRecentProperty = null; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $command The comment command |
|
50 | - * @param string $data Any data added after the command |
|
51 | - * @return AbstractType|boolean |
|
52 | - * @throws Exception |
|
53 | - * @throws Exception |
|
54 | - * @throws Exception |
|
55 | - * @throws Exception |
|
56 | - * @throws Exception |
|
57 | - * @throws Exception |
|
58 | - * @throws Exception |
|
59 | - * @throws Exception |
|
60 | - * @throws Exception |
|
61 | - * @throws Exception |
|
62 | - * @throws Exception |
|
63 | - * @throws Exception |
|
64 | - */ |
|
65 | - public function handleCommand($command, $data = null) |
|
66 | - { |
|
67 | - switch (strtolower($command)) { |
|
68 | - // type name description... |
|
69 | - case 'additionalproperties': |
|
70 | - $value = self::wordShift($data); |
|
71 | - if (is_bool($value)) { |
|
72 | - $type = $value; |
|
73 | - } else if ($value === 'false') { |
|
74 | - $type = false; |
|
75 | - } else if ($value === 'true') { |
|
76 | - $type = true; |
|
77 | - } else { |
|
78 | - $type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'"); |
|
79 | - } |
|
80 | - $this->setAdditionalProperties($type); |
|
81 | - return $this; |
|
82 | - case 'discriminator': |
|
83 | - $discriminator = self::wordShift($data); |
|
84 | - $this->setDiscriminator($discriminator); |
|
85 | - return $this; |
|
86 | - case 'property': |
|
87 | - case 'property?': |
|
88 | - case 'property!': |
|
89 | - $definition = self::wordShift($data); |
|
90 | - if (empty($definition)) { |
|
91 | - throw new Exception("Missing property definition"); |
|
92 | - } |
|
48 | + /** |
|
49 | + * @param string $command The comment command |
|
50 | + * @param string $data Any data added after the command |
|
51 | + * @return AbstractType|boolean |
|
52 | + * @throws Exception |
|
53 | + * @throws Exception |
|
54 | + * @throws Exception |
|
55 | + * @throws Exception |
|
56 | + * @throws Exception |
|
57 | + * @throws Exception |
|
58 | + * @throws Exception |
|
59 | + * @throws Exception |
|
60 | + * @throws Exception |
|
61 | + * @throws Exception |
|
62 | + * @throws Exception |
|
63 | + * @throws Exception |
|
64 | + */ |
|
65 | + public function handleCommand($command, $data = null) |
|
66 | + { |
|
67 | + switch (strtolower($command)) { |
|
68 | + // type name description... |
|
69 | + case 'additionalproperties': |
|
70 | + $value = self::wordShift($data); |
|
71 | + if (is_bool($value)) { |
|
72 | + $type = $value; |
|
73 | + } else if ($value === 'false') { |
|
74 | + $type = false; |
|
75 | + } else if ($value === 'true') { |
|
76 | + $type = true; |
|
77 | + } else { |
|
78 | + $type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'"); |
|
79 | + } |
|
80 | + $this->setAdditionalProperties($type); |
|
81 | + return $this; |
|
82 | + case 'discriminator': |
|
83 | + $discriminator = self::wordShift($data); |
|
84 | + $this->setDiscriminator($discriminator); |
|
85 | + return $this; |
|
86 | + case 'property': |
|
87 | + case 'property?': |
|
88 | + case 'property!': |
|
89 | + $definition = self::wordShift($data); |
|
90 | + if (empty($definition)) { |
|
91 | + throw new Exception("Missing property definition"); |
|
92 | + } |
|
93 | 93 | |
94 | - $name = self::wordShift($data); |
|
95 | - if (empty($name)) { |
|
96 | - throw new Exception("Missing property name: '{$definition}'"); |
|
97 | - } |
|
94 | + $name = self::wordShift($data); |
|
95 | + if (empty($name)) { |
|
96 | + throw new Exception("Missing property name: '{$definition}'"); |
|
97 | + } |
|
98 | 98 | |
99 | - $readOnly = null; |
|
100 | - $required = false; |
|
101 | - $propertySuffix = substr($command, -1); |
|
102 | - if ($propertySuffix === '!') { |
|
103 | - $readOnly = true; |
|
104 | - } else if ($propertySuffix !== '?') { |
|
105 | - $required = true; |
|
106 | - } |
|
99 | + $readOnly = null; |
|
100 | + $required = false; |
|
101 | + $propertySuffix = substr($command, -1); |
|
102 | + if ($propertySuffix === '!') { |
|
103 | + $readOnly = true; |
|
104 | + } else if ($propertySuffix !== '?') { |
|
105 | + $required = true; |
|
106 | + } |
|
107 | 107 | |
108 | - if (($name === $this->discriminator) && !$required) { |
|
109 | - throw new Exception("Discriminator must be a required property, " |
|
110 | - . "property '{$name}' is not required"); |
|
111 | - } |
|
108 | + if (($name === $this->discriminator) && !$required) { |
|
109 | + throw new Exception("Discriminator must be a required property, " |
|
110 | + . "property '{$name}' is not required"); |
|
111 | + } |
|
112 | 112 | |
113 | - unset($this->required[$name]); |
|
114 | - if ($required) { |
|
115 | - $this->required[$name] = true; |
|
116 | - } |
|
113 | + unset($this->required[$name]); |
|
114 | + if ($required) { |
|
115 | + $this->required[$name] = true; |
|
116 | + } |
|
117 | 117 | |
118 | - $this->mostRecentProperty = new Property($this, $definition, $data, $readOnly); |
|
119 | - $this->properties[$name] = $this->mostRecentProperty; |
|
120 | - return $this; |
|
118 | + $this->mostRecentProperty = new Property($this, $definition, $data, $readOnly); |
|
119 | + $this->properties[$name] = $this->mostRecentProperty; |
|
120 | + return $this; |
|
121 | 121 | |
122 | - case 'min': |
|
123 | - $this->minProperties = (int)$data; |
|
124 | - if ($this->minProperties < 0) { |
|
125 | - throw new Exception("Minimum less than zero: '{$data}'"); |
|
126 | - } |
|
127 | - if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) { |
|
128 | - throw new Exception("Minimum greater than maximum: '{$data}'"); |
|
129 | - } |
|
130 | - $this->minProperties = (int)$data; |
|
131 | - return $this; |
|
122 | + case 'min': |
|
123 | + $this->minProperties = (int)$data; |
|
124 | + if ($this->minProperties < 0) { |
|
125 | + throw new Exception("Minimum less than zero: '{$data}'"); |
|
126 | + } |
|
127 | + if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) { |
|
128 | + throw new Exception("Minimum greater than maximum: '{$data}'"); |
|
129 | + } |
|
130 | + $this->minProperties = (int)$data; |
|
131 | + return $this; |
|
132 | 132 | |
133 | - case 'max': |
|
134 | - $this->maxProperties = (int)$data; |
|
135 | - if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) { |
|
136 | - throw new Exception("Maximum less than minimum: '{$data}'"); |
|
137 | - } |
|
138 | - if ($this->maxProperties < 0) { |
|
139 | - throw new Exception("Maximum less than zero: '{$data}'"); |
|
140 | - } |
|
141 | - return $this; |
|
142 | - } |
|
133 | + case 'max': |
|
134 | + $this->maxProperties = (int)$data; |
|
135 | + if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) { |
|
136 | + throw new Exception("Maximum less than minimum: '{$data}'"); |
|
137 | + } |
|
138 | + if ($this->maxProperties < 0) { |
|
139 | + throw new Exception("Maximum less than zero: '{$data}'"); |
|
140 | + } |
|
141 | + return $this; |
|
142 | + } |
|
143 | 143 | |
144 | - // Pass through to most recent Property |
|
145 | - if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) { |
|
146 | - return $this; |
|
147 | - } |
|
144 | + // Pass through to most recent Property |
|
145 | + if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) { |
|
146 | + return $this; |
|
147 | + } |
|
148 | 148 | |
149 | - return parent::handleCommand($command, $data); |
|
150 | - } |
|
149 | + return parent::handleCommand($command, $data); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param AbstractType|bool $type |
|
154 | - * @return void |
|
155 | - * @throws Exception |
|
156 | - */ |
|
157 | - private function setAdditionalProperties($type) |
|
158 | - { |
|
159 | - if ($this->additionalProperties !== null) { |
|
160 | - throw new Exception('Additional properties may only be set once'); |
|
161 | - } |
|
162 | - $this->additionalProperties = $type; |
|
163 | - } |
|
152 | + /** |
|
153 | + * @param AbstractType|bool $type |
|
154 | + * @return void |
|
155 | + * @throws Exception |
|
156 | + */ |
|
157 | + private function setAdditionalProperties($type) |
|
158 | + { |
|
159 | + if ($this->additionalProperties !== null) { |
|
160 | + throw new Exception('Additional properties may only be set once'); |
|
161 | + } |
|
162 | + $this->additionalProperties = $type; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @param string|false $discriminator |
|
167 | - * @throws Exception |
|
168 | - * @throws Exception |
|
169 | - */ |
|
170 | - private function setDiscriminator($discriminator) |
|
171 | - { |
|
172 | - if (!empty($this->discriminator)) { |
|
173 | - throw new Exception("Discriminator may only be set once, " |
|
174 | - . "trying to change it " |
|
175 | - . "from '{$this->discriminator}' " |
|
176 | - . "to '{$discriminator}'"); |
|
177 | - } |
|
178 | - if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) { |
|
179 | - throw new Exception("Discriminator must be a required property, " |
|
180 | - . "property '{$discriminator}' is not required"); |
|
181 | - } |
|
182 | - $this->discriminator = $discriminator; |
|
183 | - } |
|
165 | + /** |
|
166 | + * @param string|false $discriminator |
|
167 | + * @throws Exception |
|
168 | + * @throws Exception |
|
169 | + */ |
|
170 | + private function setDiscriminator($discriminator) |
|
171 | + { |
|
172 | + if (!empty($this->discriminator)) { |
|
173 | + throw new Exception("Discriminator may only be set once, " |
|
174 | + . "trying to change it " |
|
175 | + . "from '{$this->discriminator}' " |
|
176 | + . "to '{$discriminator}'"); |
|
177 | + } |
|
178 | + if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) { |
|
179 | + throw new Exception("Discriminator must be a required property, " |
|
180 | + . "property '{$discriminator}' is not required"); |
|
181 | + } |
|
182 | + $this->discriminator = $discriminator; |
|
183 | + } |
|
184 | 184 | |
185 | - public function toArray(): array |
|
186 | - { |
|
187 | - return self::arrayFilterNull(array_merge(array( |
|
188 | - 'type' => 'object', |
|
189 | - 'required' => array_keys($this->required), |
|
190 | - 'properties' => self::objectsToArray($this->properties), |
|
191 | - 'minProperties' => $this->minProperties, |
|
192 | - 'maxProperties' => $this->maxProperties, |
|
193 | - 'discriminator' => $this->discriminator, |
|
194 | - 'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties, |
|
195 | - ), parent::toArray())); |
|
196 | - } |
|
185 | + public function toArray(): array |
|
186 | + { |
|
187 | + return self::arrayFilterNull(array_merge(array( |
|
188 | + 'type' => 'object', |
|
189 | + 'required' => array_keys($this->required), |
|
190 | + 'properties' => self::objectsToArray($this->properties), |
|
191 | + 'minProperties' => $this->minProperties, |
|
192 | + 'maxProperties' => $this->maxProperties, |
|
193 | + 'discriminator' => $this->discriminator, |
|
194 | + 'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties, |
|
195 | + ), parent::toArray())); |
|
196 | + } |
|
197 | 197 | |
198 | - public function __toString() |
|
199 | - { |
|
200 | - return __CLASS__; |
|
201 | - } |
|
198 | + public function __toString() |
|
199 | + { |
|
200 | + return __CLASS__; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @throws Exception |
|
205 | - */ |
|
206 | - protected function parseDefinition($definition) |
|
207 | - { |
|
208 | - $definition = self::trim($definition); |
|
203 | + /** |
|
204 | + * @throws Exception |
|
205 | + */ |
|
206 | + protected function parseDefinition($definition) |
|
207 | + { |
|
208 | + $definition = self::trim($definition); |
|
209 | 209 | |
210 | - $match = []; |
|
211 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) { |
|
212 | - $match[1] = strtolower($match[1]); |
|
213 | - } elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) { |
|
214 | - $match[1] = 'object'; |
|
215 | - } else { |
|
216 | - throw new Exception('Unparseable object definition: \'' . $definition . '\''); |
|
217 | - } |
|
210 | + $match = []; |
|
211 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) { |
|
212 | + $match[1] = strtolower($match[1]); |
|
213 | + } elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) { |
|
214 | + $match[1] = 'object'; |
|
215 | + } else { |
|
216 | + throw new Exception('Unparseable object definition: \'' . $definition . '\''); |
|
217 | + } |
|
218 | 218 | |
219 | - $this->parseFormat($definition, $match); |
|
220 | - $this->parseProperties($definition, $match); |
|
221 | - $this->parseRange($definition, $match); |
|
222 | - } |
|
219 | + $this->parseFormat($definition, $match); |
|
220 | + $this->parseProperties($definition, $match); |
|
221 | + $this->parseRange($definition, $match); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * @param string $definition |
|
226 | - * @param string[] $match |
|
227 | - * @throws Exception |
|
228 | - */ |
|
229 | - private function parseFormat($definition, $match) |
|
230 | - { |
|
231 | - if (strtolower($match[1]) !== 'object') { |
|
232 | - throw new Exception("Not an object: '{$definition}'"); |
|
233 | - } |
|
234 | - } |
|
224 | + /** |
|
225 | + * @param string $definition |
|
226 | + * @param string[] $match |
|
227 | + * @throws Exception |
|
228 | + */ |
|
229 | + private function parseFormat($definition, $match) |
|
230 | + { |
|
231 | + if (strtolower($match[1]) !== 'object') { |
|
232 | + throw new Exception("Not an object: '{$definition}'"); |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @param string $definition |
|
238 | - * @param string[] $match |
|
239 | - * @throws Exception |
|
240 | - * @throws Exception |
|
241 | - * @throws Exception |
|
242 | - * @throws Exception |
|
243 | - * @throws Exception |
|
244 | - * @throws Exception |
|
245 | - */ |
|
246 | - private function parseProperties($definition, $match) |
|
247 | - { |
|
248 | - if (empty($match[2])) { |
|
249 | - return; |
|
250 | - } |
|
236 | + /** |
|
237 | + * @param string $definition |
|
238 | + * @param string[] $match |
|
239 | + * @throws Exception |
|
240 | + * @throws Exception |
|
241 | + * @throws Exception |
|
242 | + * @throws Exception |
|
243 | + * @throws Exception |
|
244 | + * @throws Exception |
|
245 | + */ |
|
246 | + private function parseProperties($definition, $match) |
|
247 | + { |
|
248 | + if (empty($match[2])) { |
|
249 | + return; |
|
250 | + } |
|
251 | 251 | |
252 | - while (($property = self::parseListItem($match[2])) !== '') { |
|
253 | - $prop_match = []; |
|
254 | - if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) { |
|
255 | - if (empty($prop_match[1])) { |
|
256 | - $this->setAdditionalProperties(true); |
|
257 | - } else if ($prop_match[1] === '!') { |
|
258 | - $this->setAdditionalProperties(false); |
|
259 | - } else { |
|
260 | - $this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'")); |
|
261 | - } |
|
262 | - continue; |
|
263 | - } |
|
264 | - if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_NAME . self::REGEX_PROP_REQUIRED . self::REGEX_PROP_ASSIGN . self::REGEX_PROP_DEFINITION . self::REGEX_PROP_END, $property, $prop_match) !== 1) { |
|
265 | - throw new Exception("Unparseable property definition: '{$property}'"); |
|
266 | - } |
|
267 | - $this->properties[$prop_match[1]] = new Property($this, $prop_match[3]); |
|
268 | - if ($prop_match[2] !== '!' && $prop_match[2] !== '?') { |
|
269 | - $this->required[$prop_match[1]] = true; |
|
270 | - } |
|
271 | - } |
|
252 | + while (($property = self::parseListItem($match[2])) !== '') { |
|
253 | + $prop_match = []; |
|
254 | + if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) { |
|
255 | + if (empty($prop_match[1])) { |
|
256 | + $this->setAdditionalProperties(true); |
|
257 | + } else if ($prop_match[1] === '!') { |
|
258 | + $this->setAdditionalProperties(false); |
|
259 | + } else { |
|
260 | + $this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'")); |
|
261 | + } |
|
262 | + continue; |
|
263 | + } |
|
264 | + if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_NAME . self::REGEX_PROP_REQUIRED . self::REGEX_PROP_ASSIGN . self::REGEX_PROP_DEFINITION . self::REGEX_PROP_END, $property, $prop_match) !== 1) { |
|
265 | + throw new Exception("Unparseable property definition: '{$property}'"); |
|
266 | + } |
|
267 | + $this->properties[$prop_match[1]] = new Property($this, $prop_match[3]); |
|
268 | + if ($prop_match[2] !== '!' && $prop_match[2] !== '?') { |
|
269 | + $this->required[$prop_match[1]] = true; |
|
270 | + } |
|
271 | + } |
|
272 | 272 | |
273 | - } |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * @param string $definition |
|
277 | - * @param string[] $match |
|
278 | - * @throws Exception |
|
279 | - */ |
|
280 | - private function parseRange($definition, $match) |
|
281 | - { |
|
282 | - if (!empty($match[3])) { |
|
283 | - if ($match[4] === '' && $match[5] === '') { |
|
284 | - throw new Exception("Empty object range: '{$definition}'"); |
|
285 | - } |
|
275 | + /** |
|
276 | + * @param string $definition |
|
277 | + * @param string[] $match |
|
278 | + * @throws Exception |
|
279 | + */ |
|
280 | + private function parseRange($definition, $match) |
|
281 | + { |
|
282 | + if (!empty($match[3])) { |
|
283 | + if ($match[4] === '' && $match[5] === '') { |
|
284 | + throw new Exception("Empty object range: '{$definition}'"); |
|
285 | + } |
|
286 | 286 | |
287 | - $exclusiveMinimum = $match[3] == '<'; |
|
288 | - $this->minProperties = $match[4] === '' ? null : (int)$match[4]; |
|
289 | - $this->maxProperties = $match[5] === '' ? null : (int)$match[5]; |
|
290 | - $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null; |
|
291 | - if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) { |
|
292 | - self::swap($this->minProperties, $this->maxProperties); |
|
293 | - self::swap($exclusiveMinimum, $exclusiveMaximum); |
|
294 | - } |
|
295 | - $this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties); |
|
296 | - $this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties); |
|
297 | - } |
|
298 | - } |
|
287 | + $exclusiveMinimum = $match[3] == '<'; |
|
288 | + $this->minProperties = $match[4] === '' ? null : (int)$match[4]; |
|
289 | + $this->maxProperties = $match[5] === '' ? null : (int)$match[5]; |
|
290 | + $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null; |
|
291 | + if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) { |
|
292 | + self::swap($this->minProperties, $this->maxProperties); |
|
293 | + self::swap($exclusiveMinimum, $exclusiveMaximum); |
|
294 | + } |
|
295 | + $this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties); |
|
296 | + $this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties); |
|
297 | + } |
|
298 | + } |
|
299 | 299 | |
300 | 300 | } |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | return $this; |
121 | 121 | |
122 | 122 | case 'min': |
123 | - $this->minProperties = (int)$data; |
|
123 | + $this->minProperties = (int) $data; |
|
124 | 124 | if ($this->minProperties < 0) { |
125 | 125 | throw new Exception("Minimum less than zero: '{$data}'"); |
126 | 126 | } |
127 | 127 | if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) { |
128 | 128 | throw new Exception("Minimum greater than maximum: '{$data}'"); |
129 | 129 | } |
130 | - $this->minProperties = (int)$data; |
|
130 | + $this->minProperties = (int) $data; |
|
131 | 131 | return $this; |
132 | 132 | |
133 | 133 | case 'max': |
134 | - $this->maxProperties = (int)$data; |
|
134 | + $this->maxProperties = (int) $data; |
|
135 | 135 | if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) { |
136 | 136 | throw new Exception("Maximum less than minimum: '{$data}'"); |
137 | 137 | } |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | $exclusiveMinimum = $match[3] == '<'; |
288 | - $this->minProperties = $match[4] === '' ? null : (int)$match[4]; |
|
289 | - $this->maxProperties = $match[5] === '' ? null : (int)$match[5]; |
|
288 | + $this->minProperties = $match[4] === '' ? null : (int) $match[4]; |
|
289 | + $this->maxProperties = $match[5] === '' ? null : (int) $match[5]; |
|
290 | 290 | $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null; |
291 | 291 | if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) { |
292 | 292 | self::swap($this->minProperties, $this->maxProperties); |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class AllOfType extends AbstractType |
16 | 16 | { |
17 | - private $allOfItems = []; |
|
18 | - private $mostRecentItem; |
|
17 | + private $allOfItems = []; |
|
18 | + private $mostRecentItem; |
|
19 | 19 | |
20 | - public function toArray(): array |
|
21 | - { |
|
22 | - $allOf = []; |
|
23 | - foreach ($this->allOfItems as $item) { |
|
24 | - $allOf[] = $item->toArray(); |
|
25 | - } |
|
26 | - return self::arrayFilterNull(array_merge(array( |
|
27 | - 'allOf' => $allOf, |
|
28 | - ), parent::toArray())); |
|
29 | - } |
|
20 | + public function toArray(): array |
|
21 | + { |
|
22 | + $allOf = []; |
|
23 | + foreach ($this->allOfItems as $item) { |
|
24 | + $allOf[] = $item->toArray(); |
|
25 | + } |
|
26 | + return self::arrayFilterNull(array_merge(array( |
|
27 | + 'allOf' => $allOf, |
|
28 | + ), parent::toArray())); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @throws Exception |
|
33 | - */ |
|
34 | - protected function parseDefinition($definition) |
|
35 | - { |
|
36 | - $pattern = self::REGEX_START . 'allof' . self::REGEX_CONTENT . self::REGEX_END; |
|
37 | - $inlineDef = ''; |
|
38 | - if (preg_match($pattern, $definition, $matches) |
|
39 | - && isset($matches[1])) { |
|
40 | - $inlineDef = $matches[1]; |
|
41 | - } |
|
42 | - if ($inlineDef) { |
|
43 | - foreach (self::parseList($inlineDef) as $item) { |
|
44 | - $this->handleCommand('item', $item); |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
31 | + /** |
|
32 | + * @throws Exception |
|
33 | + */ |
|
34 | + protected function parseDefinition($definition) |
|
35 | + { |
|
36 | + $pattern = self::REGEX_START . 'allof' . self::REGEX_CONTENT . self::REGEX_END; |
|
37 | + $inlineDef = ''; |
|
38 | + if (preg_match($pattern, $definition, $matches) |
|
39 | + && isset($matches[1])) { |
|
40 | + $inlineDef = $matches[1]; |
|
41 | + } |
|
42 | + if ($inlineDef) { |
|
43 | + foreach (self::parseList($inlineDef) as $item) { |
|
44 | + $this->handleCommand('item', $item); |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - public function handleCommand($command, $data = null) |
|
53 | - { |
|
54 | - if (strtolower($command) === 'item') { |
|
55 | - $this->mostRecentItem = self::typeFactory($this, $data); |
|
56 | - $this->allOfItems[] = $this->mostRecentItem; |
|
57 | - return $this; |
|
58 | - } |
|
59 | - if (isset($this->mostRecentItem) |
|
60 | - && $this->mostRecentItem->handleCommand($command, $data)) { |
|
61 | - return $this; |
|
62 | - } |
|
63 | - return parent::handleCommand($command, $data); |
|
64 | - } |
|
49 | + /** |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + public function handleCommand($command, $data = null) |
|
53 | + { |
|
54 | + if (strtolower($command) === 'item') { |
|
55 | + $this->mostRecentItem = self::typeFactory($this, $data); |
|
56 | + $this->allOfItems[] = $this->mostRecentItem; |
|
57 | + return $this; |
|
58 | + } |
|
59 | + if (isset($this->mostRecentItem) |
|
60 | + && $this->mostRecentItem->handleCommand($command, $data)) { |
|
61 | + return $this; |
|
62 | + } |
|
63 | + return parent::handleCommand($command, $data); |
|
64 | + } |
|
65 | 65 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | class EmailType extends StringType implements ICustomType |
18 | 18 | { |
19 | 19 | |
20 | - const PATTERN = '\A[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z'; |
|
21 | - |
|
22 | - /** |
|
23 | - * List of formats recognized by this class |
|
24 | - * @var string[] |
|
25 | - */ |
|
26 | - private static $formats = array('email'); |
|
27 | - |
|
28 | - /** |
|
29 | - * Construct and set up the regular expression for this type |
|
30 | - * |
|
31 | - * @param AbstractObject $parent |
|
32 | - * @param string $definition |
|
33 | - */ |
|
34 | - public function __construct(AbstractObject $parent, $definition) |
|
35 | - { |
|
36 | - $this->pattern = self::PATTERN; |
|
37 | - |
|
38 | - parent::__construct($parent, $definition); |
|
39 | - } |
|
40 | - |
|
41 | - public static function getFormats() |
|
42 | - { |
|
43 | - return self::$formats; |
|
44 | - } |
|
45 | - |
|
46 | - public static function setFormats(array $formats) |
|
47 | - { |
|
48 | - self::$formats = $formats; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Parse a type definition string, assuming it belongs to this type |
|
53 | - * |
|
54 | - * @param string $definition |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - protected function parseDefinition($definition) |
|
58 | - { |
|
59 | - $definition = self::trim($definition); |
|
60 | - |
|
61 | - $match = []; |
|
62 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | - throw new Exception("Unparseable email definition: '{$definition}'"); |
|
64 | - } |
|
65 | - |
|
66 | - if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | - throw new Exception("Not an email: '{$definition}'"); |
|
68 | - } |
|
69 | - |
|
70 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check (and optionally reformat) a default value |
|
75 | - * |
|
76 | - * @param string $value |
|
77 | - * @return string |
|
78 | - * @throws Exception |
|
79 | - */ |
|
80 | - protected function validateDefault($value) |
|
81 | - { |
|
82 | - if (empty($value)) { |
|
83 | - throw new Exception("Empty email default"); |
|
84 | - } |
|
85 | - |
|
86 | - if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) { |
|
87 | - throw new Exception("Invalid email default value: '{$value}'"); |
|
88 | - } |
|
89 | - |
|
90 | - return $value; |
|
91 | - } |
|
20 | + const PATTERN = '\A[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z'; |
|
21 | + |
|
22 | + /** |
|
23 | + * List of formats recognized by this class |
|
24 | + * @var string[] |
|
25 | + */ |
|
26 | + private static $formats = array('email'); |
|
27 | + |
|
28 | + /** |
|
29 | + * Construct and set up the regular expression for this type |
|
30 | + * |
|
31 | + * @param AbstractObject $parent |
|
32 | + * @param string $definition |
|
33 | + */ |
|
34 | + public function __construct(AbstractObject $parent, $definition) |
|
35 | + { |
|
36 | + $this->pattern = self::PATTERN; |
|
37 | + |
|
38 | + parent::__construct($parent, $definition); |
|
39 | + } |
|
40 | + |
|
41 | + public static function getFormats() |
|
42 | + { |
|
43 | + return self::$formats; |
|
44 | + } |
|
45 | + |
|
46 | + public static function setFormats(array $formats) |
|
47 | + { |
|
48 | + self::$formats = $formats; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Parse a type definition string, assuming it belongs to this type |
|
53 | + * |
|
54 | + * @param string $definition |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + protected function parseDefinition($definition) |
|
58 | + { |
|
59 | + $definition = self::trim($definition); |
|
60 | + |
|
61 | + $match = []; |
|
62 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | + throw new Exception("Unparseable email definition: '{$definition}'"); |
|
64 | + } |
|
65 | + |
|
66 | + if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | + throw new Exception("Not an email: '{$definition}'"); |
|
68 | + } |
|
69 | + |
|
70 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check (and optionally reformat) a default value |
|
75 | + * |
|
76 | + * @param string $value |
|
77 | + * @return string |
|
78 | + * @throws Exception |
|
79 | + */ |
|
80 | + protected function validateDefault($value) |
|
81 | + { |
|
82 | + if (empty($value)) { |
|
83 | + throw new Exception("Empty email default"); |
|
84 | + } |
|
85 | + |
|
86 | + if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) { |
|
87 | + throw new Exception("Invalid email default value: '{$value}'"); |
|
88 | + } |
|
89 | + |
|
90 | + return $value; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | class MacType extends StringType implements ICustomType |
18 | 18 | { |
19 | 19 | |
20 | - const PATTERN = '^([0-9A-F]){2}(:[0-9A-F]{2}){5}$'; |
|
21 | - |
|
22 | - /** |
|
23 | - * List of formats recognized by this class |
|
24 | - * @var string[] |
|
25 | - */ |
|
26 | - private static $formats = array('mac'); |
|
27 | - |
|
28 | - /** |
|
29 | - * Construct and set up the regular expression for this type |
|
30 | - * |
|
31 | - * @param AbstractObject $parent |
|
32 | - * @param string $definition |
|
33 | - */ |
|
34 | - public function __construct(AbstractObject $parent, $definition) |
|
35 | - { |
|
36 | - $this->pattern = self::PATTERN; |
|
37 | - |
|
38 | - parent::__construct($parent, $definition); |
|
39 | - } |
|
40 | - |
|
41 | - public static function getFormats() |
|
42 | - { |
|
43 | - return self::$formats; |
|
44 | - } |
|
45 | - |
|
46 | - public static function setFormats(array $formats) |
|
47 | - { |
|
48 | - self::$formats = $formats; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Parse a type definition string, assuming it belongs to this type |
|
53 | - * |
|
54 | - * @param string $definition |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - protected function parseDefinition($definition) |
|
58 | - { |
|
59 | - $definition = self::trim($definition); |
|
60 | - |
|
61 | - $match = []; |
|
62 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | - throw new Exception("Unparseable MAC definition: '{$definition}'"); |
|
64 | - } |
|
65 | - |
|
66 | - if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | - throw new Exception("Not a MAC: '{$definition}'"); |
|
68 | - } |
|
69 | - |
|
70 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check (and optionally reformat) a default value |
|
75 | - * |
|
76 | - * @param string $value |
|
77 | - * @return string |
|
78 | - * @throws Exception |
|
79 | - */ |
|
80 | - protected function validateDefault($value) |
|
81 | - { |
|
82 | - if (empty($value)) { |
|
83 | - throw new Exception("Empty MAC default"); |
|
84 | - } |
|
85 | - |
|
86 | - if (preg_match('/^([0-9A-F]){2}(:[0-9A-F]{2}){5}$/', $value) !== 1) { |
|
87 | - throw new Exception("Invalid MAC default value: '{$value}'"); |
|
88 | - } |
|
89 | - |
|
90 | - return $value; |
|
91 | - } |
|
20 | + const PATTERN = '^([0-9A-F]){2}(:[0-9A-F]{2}){5}$'; |
|
21 | + |
|
22 | + /** |
|
23 | + * List of formats recognized by this class |
|
24 | + * @var string[] |
|
25 | + */ |
|
26 | + private static $formats = array('mac'); |
|
27 | + |
|
28 | + /** |
|
29 | + * Construct and set up the regular expression for this type |
|
30 | + * |
|
31 | + * @param AbstractObject $parent |
|
32 | + * @param string $definition |
|
33 | + */ |
|
34 | + public function __construct(AbstractObject $parent, $definition) |
|
35 | + { |
|
36 | + $this->pattern = self::PATTERN; |
|
37 | + |
|
38 | + parent::__construct($parent, $definition); |
|
39 | + } |
|
40 | + |
|
41 | + public static function getFormats() |
|
42 | + { |
|
43 | + return self::$formats; |
|
44 | + } |
|
45 | + |
|
46 | + public static function setFormats(array $formats) |
|
47 | + { |
|
48 | + self::$formats = $formats; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Parse a type definition string, assuming it belongs to this type |
|
53 | + * |
|
54 | + * @param string $definition |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + protected function parseDefinition($definition) |
|
58 | + { |
|
59 | + $definition = self::trim($definition); |
|
60 | + |
|
61 | + $match = []; |
|
62 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | + throw new Exception("Unparseable MAC definition: '{$definition}'"); |
|
64 | + } |
|
65 | + |
|
66 | + if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | + throw new Exception("Not a MAC: '{$definition}'"); |
|
68 | + } |
|
69 | + |
|
70 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check (and optionally reformat) a default value |
|
75 | + * |
|
76 | + * @param string $value |
|
77 | + * @return string |
|
78 | + * @throws Exception |
|
79 | + */ |
|
80 | + protected function validateDefault($value) |
|
81 | + { |
|
82 | + if (empty($value)) { |
|
83 | + throw new Exception("Empty MAC default"); |
|
84 | + } |
|
85 | + |
|
86 | + if (preg_match('/^([0-9A-F]){2}(:[0-9A-F]{2}){5}$/', $value) !== 1) { |
|
87 | + throw new Exception("Invalid MAC default value: '{$value}'"); |
|
88 | + } |
|
89 | + |
|
90 | + return $value; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | class Ipv6Type extends StringType implements ICustomType |
18 | 18 | { |
19 | 19 | |
20 | - const PATTERN = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
21 | - |
|
22 | - /** |
|
23 | - * List of formats recognized by this class |
|
24 | - * @var string[] |
|
25 | - */ |
|
26 | - private static $formats = array('ipv6'); |
|
27 | - |
|
28 | - /** |
|
29 | - * Construct and set up the regular expression for this type |
|
30 | - * |
|
31 | - * @param AbstractObject $parent |
|
32 | - * @param string $definition |
|
33 | - */ |
|
34 | - public function __construct(AbstractObject $parent, $definition) |
|
35 | - { |
|
36 | - $this->pattern = self::PATTERN; |
|
37 | - |
|
38 | - parent::__construct($parent, $definition); |
|
39 | - } |
|
40 | - |
|
41 | - public static function getFormats() |
|
42 | - { |
|
43 | - return self::$formats; |
|
44 | - } |
|
45 | - |
|
46 | - public static function setFormats(array $formats) |
|
47 | - { |
|
48 | - self::$formats = $formats; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Parse a type definition string, assuming it belongs to this type |
|
53 | - * |
|
54 | - * @param string $definition |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - protected function parseDefinition($definition) |
|
58 | - { |
|
59 | - $definition = self::trim($definition); |
|
60 | - |
|
61 | - $match = []; |
|
62 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | - throw new Exception("Unparseable IPv6 definition: '{$definition}'"); |
|
64 | - } |
|
65 | - |
|
66 | - if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | - throw new Exception("Not an IPv6: '{$definition}'"); |
|
68 | - } |
|
69 | - |
|
70 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check (and optionally reformat) a default value |
|
75 | - * |
|
76 | - * @param string $value |
|
77 | - * @return string |
|
78 | - * @throws Exception |
|
79 | - */ |
|
80 | - protected function validateDefault($value) |
|
81 | - { |
|
82 | - if (empty($value)) { |
|
83 | - throw new Exception("Empty IPv6 default"); |
|
84 | - } |
|
85 | - |
|
86 | - if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { |
|
87 | - throw new Exception("Invalid IPv6 default value: '{$value}'"); |
|
88 | - } |
|
89 | - |
|
90 | - return $value; |
|
91 | - } |
|
20 | + const PATTERN = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
21 | + |
|
22 | + /** |
|
23 | + * List of formats recognized by this class |
|
24 | + * @var string[] |
|
25 | + */ |
|
26 | + private static $formats = array('ipv6'); |
|
27 | + |
|
28 | + /** |
|
29 | + * Construct and set up the regular expression for this type |
|
30 | + * |
|
31 | + * @param AbstractObject $parent |
|
32 | + * @param string $definition |
|
33 | + */ |
|
34 | + public function __construct(AbstractObject $parent, $definition) |
|
35 | + { |
|
36 | + $this->pattern = self::PATTERN; |
|
37 | + |
|
38 | + parent::__construct($parent, $definition); |
|
39 | + } |
|
40 | + |
|
41 | + public static function getFormats() |
|
42 | + { |
|
43 | + return self::$formats; |
|
44 | + } |
|
45 | + |
|
46 | + public static function setFormats(array $formats) |
|
47 | + { |
|
48 | + self::$formats = $formats; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Parse a type definition string, assuming it belongs to this type |
|
53 | + * |
|
54 | + * @param string $definition |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + protected function parseDefinition($definition) |
|
58 | + { |
|
59 | + $definition = self::trim($definition); |
|
60 | + |
|
61 | + $match = []; |
|
62 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | + throw new Exception("Unparseable IPv6 definition: '{$definition}'"); |
|
64 | + } |
|
65 | + |
|
66 | + if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | + throw new Exception("Not an IPv6: '{$definition}'"); |
|
68 | + } |
|
69 | + |
|
70 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check (and optionally reformat) a default value |
|
75 | + * |
|
76 | + * @param string $value |
|
77 | + * @return string |
|
78 | + * @throws Exception |
|
79 | + */ |
|
80 | + protected function validateDefault($value) |
|
81 | + { |
|
82 | + if (empty($value)) { |
|
83 | + throw new Exception("Empty IPv6 default"); |
|
84 | + } |
|
85 | + |
|
86 | + if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { |
|
87 | + throw new Exception("Invalid IPv6 default value: '{$value}'"); |
|
88 | + } |
|
89 | + |
|
90 | + return $value; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -17,77 +17,77 @@ |
||
17 | 17 | class Ipv4Type extends StringType implements ICustomType |
18 | 18 | { |
19 | 19 | |
20 | - const PATTERN = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$'; |
|
21 | - |
|
22 | - /** |
|
23 | - * List of formats recognized by this class |
|
24 | - * @var string[] |
|
25 | - */ |
|
26 | - private static $formats = array('ipv4'); |
|
27 | - |
|
28 | - /** |
|
29 | - * Construct and set up the regular expression for this type |
|
30 | - * |
|
31 | - * @param AbstractObject $parent |
|
32 | - * @param string $definition |
|
33 | - */ |
|
34 | - public function __construct(AbstractObject $parent, $definition) |
|
35 | - { |
|
36 | - $this->pattern = self::PATTERN; |
|
37 | - |
|
38 | - parent::__construct($parent, $definition); |
|
39 | - } |
|
40 | - |
|
41 | - public static function getFormats() |
|
42 | - { |
|
43 | - return self::$formats; |
|
44 | - } |
|
45 | - |
|
46 | - public static function setFormats(array $formats) |
|
47 | - { |
|
48 | - self::$formats = $formats; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Parse a type definition string, assuming it belongs to this type |
|
53 | - * |
|
54 | - * @param string $definition |
|
55 | - * @throws Exception |
|
56 | - */ |
|
57 | - protected function parseDefinition($definition) |
|
58 | - { |
|
59 | - $definition = self::trim($definition); |
|
60 | - |
|
61 | - $match = []; |
|
62 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | - throw new Exception("Unparseable IPv4 definition: '{$definition}'"); |
|
64 | - } |
|
65 | - |
|
66 | - if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | - throw new Exception("Not an IPv4: '{$definition}'"); |
|
68 | - } |
|
69 | - |
|
70 | - $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check (and optionally reformat) a default value |
|
75 | - * |
|
76 | - * @param string $value |
|
77 | - * @return string |
|
78 | - * @throws Exception |
|
79 | - */ |
|
80 | - protected function validateDefault($value) |
|
81 | - { |
|
82 | - if (empty($value)) { |
|
83 | - throw new Exception("Empty IPv4 default"); |
|
84 | - } |
|
85 | - |
|
86 | - if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { |
|
87 | - throw new Exception("Invalid IPv4 default value: '{$value}'"); |
|
88 | - } |
|
89 | - |
|
90 | - return $value; |
|
91 | - } |
|
20 | + const PATTERN = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$'; |
|
21 | + |
|
22 | + /** |
|
23 | + * List of formats recognized by this class |
|
24 | + * @var string[] |
|
25 | + */ |
|
26 | + private static $formats = array('ipv4'); |
|
27 | + |
|
28 | + /** |
|
29 | + * Construct and set up the regular expression for this type |
|
30 | + * |
|
31 | + * @param AbstractObject $parent |
|
32 | + * @param string $definition |
|
33 | + */ |
|
34 | + public function __construct(AbstractObject $parent, $definition) |
|
35 | + { |
|
36 | + $this->pattern = self::PATTERN; |
|
37 | + |
|
38 | + parent::__construct($parent, $definition); |
|
39 | + } |
|
40 | + |
|
41 | + public static function getFormats() |
|
42 | + { |
|
43 | + return self::$formats; |
|
44 | + } |
|
45 | + |
|
46 | + public static function setFormats(array $formats) |
|
47 | + { |
|
48 | + self::$formats = $formats; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Parse a type definition string, assuming it belongs to this type |
|
53 | + * |
|
54 | + * @param string $definition |
|
55 | + * @throws Exception |
|
56 | + */ |
|
57 | + protected function parseDefinition($definition) |
|
58 | + { |
|
59 | + $definition = self::trim($definition); |
|
60 | + |
|
61 | + $match = []; |
|
62 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | + throw new Exception("Unparseable IPv4 definition: '{$definition}'"); |
|
64 | + } |
|
65 | + |
|
66 | + if (!in_array(strtolower($match[1]), self::$formats)) { |
|
67 | + throw new Exception("Not an IPv4: '{$definition}'"); |
|
68 | + } |
|
69 | + |
|
70 | + $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check (and optionally reformat) a default value |
|
75 | + * |
|
76 | + * @param string $value |
|
77 | + * @return string |
|
78 | + * @throws Exception |
|
79 | + */ |
|
80 | + protected function validateDefault($value) |
|
81 | + { |
|
82 | + if (empty($value)) { |
|
83 | + throw new Exception("Empty IPv4 default"); |
|
84 | + } |
|
85 | + |
|
86 | + if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { |
|
87 | + throw new Exception("Invalid IPv4 default value: '{$value}'"); |
|
88 | + } |
|
89 | + |
|
90 | + return $value; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -17,45 +17,45 @@ |
||
17 | 17 | class FileType extends AbstractType |
18 | 18 | { |
19 | 19 | |
20 | - public function toArray(): array |
|
21 | - { |
|
22 | - return self::arrayFilterNull(array_merge(array( |
|
23 | - 'type' => 'file', |
|
24 | - ), parent::toArray())); |
|
25 | - } |
|
26 | - |
|
27 | - public function __toString() |
|
28 | - { |
|
29 | - return __CLASS__; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @throws Exception |
|
34 | - */ |
|
35 | - protected function parseDefinition($definition) |
|
36 | - { |
|
37 | - $type = strtolower($definition); |
|
38 | - |
|
39 | - if ($type !== 'file') { |
|
40 | - throw new Exception("Not a file: '{$definition}'"); |
|
41 | - } |
|
42 | - |
|
43 | - $parent = $this->getParent(); |
|
44 | - if (!($parent instanceof Parameter) || !$parent->isForm()) { |
|
45 | - throw new Exception("File type '{$definition}' only allowed on form parameter"); |
|
46 | - } |
|
47 | - |
|
48 | - /** @var Operation $parentOperation */ |
|
49 | - $parentOperation = $this->getParentClass(Operation::class); |
|
50 | - $consumes = $parentOperation->getConsumes(); |
|
51 | - if (empty($consumes)) { |
|
52 | - $consumes = $this->getSwagger()->getConsumes(); |
|
53 | - } |
|
54 | - |
|
55 | - $valid_consumes = ((int)in_array('multipart/form-data', $consumes)) + ((int)in_array('application/x-www-form-urlencoded', $consumes)); |
|
56 | - if (empty($consumes) || $valid_consumes !== count($consumes)) { |
|
57 | - throw new Exception("File type '{$definition}' without valid consume"); |
|
58 | - } |
|
59 | - } |
|
20 | + public function toArray(): array |
|
21 | + { |
|
22 | + return self::arrayFilterNull(array_merge(array( |
|
23 | + 'type' => 'file', |
|
24 | + ), parent::toArray())); |
|
25 | + } |
|
26 | + |
|
27 | + public function __toString() |
|
28 | + { |
|
29 | + return __CLASS__; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @throws Exception |
|
34 | + */ |
|
35 | + protected function parseDefinition($definition) |
|
36 | + { |
|
37 | + $type = strtolower($definition); |
|
38 | + |
|
39 | + if ($type !== 'file') { |
|
40 | + throw new Exception("Not a file: '{$definition}'"); |
|
41 | + } |
|
42 | + |
|
43 | + $parent = $this->getParent(); |
|
44 | + if (!($parent instanceof Parameter) || !$parent->isForm()) { |
|
45 | + throw new Exception("File type '{$definition}' only allowed on form parameter"); |
|
46 | + } |
|
47 | + |
|
48 | + /** @var Operation $parentOperation */ |
|
49 | + $parentOperation = $this->getParentClass(Operation::class); |
|
50 | + $consumes = $parentOperation->getConsumes(); |
|
51 | + if (empty($consumes)) { |
|
52 | + $consumes = $this->getSwagger()->getConsumes(); |
|
53 | + } |
|
54 | + |
|
55 | + $valid_consumes = ((int)in_array('multipart/form-data', $consumes)) + ((int)in_array('application/x-www-form-urlencoded', $consumes)); |
|
56 | + if (empty($consumes) || $valid_consumes !== count($consumes)) { |
|
57 | + throw new Exception("File type '{$definition}' without valid consume"); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -15,61 +15,61 @@ |
||
15 | 15 | class BooleanType extends AbstractType |
16 | 16 | { |
17 | 17 | |
18 | - /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | - const REGEX_DEFAULT = '(?:=(true|false|1|0))?'; |
|
18 | + /** @noinspection PhpRegExpUnsupportedModifierInspection */ |
|
19 | + const REGEX_DEFAULT = '(?:=(true|false|1|0))?'; |
|
20 | 20 | |
21 | - private $default = null; |
|
21 | + private $default = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $command The comment command |
|
25 | - * @param string $data Any data added after the command |
|
26 | - * @return AbstractType|boolean |
|
27 | - * @throws Exception |
|
28 | - * @throws Exception |
|
29 | - */ |
|
30 | - public function handleCommand($command, $data = null) |
|
31 | - { |
|
32 | - if (strtolower($command) === 'default') { |
|
33 | - if (!in_array($data, array('0', '1', 'true', 'false'))) { |
|
34 | - throw new Exception("Invalid boolean default: '{$data}'"); |
|
35 | - } |
|
36 | - $this->default = ($data == '1') || (strtolower($data) === 'true'); |
|
37 | - return $this; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $command The comment command |
|
25 | + * @param string $data Any data added after the command |
|
26 | + * @return AbstractType|boolean |
|
27 | + * @throws Exception |
|
28 | + * @throws Exception |
|
29 | + */ |
|
30 | + public function handleCommand($command, $data = null) |
|
31 | + { |
|
32 | + if (strtolower($command) === 'default') { |
|
33 | + if (!in_array($data, array('0', '1', 'true', 'false'))) { |
|
34 | + throw new Exception("Invalid boolean default: '{$data}'"); |
|
35 | + } |
|
36 | + $this->default = ($data == '1') || (strtolower($data) === 'true'); |
|
37 | + return $this; |
|
38 | + } |
|
39 | 39 | |
40 | - return parent::handleCommand($command, $data); |
|
41 | - } |
|
40 | + return parent::handleCommand($command, $data); |
|
41 | + } |
|
42 | 42 | |
43 | - public function toArray(): array |
|
44 | - { |
|
45 | - return self::arrayFilterNull(array_merge(array( |
|
46 | - 'type' => 'boolean', |
|
47 | - 'default' => $this->default, |
|
48 | - ), parent::toArray())); |
|
49 | - } |
|
43 | + public function toArray(): array |
|
44 | + { |
|
45 | + return self::arrayFilterNull(array_merge(array( |
|
46 | + 'type' => 'boolean', |
|
47 | + 'default' => $this->default, |
|
48 | + ), parent::toArray())); |
|
49 | + } |
|
50 | 50 | |
51 | - public function __toString() |
|
52 | - { |
|
53 | - return __CLASS__; |
|
54 | - } |
|
51 | + public function __toString() |
|
52 | + { |
|
53 | + return __CLASS__; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @throws Exception |
|
58 | - */ |
|
59 | - protected function parseDefinition($definition) |
|
60 | - { |
|
61 | - $match = []; |
|
62 | - if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | - throw new Exception("Unparseable boolean definition: '{$definition}'"); |
|
64 | - } |
|
56 | + /** |
|
57 | + * @throws Exception |
|
58 | + */ |
|
59 | + protected function parseDefinition($definition) |
|
60 | + { |
|
61 | + $match = []; |
|
62 | + if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) { |
|
63 | + throw new Exception("Unparseable boolean definition: '{$definition}'"); |
|
64 | + } |
|
65 | 65 | |
66 | - if (strtolower($match[1]) !== 'boolean') { |
|
67 | - throw new Exception("Not a boolean: '{$definition}'"); |
|
68 | - } |
|
66 | + if (strtolower($match[1]) !== 'boolean') { |
|
67 | + throw new Exception("Not a boolean: '{$definition}'"); |
|
68 | + } |
|
69 | 69 | |
70 | - if (isset($match[2])) { |
|
71 | - $this->default = ($match[2] === '1') || (strtolower($match[2]) === 'true'); |
|
72 | - } |
|
73 | - } |
|
70 | + if (isset($match[2])) { |
|
71 | + $this->default = ($match[2] === '1') || (strtolower($match[2]) === 'true'); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |