Loads the view helpers and outputs the response in an appropriate format.
@param Response $response
771492
public function render(Response $response): void
    {
        $i = 0;
        foreach ($response->getViewHelpers() as $name => $view_helper) {
            if (is_a($view_helper, ViewHelperInterface::class)) {
                /** @var $view_helper ViewHelperInterface */
                if (null !== $view_helper->getParent() && !is_null($response->getViewHelper($view_helper->getParent()))) {
                    $parent = $response->getViewHelper($view_helper->getParent());
                    if (is_a($parent, ViewHelperCollection::class)) {
                        /** @var $parent ViewHelperCollection */
                        $parent->append($name, $view_helper);
                    }
                }
            }
        }
    }
61316
public function prepareForResponse(Response $response) {
		$response->setHeader('Content-Type: ' . $this->getContentType());

		if (!$this->isInitialized()) {
			$this->initialize();
		}
	}
1243104
protected function parseLookupResponse(Response $response)
    {
        $responseData = $response->getBody();
        $responseObject = json_decode($responseData);
        $definitionsData = $responseObject->def;
        $definitions = [];
        foreach ($definitionsData as $definitionData) {
            $definitions[] = new DictionaryDefinition($definitionData);
        }
        return $definitions;
    }
502320
private function performResponse($response)
    {
        $data = false;
        if ($response instanceof ResponseInterface) {
            $data = json_decode($response->getBody()->getContents());
            $this->getValidationResponse()->validateResponseData($data);
        }

        return $data;
    }
211352
public function injectDebugbar(Response $response)
    {
        $content = $response->getContent();

        $renderer = $this->getJavascriptRenderer();

        $openHandlerUrl = $this->di['url']->getStatic( array('for'=>'debugbar.openhandler') );
        $renderer->setOpenHandlerUrl($openHandlerUrl);


        $renderedContent = $renderer->renderHead() . $renderer->render();

        $pos = strripos($content, '</body>');
        if (false !== $pos) {
            $content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
        } else {
            $content = $content . $renderedContent;
        }

        $response->setContent($content);
    }
1006395
protected function getResponseData(Response $response)
    {
        if ($response instanceof JsonResponse) {
            /** @var $response JsonResponse */
            return $response->getData(true) ?: [];
        }

        $content = $response->getContent();

        return json_decode($content, true) ?: false;
    }
845289
protected function prepareResponse($response)
    {
        if ($response instanceof HTTPResponse) {
            if (isset($_REQUEST['debug_request'])) {
                $class = static::class;
                Debug::message(
                    "Request handler returned HTTPResponse object to {$class} controller;"
                    . "returning it without modification."
                );
            }
            $this->setResponse($response);
        } else {
            // Could be Controller, or ViewableData_Customised controller wrapper
            if (ClassInfo::hasMethod($response, 'getViewer')) {
                if (isset($_REQUEST['debug_request'])) {
                    $class = static::class;
                    $responseClass = get_class($response);
                    Debug::message(
                        "Request handler {$responseClass} object to {$class} controller;"
                        . "rendering with template returned by {$responseClass}::getViewer()"
                    );
                }
                $response = $response->getViewer($this->getAction())->process($response);
            }

            $this->getResponse()->setBody($response);
        }

        //deal with content if appropriate
        ContentNegotiator::process($this->getResponse());
    }
627345
public function output($response)
    {
        // Set format
        switch ($this->format) {
            case 'json':
                $response = array_merge_recursive($response, $this->extra);
                $this->header('Content-type: application/json; charset=utf-8');
                $response = json_encode($response);

                // Replace string numbers for integers
                $response = preg_replace('/(")([0-9]+)(")/is', '\\2', $response);
                break;
            case 'html':
                $this->header('Content-type: text/html; charset=utf-8');
                $response = $this->html($response);
                break;
        }

        // Set cookies
        foreach ($this->cookies as $key => $value) {
            setcookie($key, $value, time() + 3600, '/');
        }

        // Set headers
        foreach ($this->headers as $header) {
            header($header);
        }

        // Return response
        echo $response;
        exit;
    }
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }
107399
protected function jsonActionResponse(Response $response): ServiceResponse
    {
        // get the frontendData set by the Frontend plugin and remove unnecessary data
        $frontendData = $this->viewVars['frontendData'];
        unset($frontendData['Types']);
        $response = [
            'code' => 'success',
            'data' => [
                'frontendData' => $frontendData,
                'html' => $response->body(),
                'closeDialog' => $this->viewVars['closeDialog']
            ]
        ];

        return new ServiceResponse($response);
    }
639139
public function render($view, array $parameters = array(), Response $response = null)
    {
        if (null === $response) {
            $response = new Response();
        }

        // locate the full path to the view
        $matches = null;
        preg_match("/Bundle\\\([a-zA-Z0-9]+Bundle)\\\/i", get_class($this), $matches);
        if (isset($matches[1])) {
            $bundleName = $matches[1];

            // check that the view is not the full path already
            $matchesView = null;
            preg_match("/Bundle\\\\([a-zA-Z0-9]+Bundle)\\\\/i", $view, $matchesView);

            if (!isset($matchesView[1])) {
                // view is not the full path, so prepend the bundle views dir
                $bundle = $this->getApplication()->getBundle($bundleName);
                $bundle->getBaseDir();
                $view = $bundle->getBaseDir().'/Ressources/views/'.$view;
            }
        } else {
            $view = $this->getApplication()->getBBDir().'/Resources/views/'.$view;
        }

        try {
            $this->renderer = $this->getApplication()->getRenderer();
            $content = $this->renderer->partial($view, $parameters);
            $response->setContent($content);
        } catch (\Exception $e) {
            throw $e;
        }

        return $response;
    }
482888
public function loadResponseBody()
    {
        if (array_key_exists('php://output', $this->mockedData)) {
            $this->loadBodyByContent($this->getResponseHeader(), $this->mockedData['php://output']);
        }
        else {
            $this->loadBodyByContent($this->getResponseHeader(), file_get_contents("php://output"));
        }
    }
1043781
public function prepareForResponse(Response $response) {
	    if ('application/json' == $response->getRequest()->getAcceptRange()
	               ->bestMatch(['text/html', 'application/json'])) {
	        $this->jhtmlJsonPayload = new JhtmlJsonPayload($this->additionalAttrs);
	        $this->jhtmlJsonPayload->applyView($this->htmlView);
	        $this->jhtmlJsonPayload->prepareForResponse($response);
	        return;
	    }
	    
	    $this->jhtmlJsonPayload = null;
	    $this->htmlView->prepareForResponse($response);
	}
386694
public function View ()
	{
		
		// If the view is JSON
		
		if ($this->view instanceof \Sonic\View\JSON)
		{
			
			// Display view

			$response = $this->view->display ();
			
		}
		
		// Else call parent method
		
		else
		{
			parent::View ();
		}
		
	}
1220105
private function handleStream($response)
    {
        try {
            foreach ($response->readAll() as $count => $result) {
                $res = $this->serializer->encodeMessage($result);
                yield $res;
            }
        } catch (\Exception $ex) {
            throw $this->convertToGoogleException($ex);
        }
    }
67382
public function processResponse(ResponseInterface $response)
    {
        if (!$response instanceof Response
            || !$this->getRequest()
        ) {
            return;
        }

        $response = $this->handleResponse($response);
        $this->renderResponse($response);
        $this->terminateApp();
    }
843939
public function format($response)
    {
        if (stripos($this->contentType, 'charset') === false) {
            $this->contentType .= '; charset=' . $response->encoding;
        }
        $response->setHeader('Content-Type', $this->contentType);
        if ($response->data !== null) {
            $response->content = $response->data;
        }
    }