From e65b3ac153915504b47c6765e4af5bfb3328c946 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 14 Aug 2018 23:30:49 +0200 Subject: [PATCH] Split SessionServiceProvider from UserServiceProvider This lets us register the former during installation, where the latter is not yet registered. That, in turn, means we can finally re-enable the StartSession middleware in the installer app, which we need to log in the new admin user when installation is complete. --- .../core/src/Foundation/InstalledSite.php | 2 ++ .../core/src/Foundation/UninstalledSite.php | 2 ++ framework/core/src/Install/Installer.php | 2 +- .../core/src/User/SessionServiceProvider.php | 35 +++++++++++++++++++ .../core/src/User/UserServiceProvider.php | 16 --------- .../tests/Test/Concerns/MakesApiRequests.php | 2 ++ 6 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 framework/core/src/User/SessionServiceProvider.php diff --git a/framework/core/src/Foundation/InstalledSite.php b/framework/core/src/Foundation/InstalledSite.php index f30d29625..c811e32cf 100644 --- a/framework/core/src/Foundation/InstalledSite.php +++ b/framework/core/src/Foundation/InstalledSite.php @@ -29,6 +29,7 @@ use Flarum\Search\SearchServiceProvider; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsServiceProvider; use Flarum\Update\UpdateServiceProvider; +use Flarum\User\SessionServiceProvider; use Flarum\User\UserServiceProvider; use Illuminate\Cache\FileStore; use Illuminate\Cache\Repository as CacheRepository; @@ -143,6 +144,7 @@ class InstalledSite implements SiteInterface $laravel->register(NotificationServiceProvider::class); $laravel->register(PostServiceProvider::class); $laravel->register(SearchServiceProvider::class); + $laravel->register(SessionServiceProvider::class); $laravel->register(UserServiceProvider::class); $laravel->register(UpdateServiceProvider::class); diff --git a/framework/core/src/Foundation/UninstalledSite.php b/framework/core/src/Foundation/UninstalledSite.php index b655e150d..9519d25f2 100644 --- a/framework/core/src/Foundation/UninstalledSite.php +++ b/framework/core/src/Foundation/UninstalledSite.php @@ -16,6 +16,7 @@ use Flarum\Install\InstallServiceProvider; use Flarum\Locale\LocaleServiceProvider; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\UninstalledSettingsRepository; +use Flarum\User\SessionServiceProvider; use Illuminate\Config\Repository as ConfigRepository; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Filesystem\FilesystemServiceProvider; @@ -79,6 +80,7 @@ class UninstalledSite implements SiteInterface $laravel->register(LocaleServiceProvider::class); $laravel->register(FilesystemServiceProvider::class); + $laravel->register(SessionServiceProvider::class); $laravel->register(ValidationServiceProvider::class); $laravel->register(InstallServiceProvider::class); diff --git a/framework/core/src/Install/Installer.php b/framework/core/src/Install/Installer.php index 0ca0253e7..da9889db4 100644 --- a/framework/core/src/Install/Installer.php +++ b/framework/core/src/Install/Installer.php @@ -38,7 +38,7 @@ class Installer implements AppInterface { $pipe = new MiddlewarePipe; $pipe->pipe($this->laravel->make(HandleErrorsWithWhoops::class)); - #$pipe->pipe($this->laravel->make(StartSession::class)); + $pipe->pipe($this->laravel->make(StartSession::class)); $pipe->pipe( $this->laravel->make( DispatchRoute::class, diff --git a/framework/core/src/User/SessionServiceProvider.php b/framework/core/src/User/SessionServiceProvider.php new file mode 100644 index 000000000..87004fe20 --- /dev/null +++ b/framework/core/src/User/SessionServiceProvider.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\User; + +use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Session\FileSessionHandler; +use SessionHandlerInterface; + +class SessionServiceProvider extends AbstractServiceProvider +{ + /** + * {@inheritdoc} + */ + public function register() + { + $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); + } +} diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index a52d128ad..12aae50fb 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -15,9 +15,7 @@ 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 { @@ -26,24 +24,10 @@ class UserServiceProvider extends AbstractServiceProvider */ 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) { diff --git a/framework/core/tests/Test/Concerns/MakesApiRequests.php b/framework/core/tests/Test/Concerns/MakesApiRequests.php index bcf69f819..d963e9af0 100644 --- a/framework/core/tests/Test/Concerns/MakesApiRequests.php +++ b/framework/core/tests/Test/Concerns/MakesApiRequests.php @@ -14,6 +14,7 @@ namespace Flarum\Tests\Test\Concerns; use Flarum\Api\ApiServiceProvider; use Flarum\Api\Client; use Flarum\User\Guest; +use Flarum\User\SessionServiceProvider; use Flarum\User\User; use Flarum\User\UserServiceProvider; use Psr\Http\Message\ResponseInterface; @@ -22,6 +23,7 @@ trait MakesApiRequests { public function call(string $controller, User $actor = null, array $queryParams = [], array $body = []): ResponseInterface { + $this->app->register(SessionServiceProvider::class); $this->app->register(UserServiceProvider::class); $this->app->register(ApiServiceProvider::class); $this->app->make('flarum.api.middleware');