/**
  * 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);
 }
 /**
  * Determines and sets the Request format
  *
  * @param GetResponseEvent $event The event
  *
  * @throws HttpException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $format = $this->formatNegotiator->getBestFormat($request);
     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);
 }
Example #3
0
 /**
  * Determines and sets the Request format
  *
  * @param GetResponseEvent $event The event
  *
  * @throws NotAcceptableHttpException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $format = null;
     if ($this->formatNegotiator instanceof MediaTypeNegotiatorInterface) {
         $mediaType = $this->formatNegotiator->getBestMediaType($request);
         if ($mediaType) {
             $request->attributes->set('media_type', $mediaType);
             $format = $request->getFormat($mediaType);
         }
     } else {
         $format = $this->formatNegotiator->getBestFormat($request);
     }
     if (null === $format) {
         if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
             throw new NotAcceptableHttpException("No matching accepted Response format could be determined");
         }
         return;
     }
     $request->setRequestFormat($format);
 }