Skip to content

Laravel fixes #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Bootstraps/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ public function getApplication()

$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');

$this->app->singleton('auth', function() {
return new \Illuminate\Auth\AuthManager($this->app);
});

$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']);
$guard->setCookieJar($app['cookie']);
$guard->setDispatcher($app['events']);
$guard->setRequest($app->refresh('request', $guard, 'setRequest'));

return $guard;
});
});

return $kernel;
}

Expand All @@ -90,5 +106,20 @@ public function preHandle($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);
}
}
4 changes: 4 additions & 0 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function onRequest(ReactRequest $request, HttpResponse $response)
if ($this->application instanceof TerminableInterface) {
$this->application->terminate($syRequest, $syResponse);
}

if (is_a($this->application, '\Illuminate\Contracts\Http\Kernel')) {
$this->application->terminate($syRequest, $syResponse);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does \Illuminate\Contracts\Http\Kernel not implementTerminableInterface?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that Kernel implements, is just mentioned contract, that's why this one more case is required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why you don't go with $this->application instanceof \Illuminate\Contracts\Http\Kernel?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping


if ($this->bootstrap instanceof HooksInterface) {
$this->bootstrap->postHandle($this->application);
Expand Down
36 changes: 36 additions & 0 deletions Laravel/SessionGuard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace PHPPM\Laravel;

use Symfony\Component\HttpFoundation\Request;

class SessionGuard extends \Illuminate\Auth\SessionGuard
{
/**
* Set the current request instance.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @return $this
*/
public function setRequest(Request $request)
{
$this->reset();
$this->session = $request->getSession();

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;
}
}