public function handle(View $view, Request $request = null)
    {
        if (null === $request) {
            $request = $this->requestStack->getCurrentRequest();
        }

        $format = $view->getFormat() ?: $request->getRequestFormat();

        if (!$this->supports($format)) {
            $msg = "Format '$format' not supported, handler must be implemented";

            throw new UnsupportedMediaTypeHttpException($msg);
        }

        if (isset($this->customHandlers[$format])) {
            return call_user_func($this->customHandlers[$format], $this, $view, $request, $format);
        }

        return $this->createResponse($view, $request, $format);
    }
public function handle(View $view, Request $request = null)
    {
        if (null === $request) {
            $request = $this->requestStack->getCurrentRequest();
        }

        $format = $view->getFormat() ?: $request->getRequestFormat();

        if (!$this->supports($format)) {
            $msg = "Format '$format' not supported, handler must be implemented";

            throw new UnsupportedMediaTypeHttpException($msg);
        }

        if (isset($this->customHandlers[$format])) {
            return call_user_func($this->customHandlers[$format], $this, $view, $request, $format);
        }

        return $this->createResponse($view, $request, $format);
    }
public function handle ( View $ view , Request $ request = null ) { if ( null === $ request ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; } $ format = $ view -> getFormat ( ) ? : $ request -> getRequestFormat ( ) ; if ( ! $ this -> supports ( $ format ) ) { $ msg = "Format '$format' not supported, handler must be implemented" ; throw new UnsupportedMediaTypeHttpException ( $ msg ) ; } if ( isset ( $ this -> customHandlers [ $ format ] ) ) { return call_user_func ( $ this -> customHandlers [ $ format ] , $ this , $ view , $ request , $ format ) ; } return $ this -> createResponse ( $ view , $ request , $ format ) ; }
Handles a request with the proper handler.

Decides on which handler to use based on the request format.

@param View    $view
@param Request $request

@throws UnsupportedMediaTypeHttpException

@return Response
Handles a request with the proper handler .