public function setRequestFormat(Request $request, Application $app)
    {
        // If there is no Accept header, do nothing
        if (!$request->headers->get("Accept")) {
            return;
        }

        // Check the Accept header for acceptable formats
        foreach ($request->getAcceptableContentTypes() as $contentType) {
            // If any format is acceptable, do nothing
            if ($contentType === "*/*") {
                return;
            }

            $format = $request->getFormat($contentType);
            if (in_array($format, $app["conneg.responseFormats"])) {
                // An acceptable format was found.  Set it as the requestFormat
                // where it can be referenced later.
                $request->setRequestFormat($format);
                return;
            }
        }

        // No acceptable formats were found
        throw new NotAcceptableHttpException();
    }
public function setRequestFormat(Request $request, Application $app)
    {
        // If there is no Accept header, do nothing
        if (!$request->headers->get("Accept")) {
            return;
        }

        // Check the Accept header for acceptable formats
        foreach ($request->getAcceptableContentTypes() as $contentType) {
            // If any format is acceptable, do nothing
            if ($contentType === "*/*") {
                return;
            }

            $format = $request->getFormat($contentType);
            if (in_array($format, $app["conneg.responseFormats"])) {
                // An acceptable format was found.  Set it as the requestFormat
                // where it can be referenced later.
                $request->setRequestFormat($format);
                return;
            }
        }

        // No acceptable formats were found
        throw new NotAcceptableHttpException();
    }
public function setRequestFormat ( Request $ request , Application $ app ) { // If there is no Accept header, do nothing if ( ! $ request -> headers -> get ( "Accept" ) ) { return ; } // Check the Accept header for acceptable formats foreach ( $ request -> getAcceptableContentTypes ( ) as $ contentType ) { // If any format is acceptable, do nothing if ( $ contentType === "*/*" ) { return ; } $ format = $ request -> getFormat ( $ contentType ) ; if ( in_array ( $ format , $ app [ "conneg.responseFormats" ] ) ) { // An acceptable format was found.  Set it as the requestFormat // where it can be referenced later. $ request -> setRequestFormat ( $ format ) ; return ; } } // No acceptable formats were found throw new NotAcceptableHttpException ( ) ; }
This before middleware validates whether the application will be able to
respond in a format that the client understands.

@param Request $request
@throws NotAcceptableHttpException
This before middleware validates whether the application will be able to respond in a format that the client understands .