|
16 | 16 | * |
17 | 17 | * API for the Catrobat Share Platform |
18 | 18 | * |
19 | | - * The version of the OpenAPI document: v1.0.39 |
| 19 | + * The version of the OpenAPI document: v1.0.40 |
20 | 20 | * Contact: webmaster@catrobat.org |
21 | 21 | * Generated by: https://github.com/openapitools/openapi-generator.git |
22 | 22 | */ |
|
32 | 32 | use OpenAPI\Server\Service\SerializerInterface; |
33 | 33 | use OpenAPI\Server\Service\ValidatorInterface; |
34 | 34 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 35 | +use Symfony\Component\HttpFoundation\Request; |
35 | 36 | use Symfony\Component\HttpFoundation\Response; |
36 | 37 | use Symfony\Component\HttpKernel\Exception\HttpException; |
37 | 38 |
|
@@ -97,6 +98,47 @@ public function createErrorResponse(HttpException $exception) |
97 | 98 | return new Response(json_encode($json, 15, 512), $statusCode, $headers); |
98 | 99 | } |
99 | 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 | + |
100 | 142 | /** |
101 | 143 | * Serializes data to a given type format. |
102 | 144 | * |
|
0 commit comments