private function initResponse(View $view, $format)
    {
        $content = null;
        if ($this->isFormatTemplating($format)) {
            $content = $this->renderTemplate($view, $format);
        } elseif ($this->serializeNull || null !== $view->getData()) {
            $data = $this->getDataFromView($view);

            if ($data instanceof FormInterface && $data->isSubmitted() && !$data->isValid()) {
                $view->getContext()->setAttribute('status_code', $this->failedValidationCode);
            }

            $context = $this->getSerializationContext($view);
            $context->setAttribute('template_data', $view->getTemplateData());

            $content = $this->serializer->serialize($data, $format, $context);
        }

        $response = $view->getResponse();
        $response->setStatusCode($this->getStatusCode($view, $content));

        if (null !== $content) {
            $response->setContent($content);
        }

        return $response;
    }
private function initResponse(View $view, $format)
    {
        $content = null;
        if ($this->isFormatTemplating($format)) {
            $content = $this->renderTemplate($view, $format);
        } elseif ($this->serializeNull || null !== $view->getData()) {
            $data = $this->getDataFromView($view);

            if ($data instanceof FormInterface && $data->isSubmitted() && !$data->isValid()) {
                $view->getContext()->setAttribute('status_code', $this->failedValidationCode);
            }

            $context = $this->getSerializationContext($view);
            $context->setAttribute('template_data', $view->getTemplateData());

            $content = $this->serializer->serialize($data, $format, $context);
        }

        $response = $view->getResponse();
        $response->setStatusCode($this->getStatusCode($view, $content));

        if (null !== $content) {
            $response->setContent($content);
        }

        return $response;
    }
private function initResponse ( View $ view , $ format ) { $ content = null ; if ( $ this -> isFormatTemplating ( $ format ) ) { $ content = $ this -> renderTemplate ( $ view , $ format ) ; } elseif ( $ this -> serializeNull || null !== $ view -> getData ( ) ) { $ data = $ this -> getDataFromView ( $ view ) ; if ( $ data instanceof FormInterface && $ data -> isSubmitted ( ) && ! $ data -> isValid ( ) ) { $ view -> getContext ( ) -> setAttribute ( 'status_code' , $ this -> failedValidationCode ) ; } $ context = $ this -> getSerializationContext ( $ view ) ; $ context -> setAttribute ( 'template_data' , $ view -> getTemplateData ( ) ) ; $ content = $ this -> serializer -> serialize ( $ data , $ format , $ context ) ; } $ response = $ view -> getResponse ( ) ; $ response -> setStatusCode ( $ this -> getStatusCode ( $ view , $ content ) ) ; if ( null !== $ content ) { $ response -> setContent ( $ content ) ; } return $ response ; }
Initializes a response object that represents the view and holds the view's status code.

@param View   $view
@param string $format

@return Response
Initializes a response object that represents the view and holds the view s status code .