public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
            return;
        }

        try {
            $format = $request->getRequestFormat(null);
            if (null === $format) {
                $accept = $this->formatNegotiator->getBest('');
                if (null !== $accept && 0.0 < $accept->getQuality()) {
                    $format = $request->getFormat($accept->getValue());
                    if (null !== $format) {
                        $request->attributes->set('media_type', $accept->getValue());
                    }
                }
            }

            if (null === $format) {
                if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
                    throw new NotAcceptableHttpException('No matching accepted Response format could be determined');
                }

                return;
            }

            $request->setRequestFormat($format);
        } catch (StopFormatListenerException $e) {
            // nothing to do
        }
    }
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
            return;
        }

        try {
            $format = $request->getRequestFormat(null);
            if (null === $format) {
                $accept = $this->formatNegotiator->getBest('');
                if (null !== $accept && 0.0 < $accept->getQuality()) {
                    $format = $request->getFormat($accept->getValue());
                    if (null !== $format) {
                        $request->attributes->set('media_type', $accept->getValue());
                    }
                }
            }

            if (null === $format) {
                if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
                    throw new NotAcceptableHttpException('No matching accepted Response format could be determined');
                }

                return;
            }

            $request->setRequestFormat($format);
        } catch (StopFormatListenerException $e) {
            // nothing to do
        }
    }
public function onKernelRequest ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( ! $ request -> attributes -> get ( FOSRestBundle :: ZONE_ATTRIBUTE , true ) ) { return ; } try { $ format = $ request -> getRequestFormat ( null ) ; if ( null === $ format ) { $ accept = $ this -> formatNegotiator -> getBest ( '' ) ; if ( null !== $ accept && 0.0 < $ accept -> getQuality ( ) ) { $ format = $ request -> getFormat ( $ accept -> getValue ( ) ) ; if ( null !== $ format ) { $ request -> attributes -> set ( 'media_type' , $ accept -> getValue ( ) ) ; } } } if ( null === $ format ) { if ( HttpKernelInterface :: MASTER_REQUEST === $ event -> getRequestType ( ) ) { throw new NotAcceptableHttpException ( 'No matching accepted Response format could be determined' ) ; } return ; } $ request -> setRequestFormat ( $ format ) ; } catch ( StopFormatListenerException $ e ) { // nothing to do } }
Determines and sets the Request format.

@param GetResponseEvent $event The event

@throws NotAcceptableHttpException
Determines and sets the Request format .