|
16 | 16 | * |
17 | 17 | * API for the Catrobat Share Platform |
18 | 18 | * |
19 | | - * The version of the OpenAPI document: v1.0.52 |
| 19 | + * The version of the OpenAPI document: v1.0.53 |
20 | 20 | * Contact: webmaster@catrobat.org |
21 | 21 | * Generated by: https://github.com/openapitools/openapi-generator.git |
22 | 22 | */ |
@@ -98,47 +98,6 @@ public function createErrorResponse(HttpException $exception) |
98 | 98 | return new Response(json_encode($json, 15, 512), $statusCode, $headers); |
99 | 99 | } |
100 | 100 |
|
101 | | - /** |
102 | | - * Checks whether Content-Type request header presented in supported formats. |
103 | | - * |
104 | | - * @param Request $request request instance |
105 | | - * @param array $consumes array of supported content types |
106 | | - * |
107 | | - * @return bool returns true if Content-Type supported otherwise false |
108 | | - */ |
109 | | - public static function isContentTypeAllowed(Request $request, array $consumes = []) |
110 | | - { |
111 | | - if (!empty($consumes) && '*/*' !== $consumes[0]) |
112 | | - { |
113 | | - $currentFormat = $request->getContentType(); |
114 | | - foreach ($consumes as $mimeType) |
115 | | - { |
116 | | - // canonize mime type |
117 | | - if (is_string($mimeType) && false !== $pos = strpos($mimeType, ';')) |
118 | | - { |
119 | | - $mimeType = trim(substr($mimeType, 0, $pos)); |
120 | | - } |
121 | | - |
122 | | - if (!$format = $request->getFormat($mimeType)) |
123 | | - { |
124 | | - // add custom format to request |
125 | | - $format = $mimeType; |
126 | | - $request->setFormat($format, $format); |
127 | | - $currentFormat = $request->getContentType(); |
128 | | - } |
129 | | - |
130 | | - if ($format === $currentFormat) |
131 | | - { |
132 | | - return true; |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - return false; |
137 | | - } |
138 | | - |
139 | | - return true; |
140 | | - } |
141 | | - |
142 | 101 | /** |
143 | 102 | * Serializes data to a given type format. |
144 | 103 | * |
@@ -179,6 +138,32 @@ protected function validate($data, $asserts = null) |
179 | 138 | } |
180 | 139 | } |
181 | 140 |
|
| 141 | + /** |
| 142 | + * Converts an exception to a serializable array. |
| 143 | + * |
| 144 | + * @return array |
| 145 | + */ |
| 146 | + private function exceptionToArray(\Exception $exception = null) |
| 147 | + { |
| 148 | + if (null === $exception) |
| 149 | + { |
| 150 | + return null; |
| 151 | + } |
| 152 | + |
| 153 | + if (!$this->container->get('kernel')->isDebug()) |
| 154 | + { |
| 155 | + return [ |
| 156 | + 'message' => $exception->getMessage(), |
| 157 | + ]; |
| 158 | + } |
| 159 | + |
| 160 | + return [ |
| 161 | + 'message' => $exception->getMessage(), |
| 162 | + 'type' => get_class($exception), |
| 163 | + 'previous' => $this->exceptionToArray($exception->getPrevious()), |
| 164 | + ]; |
| 165 | + } |
| 166 | + |
182 | 167 | protected function getOutputFormat($accept, array $produced) |
183 | 168 | { |
184 | 169 | // Figure out what the client accepts |
@@ -212,28 +197,43 @@ protected function getOutputFormat($accept, array $produced) |
212 | 197 | } |
213 | 198 |
|
214 | 199 | /** |
215 | | - * Converts an exception to a serializable array. |
| 200 | + * Checks whether Content-Type request header presented in supported formats. |
216 | 201 | * |
217 | | - * @return array |
| 202 | + * @param Request $request request instance |
| 203 | + * @param array $consumes array of supported content types |
| 204 | + * |
| 205 | + * @return bool returns true if Content-Type supported otherwise false |
218 | 206 | */ |
219 | | - private function exceptionToArray(\Exception $exception = null) |
| 207 | + public static function isContentTypeAllowed(Request $request, array $consumes = []) |
220 | 208 | { |
221 | | - if (null === $exception) |
| 209 | + if (!empty($consumes) && '*/*' !== $consumes[0]) |
222 | 210 | { |
223 | | - return null; |
224 | | - } |
| 211 | + $currentFormat = $request->getContentType(); |
| 212 | + foreach ($consumes as $mimeType) |
| 213 | + { |
| 214 | + // canonize mime type |
| 215 | + if (is_string($mimeType) && false !== $pos = strpos($mimeType, ';')) |
| 216 | + { |
| 217 | + $mimeType = trim(substr($mimeType, 0, $pos)); |
| 218 | + } |
225 | 219 |
|
226 | | - if (!$this->container->get('kernel')->isDebug()) |
227 | | - { |
228 | | - return [ |
229 | | - 'message' => $exception->getMessage(), |
230 | | - ]; |
| 220 | + if (!$format = $request->getFormat($mimeType)) |
| 221 | + { |
| 222 | + // add custom format to request |
| 223 | + $format = $mimeType; |
| 224 | + $request->setFormat($format, $format); |
| 225 | + $currentFormat = $request->getContentType(); |
| 226 | + } |
| 227 | + |
| 228 | + if ($format === $currentFormat) |
| 229 | + { |
| 230 | + return true; |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + return false; |
231 | 235 | } |
232 | 236 |
|
233 | | - return [ |
234 | | - 'message' => $exception->getMessage(), |
235 | | - 'type' => get_class($exception), |
236 | | - 'previous' => $this->exceptionToArray($exception->getPrevious()), |
237 | | - ]; |
| 237 | + return true; |
238 | 238 | } |
239 | 239 | } |
0 commit comments