app = $app; } /** * {@inheritdoc} */ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE): Response { // Register available mime types. foreach ($this->formats as $format => $mime_type) { $request->setFormat($format, $mime_type); } // Determine the request format using the negotiator. if ($requested_format = $this->getContentType($request)) { $request->setRequestFormat($requested_format); } return $this->app->handle($request, $type, $catch); } /** * Registers a format for a given MIME type. * * @param string $format * The format. * @param string $mime_type * The MIME type. * * @return $this */ public function registerFormat($format, $mime_type) { $this->formats[$format] = $mime_type; return $this; } /** * Gets the normalized type of a request. * * The normalized type is a short, lowercase version of the format, such as * 'html', 'json' or 'atom'. * * @param \Symfony\Component\HttpFoundation\Request $request * The request object from which to extract the content type. * * @return string * The normalized type of a given request. */ protected function getContentType(Request $request) { // AJAX iframe uploads need special handling, because they contain a JSON // response wrapped in