From 48266dab3681679421edd6f02e4ebb18e706c30d Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 11 Sep 2024 20:01:29 +0200 Subject: [PATCH] Revert and fix session manager (#1666) --- src/LaravelDebugbar.php | 18 ++++--- src/ServiceProvider.php | 14 ----- src/SessionHttpDriver.php | 107 -------------------------------------- src/SymfonyHttpDriver.php | 1 - 4 files changed, 10 insertions(+), 130 deletions(-) delete mode 100644 src/SessionHttpDriver.php diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php index b3a1ca95..668d2df5 100644 --- a/src/LaravelDebugbar.php +++ b/src/LaravelDebugbar.php @@ -130,16 +130,12 @@ public function __construct($app = null) public function getHttpDriver() { if ($this->httpDriver === null) { - if ($this->app->bound('cookie')) { - $this->httpDriver = $this->app->make(SessionHttpDriver::class); - } else { - $this->httpDriver = $this->app->make(SymfonyHttpDriver::class); - } + $this->httpDriver = $this->app->make(SymfonyHttpDriver::class); } return $this->httpDriver; } - + /** * Enable the Debugbar and boot, if not already booted. */ @@ -740,6 +736,12 @@ public function modifyResponse(Request $request, Response $response) // Prevent duplicate modification $this->responseIsModified = true; + // Set the Response if required + $httpDriver = $this->getHttpDriver(); + if ($httpDriver instanceof SymfonyHttpDriver) { + $httpDriver->setResponse($response); + } + // Show the Http Response Exception in the Debugbar, when available if (isset($response->exception)) { $this->addThrowable($response->exception); @@ -757,11 +759,11 @@ public function modifyResponse(Request $request, Response $response) $sessionHiddens = $app['config']->get('debugbar.options.session.hiddens', []); if ($app->bound(SessionManager::class)) { + /** @var \Illuminate\Session\SessionManager $sessionManager */ + $sessionManager = $app->make(SessionManager::class); if ($this->shouldCollect('session') && ! $this->hasCollector('session')) { try { - /** @var \Illuminate\Session\SessionManager $sessionManager */ - $sessionManager = $app->make(SessionManager::class); $this->addCollector(new SessionCollector($sessionManager, $sessionHiddens)); } catch (Exception $e) { $this->addCollectorException('Cannot add SessionCollector', $e); diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index f859ae16..3ba40316 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -35,14 +35,6 @@ public function register() return new LaravelDebugbar($app); }); - $this->app->singleton(SessionHttpDriver::class, function ($app) { - // Attach the Cookie Handler with Request - $cookieHandler = new CookieSessionHandler($app->make('cookie'), 0, true); - $cookieHandler->setRequest($app['request']); - - return new SessionHttpDriver($cookieHandler); - }); - $this->app->singleton(SymfonyHttpDriver::class, function ($app) { return new SymfonyHttpDriver($app->make(SessionManager::class)); }); @@ -176,12 +168,6 @@ protected function registerResponseListener() /** @var LaravelDebugbar $debugbar */ $debugbar = $this->app->make(LaravelDebugbar::class); if ($debugbar->isEnabled()) { - // Now that we have a Response, set it on the Driver - $httpDriver = $debugbar->getHttpDriver(); - if ($httpDriver instanceof SessionHttpDriver || $httpDriver instanceof SymfonyHttpDriver) { - $httpDriver->setResponse($event->response); - } - if ($event->response->isRedirection()) { $debugbar->modifyResponse($event->request, $event->response); } else { diff --git a/src/SessionHttpDriver.php b/src/SessionHttpDriver.php deleted file mode 100644 index eafd2a97..00000000 --- a/src/SessionHttpDriver.php +++ /dev/null @@ -1,107 +0,0 @@ -session = $session; - $this->response = $response; - } - - /** - * @param \Symfony\Component\HttpFoundation\Response $response - * @return void - */ - public function setResponse($response) - { - $this->response = $response; - } - - /** - * {@inheritDoc} - */ - public function setHeaders(array $headers) - { - if (!is_null($this->response)) { - $this->response->headers->add($headers); - } - } - - protected function ensureStarted() - { - if ($this->data === null) { - $this->data = json_decode($this->session->read($this->id), true) ?: []; - } - } - - /** - * {@inheritDoc} - */ - public function isSessionStarted() - { - $this->ensureStarted(); - return true; - } - - /** - * {@inheritDoc} - */ - public function setSessionValue($name, $value) - { - $this->isSessionStarted(); - - $this->data[$name] = $value; - $this->session->write($this->id, json_encode($this->data)); - } - - /** - * {@inheritDoc} - */ - public function hasSessionValue($name) - { - $this->ensureStarted(); - - return array_key_exists($name, $this->data); - } - - /** - * {@inheritDoc} - */ - public function getSessionValue($name) - { - $this->ensureStarted(); - - return $this->data[$name] ?? null; - } - - /** - * {@inheritDoc} - */ - public function deleteSessionValue($name) - {$this->isSessionStarted(); - - unset($this->data[$name]); - - $this->session->write($this->id, json_encode($this->data)); - } -} diff --git a/src/SymfonyHttpDriver.php b/src/SymfonyHttpDriver.php index 1daf0ffc..8bfd5562 100644 --- a/src/SymfonyHttpDriver.php +++ b/src/SymfonyHttpDriver.php @@ -9,7 +9,6 @@ /** * HTTP driver for Symfony Request/Session * - * @deprecated */ class SymfonyHttpDriver implements HttpDriverInterface {