diff --git a/Bootstraps/Laravel.php b/Bootstraps/Laravel.php index 52e231b..18ae89e 100644 --- a/Bootstraps/Laravel.php +++ b/Bootstraps/Laravel.php @@ -75,23 +75,59 @@ public function getApplication() } $kernel = $this->app->make('Illuminate\Contracts\Http\Kernel'); + + $this->app->afterResolving('auth', function($auth) { + $auth->extend('session', function($app, $name, $config) { + $provider = $app['auth']->createUserProvider($config['provider']); + $guard = new \PHPPM\Laravel\SessionGuard($name, $provider, $app['session.store'], null, $app); + $guard->setCookieJar($app['cookie']); + $guard->setDispatcher($app['events']); + $guard->setRequest($app->refresh('request', $guard, 'setRequest')); + + return $guard; + }); + }); + + $app = $this->app; + $this->app->extend('session.store', function() use ($app) { + $manager = $app['session']; + return $manager->driver(); + }); + + return $kernel; } - - /** - * @param \Illuminate\Contracts\Foundation\Application $app - */ - public function preHandle($app) - { - //reset const LARAVEL_START, to get the correct timing - } - - /** - * @param \Illuminate\Contracts\Foundation\Application $app - */ - public function postHandle($app) - { - //reset debugbar if available - } + + /** + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function preHandle($app) + { + //reset const LARAVEL_START, to get the correct timing + } + + /** + * @param \Illuminate\Contracts\Foundation\Application $app + */ + public function postHandle($app) + { + //reset debugbar if available + + $this->resetProvider('\Illuminate\Cookie\CookieServiceProvider'); + $this->resetProvider('\Illuminate\Session\SessionServiceProvider'); + } + + /** + * @param string $providerName + */ + protected function resetProvider($providerName) + { + if (!$this->app->getProvider($providerName)) + { + return; + } + + $this->app->register($providerName, [], true); + } } diff --git a/Bridges/HttpKernel.php b/Bridges/HttpKernel.php index eed3a1f..98917ea 100644 --- a/Bridges/HttpKernel.php +++ b/Bridges/HttpKernel.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Symfony\Component\HttpFoundation\StreamedResponse as SymfonyStreamedResponse; use Symfony\Component\HttpKernel\TerminableInterface; +use Illuminate\Contracts\Http\Kernel; class HttpKernel implements BridgeInterface { @@ -110,6 +111,10 @@ public function onRequest(ReactRequest $request, HttpResponse $response) if ($this->application instanceof TerminableInterface) { $this->application->terminate($syRequest, $syResponse); } + + if ($this->application instanceof Kernel) { + $this->application->terminate($syRequest, $syResponse); + } if ($this->bootstrap instanceof HooksInterface) { $this->bootstrap->postHandle($this->application); diff --git a/Laravel/SessionGuard.php b/Laravel/SessionGuard.php new file mode 100644 index 0000000..773536f --- /dev/null +++ b/Laravel/SessionGuard.php @@ -0,0 +1,73 @@ +name = $name; + $this->session = $session; + $this->request = $request; + $this->provider = $provider; + $this->app = $app; + } + + /** + * Set the current request instance. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * @return $this + */ + public function setRequest(Request $request) + { + // reset the current state + $this->reset(); + + // retrieve a new session from the app + $this->session = $this->app->make('session'); + + return parent::setRequest($request); + } + + /** + * Reset the state of current class instance. + * + * @return void + */ + protected function reset() + { + $this->user = null; + $this->lastAttempted = null; + $this->viaRemember = false; + $this->loggedOut = false; + $this->tokenRetrievalAttempted = false; + } +}