Snowair\Debugbar\PhalconDebugbar::modifyResponse PHP Method

modifyResponse() public method

public modifyResponse ( Phalcon\Http\Response $response ) : mixed
$response Phalcon\Http\Response
return mixed
    public function modifyResponse($response)
    {
        $request = $this->di['request'];
        $config = $this->config;
        if (!$this->isEnabled()) {
            return $response;
        }
        if ($this->shouldCollect('config', false) && $this->di->has('config')) {
            try {
                $config_data = $this->di['config']->toArray();
                $protect = $config->options->config->get('protect');
                $configCollector = new ConfigCollector($config_data);
                $configCollector->setProtect($protect);
                $this->addCollector($configCollector);
            } catch (\Exception $e) {
                $this->addException(new Exception('Cannot add ConfigCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
            }
        }
        if ($this->shouldCollect('session') && $this->di->has('session')) {
            try {
                $this->addCollector(new SessionCollector($this->di['session']));
            } catch (\Exception $e) {
                $this->addException(new Exception('Cannot add SessionCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
            }
        }
        if ($this->shouldCollect('phalcon_request', true) and !$this->hasCollector('request')) {
            try {
                $this->addCollector(new PhalconRequestCollector($this->di['request'], $response, $this->di));
            } catch (\Exception $e) {
                $this->addException(new Exception('Cannot add PhalconRequestCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
            }
        }
        if ($this->hasCollector('pdo')) {
            /** @var Profiler $profiler */
            $profiler = $this->getCollector('pdo')->getProfiler();
            $profiler->handleFailed();
        }
        if ($this->isDebugbarRequest) {
            // Notice: All Collectors must be added before check if is debugbar request.
            return $response;
        }
        try {
            if ($this->isRedirection($response)) {
                $this->stackData();
            } elseif ($this->isJsonRequest($request) && $this->config->get('capture_ajax', true)) {
                $this->sendDataInHeaders(true);
            } elseif ($content_type = $response->getHeaders()->get('Content-Type') and strpos($response->getHeaders()->get('Content-Type'), 'html') === false) {
                $this->collect();
            } elseif ($this->config->get('inject', true)) {
                $response->setHeader('Phalcon-Debugbar', 'on');
                $this->injectDebugbar($response);
            }
        } catch (\Exception $e) {
            $this->addException($e);
        }
        // Stop further rendering (on subrequests etc)
        $this->disable();
        return $response;
    }