/**
  * Determines and sets the Request format
  *
  * @param GetResponseEvent $event The event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     /*
             // TODO get priorities from the controller action
             $action = $request->attributes->get('_controller');
             $controller = $event->getController();
             $priorities =
     */
     if (empty($priorities)) {
         $priorities = $this->defaultPriorities;
     }
     $format = null;
     if (!empty($priorities)) {
         $format = $this->formatNegotiator->getBestFormat($request, $priorities, $this->preferExtension);
     }
     if (null === $format) {
         $format = $this->fallbackFormat;
     }
     if (null === $format) {
         if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
             throw new HttpException(Codes::HTTP_NOT_ACCEPTABLE, "No matching accepted Response format could be determined");
         }
         return;
     }
     $request->setRequestFormat($format);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function doKernelRequest(Request $request)
 {
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return null;
     }
     if (!$request->attributes->has('_format')) {
         $request->attributes->set('_format', $request->query->get('format'));
     }
     $acceptableFormats = (array) $route->getOption(RouteOptions::SUPPORTED_FORMATS);
     $bestFormat = $this->formatNegotiator->getBestFormat($request, $acceptableFormats, true);
     if (!$bestFormat) {
         return new Response('', 406);
     }
     $route->setOption(RouteOptions::ACCEPTED_FORMAT, $bestFormat);
     return null;
 }