Barryvdh\Debugbar\LaravelDebugbar::modifyResponse PHP Method

modifyResponse() public method

Modify the response and inject the debugbar (or data in headers)
public modifyResponse ( Request $request, Response $response ) : Response
$request Symfony\Component\HttpFoundation\Request
$response Symfony\Component\HttpFoundation\Response
return Symfony\Component\HttpFoundation\Response
    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;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Handle an incoming request.
  *
  * @param  Request  $request
  * @param  Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         /** @var \Illuminate\Http\Response $response */
         $response = $next($request);
     } catch (Exception $e) {
         $response = $this->handleException($request, $e);
     }
     // Modify the response to add the Debugbar
     $this->debugbar->modifyResponse($request, $response);
     return $response;
 }
All Usage Examples Of Barryvdh\Debugbar\LaravelDebugbar::modifyResponse