1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 00:15:51 +02:00

Bind session handling to request lifecycle

With this change, session objects are no longer instantiated
globally, but instead created within a middleware during the
request lifecycle.

In addition, session garbage collection is integrated with
the already existing middleware for this purpose.
This commit is contained in:
Franz Liedke
2018-03-18 15:58:31 +01:00
parent 5672819549
commit bb49e24ffe
5 changed files with 73 additions and 45 deletions

View File

@@ -15,7 +15,9 @@ use Flarum\Event\ConfigureUserPreferences;
use Flarum\Event\GetPermission;
use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\Session\FileSessionHandler;
use RuntimeException;
use SessionHandlerInterface;
class UserServiceProvider extends AbstractServiceProvider
{
@@ -23,6 +25,26 @@ class UserServiceProvider extends AbstractServiceProvider
* {@inheritdoc}
*/
public function register()
{
$this->registerSession();
$this->registerGate();
$this->registerAvatarsFilesystem();
}
protected function registerSession()
{
$this->app->singleton('session.handler', function ($app) {
return new FileSessionHandler(
$app['files'],
$app['config']['session.files'],
$app['config']['session.lifetime']
);
});
$this->app->alias('session.handler', SessionHandlerInterface::class);
}
protected function registerGate()
{
$this->app->singleton('flarum.gate', function ($app) {
return new Gate($app, function () {
@@ -32,8 +54,6 @@ class UserServiceProvider extends AbstractServiceProvider
$this->app->alias('flarum.gate', 'Illuminate\Contracts\Auth\Access\Gate');
$this->app->alias('flarum.gate', Gate::class);
$this->registerAvatarsFilesystem();
}
protected function registerAvatarsFilesystem()