public function modifyResponse(Request $request, Response $response)
{
$app = $this->app;
if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
return $response;
}
// Show the Http Response Exception in the Debugbar, when available
if (isset($response->exception)) {
$this->addThrowable($response->exception);
}
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->all());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addThrowable(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($this->app->bound(SessionManager::class)) {
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app->make(SessionManager::class);
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
try {
$this->addCollector(new SessionCollector($sessionManager));
} catch (\Exception $e) {
$this->addThrowable(new Exception('Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
} else {
$sessionManager = null;
}
if ($this->shouldCollect('symfony_request', true) && !$this->hasCollector('request')) {
try {
$this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addThrowable(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
}
if ($app['config']->get('debugbar.clockwork') && !$this->hasCollector('clockwork')) {
try {
$this->addCollector(new ClockworkCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addThrowable(new Exception('Cannot add ClockworkCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
}
$this->addClockworkHeaders($response);
}
if ($response->isRedirection()) {
try {
$this->stackData();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($this->isJsonRequest($request) && $app['config']->get('debugbar.capture_ajax', true)) {
try {
$this->sendDataInHeaders(true);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || $request->getRequestFormat() !== 'html') {
try {
// Just collect + store data, don't inject it.
$this->collect();
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
} elseif ($app['config']->get('debugbar.inject', true)) {
try {
$this->injectDebugbar($response);
} catch (\Exception $e) {
$app['log']->error('Debugbar exception: ' . $e->getMessage());
}
}
return $response;
}