From d77cc5440b72d65a2a923fafb3eff8d0f0283988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Thu, 29 Apr 2021 21:33:51 +0200 Subject: [PATCH] fixed container bindings use of container (#2807) --- .../core/src/Admin/AdminServiceProvider.php | 37 +++--- framework/core/src/Api/ApiServiceProvider.php | 29 ++--- framework/core/src/Bus/BusServiceProvider.php | 3 +- .../src/Console/ConsoleServiceProvider.php | 11 +- .../src/Database/DatabaseServiceProvider.php | 22 ++-- .../Discussion/DiscussionServiceProvider.php | 8 +- .../Extension/ExtensionServiceProvider.php | 5 +- .../Filesystem/FilesystemServiceProvider.php | 17 +-- .../core/src/Filter/FilterServiceProvider.php | 11 +- .../Formatter/FormatterServiceProvider.php | 2 +- .../core/src/Forum/ForumServiceProvider.php | 108 +++++++++--------- .../src/Frontend/FrontendServiceProvider.php | 29 ++--- .../core/src/Http/HttpServiceProvider.php | 15 +-- .../src/Install/InstallServiceProvider.php | 12 +- .../core/src/Locale/LocaleServiceProvider.php | 25 ++-- .../core/src/Mail/MailServiceProvider.php | 25 ++-- .../NotificationServiceProvider.php | 17 +-- .../core/src/Post/PostServiceProvider.php | 8 +- .../core/src/Queue/QueueServiceProvider.php | 30 ++--- .../core/src/Search/SearchServiceProvider.php | 24 ++-- .../src/Settings/SettingsServiceProvider.php | 5 +- .../core/src/Update/UpdateServiceProvider.php | 14 +-- .../core/src/User/UserServiceProvider.php | 34 +++--- 23 files changed, 246 insertions(+), 245 deletions(-) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 24ba91b29..4fd20f77f 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -27,6 +27,7 @@ use Flarum\Http\RouteHandlerFactory; use Flarum\Http\UrlGenerator; use Flarum\Locale\LocaleManager; use Flarum\Settings\Event\Saved; +use Illuminate\Contracts\Container\Container; use Laminas\Stratigility\MiddlewarePipe; class AdminServiceProvider extends AbstractServiceProvider @@ -36,8 +37,8 @@ class AdminServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { - return $url->addCollection('admin', $this->container->make('flarum.admin.routes'), 'admin'); + $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) { + return $url->addCollection('admin', $container->make('flarum.admin.routes'), 'admin'); }); $this->container->singleton('flarum.admin.routes', function () { @@ -62,23 +63,23 @@ class AdminServiceProvider extends AbstractServiceProvider ]; }); - $this->container->bind('flarum.admin.error_handler', function () { + $this->container->bind('flarum.admin.error_handler', function (Container $container) { return new HttpMiddleware\HandleErrors( - $this->container->make(Registry::class), - $this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class), - $this->container->tagged(Reporter::class) + $container->make(Registry::class), + $container['flarum.config']->inDebugMode() ? $container->make(WhoopsFormatter::class) : $container->make(ViewFormatter::class), + $container->tagged(Reporter::class) ); }); - $this->container->bind('flarum.admin.route_resolver', function () { - return new HttpMiddleware\ResolveRoute($this->container->make('flarum.admin.routes')); + $this->container->bind('flarum.admin.route_resolver', function (Container $container) { + return new HttpMiddleware\ResolveRoute($container->make('flarum.admin.routes')); }); - $this->container->singleton('flarum.admin.handler', function () { + $this->container->singleton('flarum.admin.handler', function (Container $container) { $pipe = new MiddlewarePipe; - foreach ($this->container->make('flarum.admin.middleware') as $middleware) { - $pipe->pipe($this->container->make($middleware)); + foreach ($container->make('flarum.admin.middleware') as $middleware) { + $pipe->pipe($container->make($middleware)); } $pipe->pipe(new HttpMiddleware\ExecuteRoute()); @@ -86,9 +87,9 @@ class AdminServiceProvider extends AbstractServiceProvider return $pipe; }); - $this->container->bind('flarum.assets.admin', function () { + $this->container->bind('flarum.assets.admin', function (Container $container) { /** @var \Flarum\Frontend\Assets $assets */ - $assets = $this->container->make('flarum.assets.factory')('admin'); + $assets = $container->make('flarum.assets.factory')('admin'); $assets->js(function (SourceCollector $sources) { $sources->addFile(__DIR__.'/../../js/dist/admin.js'); @@ -98,17 +99,17 @@ class AdminServiceProvider extends AbstractServiceProvider $sources->addFile(__DIR__.'/../../less/admin.less'); }); - $this->container->make(AddTranslations::class)->forFrontend('admin')->to($assets); - $this->container->make(AddLocaleAssets::class)->to($assets); + $container->make(AddTranslations::class)->forFrontend('admin')->to($assets); + $container->make(AddLocaleAssets::class)->to($assets); return $assets; }); - $this->container->bind('flarum.frontend.admin', function () { + $this->container->bind('flarum.frontend.admin', function (Container $container) { /** @var \Flarum\Frontend\Frontend $frontend */ - $frontend = $this->container->make('flarum.frontend.factory')('admin'); + $frontend = $container->make('flarum.frontend.factory')('admin'); - $frontend->content($this->container->make(Content\AdminPayload::class)); + $frontend->content($container->make(Content\AdminPayload::class)); return $frontend; }); diff --git a/framework/core/src/Api/ApiServiceProvider.php b/framework/core/src/Api/ApiServiceProvider.php index aea885adb..f092924a8 100644 --- a/framework/core/src/Api/ApiServiceProvider.php +++ b/framework/core/src/Api/ApiServiceProvider.php @@ -21,6 +21,7 @@ use Flarum\Http\Middleware as HttpMiddleware; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; use Flarum\Http\UrlGenerator; +use Illuminate\Contracts\Container\Container; use Laminas\Stratigility\MiddlewarePipe; class ApiServiceProvider extends AbstractServiceProvider @@ -30,8 +31,8 @@ class ApiServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { - return $url->addCollection('api', $this->container->make('flarum.api.routes'), 'api'); + $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) { + return $url->addCollection('api', $container->make('flarum.api.routes'), 'api'); }); $this->container->singleton('flarum.api.routes', function () { @@ -51,7 +52,7 @@ class ApiServiceProvider extends AbstractServiceProvider ]; }); - $this->container->bind(Middleware\ThrottleApi::class, function ($container) { + $this->container->bind(Middleware\ThrottleApi::class, function (Container $container) { return new Middleware\ThrottleApi($container->make('flarum.api.throttlers')); }); @@ -72,23 +73,23 @@ class ApiServiceProvider extends AbstractServiceProvider ]; }); - $this->container->bind('flarum.api.error_handler', function () { + $this->container->bind('flarum.api.error_handler', function (Container $container) { return new HttpMiddleware\HandleErrors( - $this->container->make(Registry::class), - new JsonApiFormatter($this->container['flarum.config']->inDebugMode()), - $this->container->tagged(Reporter::class) + $container->make(Registry::class), + new JsonApiFormatter($container['flarum.config']->inDebugMode()), + $container->tagged(Reporter::class) ); }); - $this->container->bind('flarum.api.route_resolver', function () { - return new HttpMiddleware\ResolveRoute($this->container->make('flarum.api.routes')); + $this->container->bind('flarum.api.route_resolver', function (Container $container) { + return new HttpMiddleware\ResolveRoute($container->make('flarum.api.routes')); }); - $this->container->singleton('flarum.api.handler', function () { + $this->container->singleton('flarum.api.handler', function (Container $container) { $pipe = new MiddlewarePipe; foreach ($this->container->make('flarum.api.middleware') as $middleware) { - $pipe->pipe($this->container->make($middleware)); + $pipe->pipe($container->make($middleware)); } $pipe->pipe(new HttpMiddleware\ExecuteRoute()); @@ -106,13 +107,13 @@ class ApiServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Container $container) { $this->setNotificationSerializers(); - AbstractSerializeController::setContainer($this->container); + AbstractSerializeController::setContainer($container); - AbstractSerializer::setContainer($this->container); + AbstractSerializer::setContainer($container); } /** diff --git a/framework/core/src/Bus/BusServiceProvider.php b/framework/core/src/Bus/BusServiceProvider.php index b5264bd5f..d3455f7bc 100644 --- a/framework/core/src/Bus/BusServiceProvider.php +++ b/framework/core/src/Bus/BusServiceProvider.php @@ -13,13 +13,14 @@ use Flarum\Foundation\AbstractServiceProvider; use Illuminate\Bus\Dispatcher as BaseDispatcher; use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract; use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; class BusServiceProvider extends AbstractServiceProvider { public function register() { - $this->container->bind(BaseDispatcher::class, function ($container) { + $this->container->bind(BaseDispatcher::class, function (Container $container) { return new Dispatcher($container, function ($connection = null) use ($container) { return $container[QueueFactoryContract::class]->connection($connection); }); diff --git a/framework/core/src/Console/ConsoleServiceProvider.php b/framework/core/src/Console/ConsoleServiceProvider.php index 1ad0e69b4..0e44aa32c 100644 --- a/framework/core/src/Console/ConsoleServiceProvider.php +++ b/framework/core/src/Console/ConsoleServiceProvider.php @@ -18,6 +18,7 @@ use Flarum\Foundation\Console\InfoCommand; use Illuminate\Console\Scheduling\Schedule as LaravelSchedule; use Illuminate\Console\Scheduling\ScheduleListCommand; use Illuminate\Console\Scheduling\ScheduleRunCommand; +use Illuminate\Contracts\Container\Container; class ConsoleServiceProvider extends AbstractServiceProvider { @@ -32,8 +33,8 @@ class ConsoleServiceProvider extends AbstractServiceProvider define('ARTISAN_BINARY', 'flarum'); } - $this->container->singleton(LaravelSchedule::class, function () { - return $this->container->make(Schedule::class); + $this->container->singleton(LaravelSchedule::class, function (Container $container) { + return $container->make(Schedule::class); }); $this->container->singleton('flarum.console.commands', function () { @@ -56,11 +57,11 @@ class ConsoleServiceProvider extends AbstractServiceProvider /** * {@inheritDoc} */ - public function boot() + public function boot(Container $container) { - $schedule = $this->container->make(LaravelSchedule::class); + $schedule = $container->make(LaravelSchedule::class); - foreach ($this->container->make('flarum.console.scheduled') as $scheduled) { + foreach ($container->make('flarum.console.scheduled') as $scheduled) { $event = $schedule->command($scheduled['command'], $scheduled['args']); $scheduled['callback']($event); } diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index 47ead30a7..ad66fcbd4 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -10,6 +10,7 @@ namespace Flarum\Database; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Container\Container; use Illuminate\Database\Capsule\Manager; use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionResolverInterface; @@ -21,10 +22,10 @@ class DatabaseServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->singleton(Manager::class, function ($container) { + $this->container->singleton(Manager::class, function (Container $container) { $manager = new Manager($container); - $config = $this->container['flarum']->config('database'); + $config = $container['flarum']->config('database'); $config['engine'] = 'InnoDB'; $config['prefix_indexes'] = true; @@ -33,7 +34,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider return $manager; }); - $this->container->singleton(ConnectionResolverInterface::class, function ($container) { + $this->container->singleton(ConnectionResolverInterface::class, function (Container $container) { $manager = $container->make(Manager::class); $manager->setAsGlobal(); $manager->bootEloquent(); @@ -46,7 +47,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider $this->container->alias(ConnectionResolverInterface::class, 'db'); - $this->container->singleton(ConnectionInterface::class, function ($container) { + $this->container->singleton(ConnectionInterface::class, function (Container $container) { $resolver = $container->make(ConnectionResolverInterface::class); return $resolver->connection(); @@ -55,7 +56,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider $this->container->alias(ConnectionInterface::class, 'db.connection'); $this->container->alias(ConnectionInterface::class, 'flarum.db'); - $this->container->singleton(MigrationRepositoryInterface::class, function ($container) { + $this->container->singleton(MigrationRepositoryInterface::class, function (Container $container) { return new DatabaseMigrationRepository($container['flarum.db'], 'migrations'); }); @@ -64,15 +65,12 @@ class DatabaseServiceProvider extends AbstractServiceProvider }); } - /** - * {@inheritdoc} - */ - public function boot() + public function boot(Container $container) { - AbstractModel::setConnectionResolver($this->container->make(ConnectionResolverInterface::class)); - AbstractModel::setEventDispatcher($this->container->make('events')); + AbstractModel::setConnectionResolver($container->make(ConnectionResolverInterface::class)); + AbstractModel::setEventDispatcher($container->make('events')); - foreach ($this->container->make('flarum.database.model_private_checkers') as $modelClass => $checkers) { + foreach ($container->make('flarum.database.model_private_checkers') as $modelClass => $checkers) { $modelClass::saving(function ($instance) use ($checkers) { foreach ($checkers as $checker) { if ($checker($instance) === true) { diff --git a/framework/core/src/Discussion/DiscussionServiceProvider.php b/framework/core/src/Discussion/DiscussionServiceProvider.php index d5c5c0062..453dbb4a7 100644 --- a/framework/core/src/Discussion/DiscussionServiceProvider.php +++ b/framework/core/src/Discussion/DiscussionServiceProvider.php @@ -12,16 +12,12 @@ namespace Flarum\Discussion; use Flarum\Discussion\Access\ScopeDiscussionVisibility; use Flarum\Discussion\Event\Renamed; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Events\Dispatcher; class DiscussionServiceProvider extends AbstractServiceProvider { - /** - * {@inheritdoc} - */ - public function boot() + public function boot(Dispatcher $events) { - $events = $this->container->make('events'); - $events->subscribe(DiscussionMetadataUpdater::class); $events->listen( diff --git a/framework/core/src/Extension/ExtensionServiceProvider.php b/framework/core/src/Extension/ExtensionServiceProvider.php index 0be6ff750..648b0285e 100644 --- a/framework/core/src/Extension/ExtensionServiceProvider.php +++ b/framework/core/src/Extension/ExtensionServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Extension; use Flarum\Extension\Event\Disabling; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Events\Dispatcher; class ExtensionServiceProvider extends AbstractServiceProvider { @@ -34,9 +35,9 @@ class ExtensionServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Dispatcher $events) { - $this->container->make('events')->listen( + $events->listen( Disabling::class, DefaultLanguagePackGuard::class ); diff --git a/framework/core/src/Filesystem/FilesystemServiceProvider.php b/framework/core/src/Filesystem/FilesystemServiceProvider.php index 9583d4ceb..011204e28 100644 --- a/framework/core/src/Filesystem/FilesystemServiceProvider.php +++ b/framework/core/src/Filesystem/FilesystemServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Filesystem; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Paths; use Flarum\Http\UrlGenerator; +use Illuminate\Contracts\Container\Container; use Illuminate\Filesystem\Filesystem; class FilesystemServiceProvider extends AbstractServiceProvider @@ -46,17 +47,17 @@ class FilesystemServiceProvider extends AbstractServiceProvider return []; }); - $this->container->singleton('flarum.filesystem.resolved_drivers', function () { - return array_map(function ($driverClass) { - return $this->container->make($driverClass); - }, $this->container->make('flarum.filesystem.drivers')); + $this->container->singleton('flarum.filesystem.resolved_drivers', function (Container $container) { + return array_map(function ($driverClass) use ($container) { + return $container->make($driverClass); + }, $container->make('flarum.filesystem.drivers')); }); - $this->container->singleton('filesystem', function () { + $this->container->singleton('filesystem', function (Container $container) { return new FilesystemManager( - $this->container, - $this->container->make('flarum.filesystem.disks'), - $this->container->make('flarum.filesystem.resolved_drivers') + $container, + $container->make('flarum.filesystem.disks'), + $container->make('flarum.filesystem.resolved_drivers') ); }); } diff --git a/framework/core/src/Filter/FilterServiceProvider.php b/framework/core/src/Filter/FilterServiceProvider.php index b2ca7c739..43b447f66 100644 --- a/framework/core/src/Filter/FilterServiceProvider.php +++ b/framework/core/src/Filter/FilterServiceProvider.php @@ -17,6 +17,7 @@ use Flarum\Post\Filter as PostFilter; use Flarum\Post\Filter\PostFilterer; use Flarum\User\Filter\UserFilterer; use Flarum\User\Query as UserQuery; +use Illuminate\Contracts\Container\Container; use Illuminate\Support\Arr; class FilterServiceProvider extends AbstractServiceProvider @@ -55,7 +56,7 @@ class FilterServiceProvider extends AbstractServiceProvider }); } - public function boot() + public function boot(Container $container) { // We can resolve the filter mutators in the when->needs->give callback, // but we need to resolve at least one regardless so we know which @@ -63,7 +64,7 @@ class FilterServiceProvider extends AbstractServiceProvider $filters = $this->container->make('flarum.filter.filters'); foreach ($filters as $filterer => $filterClasses) { - $this->container + $container ->when($filterer) ->needs('$filters') ->give(function () use ($filterClasses) { @@ -77,13 +78,13 @@ class FilterServiceProvider extends AbstractServiceProvider return $compiled; }); - $this->container + $container ->when($filterer) ->needs('$filterMutators') - ->give(function () use ($filterer) { + ->give(function () use ($container, $filterer) { return array_map(function ($filterMutatorClass) { return ContainerUtil::wrapCallback($filterMutatorClass, $this->container); - }, Arr::get($this->container->make('flarum.filter.filter_mutators'), $filterer, [])); + }, Arr::get($container->make('flarum.filter.filter_mutators'), $filterer, [])); }); } } diff --git a/framework/core/src/Formatter/FormatterServiceProvider.php b/framework/core/src/Formatter/FormatterServiceProvider.php index 399453924..811f3cf1e 100644 --- a/framework/core/src/Formatter/FormatterServiceProvider.php +++ b/framework/core/src/Formatter/FormatterServiceProvider.php @@ -24,7 +24,7 @@ class FormatterServiceProvider extends AbstractServiceProvider $this->container->singleton('flarum.formatter', function (Container $container) { return new Formatter( new Repository($container->make('cache.filestore')), - $this->container[Paths::class]->storage.'/formatter' + $container[Paths::class]->storage.'/formatter' ); }); diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index 0fc3ed579..9ea0df61c 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -31,6 +31,9 @@ use Flarum\Locale\LocaleManager; use Flarum\Settings\Event\Saved; use Flarum\Settings\Event\Saving; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\View\Factory; use Laminas\Stratigility\MiddlewarePipe; use Symfony\Contracts\Translation\TranslatorInterface; @@ -41,19 +44,19 @@ class ForumServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { - return $url->addCollection('forum', $this->container->make('flarum.forum.routes')); + $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) { + return $url->addCollection('forum', $container->make('flarum.forum.routes')); }); - $this->container->singleton('flarum.forum.routes', function () { + $this->container->singleton('flarum.forum.routes', function (Container $container) { $routes = new RouteCollection; - $this->populateRoutes($routes); + $this->populateRoutes($routes, $container); return $routes; }); - $this->container->afterResolving('flarum.forum.routes', function (RouteCollection $routes) { - $this->setDefaultRoute($routes); + $this->container->afterResolving('flarum.forum.routes', function (RouteCollection $routes, Container $container) { + $this->setDefaultRoute($routes, $container); }); $this->container->singleton('flarum.forum.middleware', function () { @@ -73,23 +76,23 @@ class ForumServiceProvider extends AbstractServiceProvider ]; }); - $this->container->bind('flarum.forum.error_handler', function () { + $this->container->bind('flarum.forum.error_handler', function (Container $container) { return new HttpMiddleware\HandleErrors( - $this->container->make(Registry::class), - $this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class), - $this->container->tagged(Reporter::class) + $container->make(Registry::class), + $container['flarum.config']->inDebugMode() ? $container->make(WhoopsFormatter::class) : $container->make(ViewFormatter::class), + $container->tagged(Reporter::class) ); }); - $this->container->bind('flarum.forum.route_resolver', function () { - return new HttpMiddleware\ResolveRoute($this->container->make('flarum.forum.routes')); + $this->container->bind('flarum.forum.route_resolver', function (Container $container) { + return new HttpMiddleware\ResolveRoute($container->make('flarum.forum.routes')); }); - $this->container->singleton('flarum.forum.handler', function () { + $this->container->singleton('flarum.forum.handler', function (Container $container) { $pipe = new MiddlewarePipe; - foreach ($this->container->make('flarum.forum.middleware') as $middleware) { - $pipe->pipe($this->container->make($middleware)); + foreach ($container->make('flarum.forum.middleware') as $middleware) { + $pipe->pipe($container->make($middleware)); } $pipe->pipe(new HttpMiddleware\ExecuteRoute()); @@ -97,55 +100,50 @@ class ForumServiceProvider extends AbstractServiceProvider return $pipe; }); - $this->container->bind('flarum.assets.forum', function () { + $this->container->bind('flarum.assets.forum', function (Container $container) { /** @var Assets $assets */ - $assets = $this->container->make('flarum.assets.factory')('forum'); + $assets = $container->make('flarum.assets.factory')('forum'); - $assets->js(function (SourceCollector $sources) { + $assets->js(function (SourceCollector $sources) use ($container) { $sources->addFile(__DIR__.'/../../js/dist/forum.js'); - $sources->addString(function () { - return $this->container->make(Formatter::class)->getJs(); + $sources->addString(function () use ($container) { + return $container->make(Formatter::class)->getJs(); }); }); - $assets->css(function (SourceCollector $sources) { + $assets->css(function (SourceCollector $sources) use ($container) { $sources->addFile(__DIR__.'/../../less/forum.less'); - $sources->addString(function () { - return $this->container->make(SettingsRepositoryInterface::class)->get('custom_less', ''); + $sources->addString(function () use ($container) { + return $container->make(SettingsRepositoryInterface::class)->get('custom_less', ''); }); }); - $this->container->make(AddTranslations::class)->forFrontend('forum')->to($assets); - $this->container->make(AddLocaleAssets::class)->to($assets); + $container->make(AddTranslations::class)->forFrontend('forum')->to($assets); + $container->make(AddLocaleAssets::class)->to($assets); return $assets; }); - $this->container->bind('flarum.frontend.forum', function () { - return $this->container->make('flarum.frontend.factory')('forum'); + $this->container->bind('flarum.frontend.forum', function (Container $container) { + return $container->make('flarum.frontend.factory')('forum'); }); } - /** - * {@inheritdoc} - */ - public function boot() + public function boot(Container $container, Dispatcher $events, Factory $view) { $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); - $this->container->make('view')->share([ - 'translator' => $this->container->make(TranslatorInterface::class), - 'settings' => $this->container->make(SettingsRepositoryInterface::class) + $view->share([ + 'translator' => $container->make(TranslatorInterface::class), + 'settings' => $container->make(SettingsRepositoryInterface::class) ]); - $events = $this->container->make('events'); - $events->listen( [Enabled::class, Disabled::class, ClearingCache::class], - function () { + function () use ($container) { $recompile = new RecompileFrontendAssets( - $this->container->make('flarum.assets.forum'), - $this->container->make(LocaleManager::class) + $container->make('flarum.assets.forum'), + $container->make(LocaleManager::class) ); $recompile->flush(); } @@ -153,17 +151,17 @@ class ForumServiceProvider extends AbstractServiceProvider $events->listen( Saved::class, - function (Saved $event) { + function (Saved $event) use ($container) { $recompile = new RecompileFrontendAssets( - $this->container->make('flarum.assets.forum'), - $this->container->make(LocaleManager::class) + $container->make('flarum.assets.forum'), + $container->make(LocaleManager::class) ); $recompile->whenSettingsSaved($event); $validator = new ValidateCustomLess( - $this->container->make('flarum.assets.forum'), - $this->container->make('flarum.locales'), - $this->container + $container->make('flarum.assets.forum'), + $container->make('flarum.locales'), + $container ); $validator->whenSettingsSaved($event); } @@ -171,11 +169,11 @@ class ForumServiceProvider extends AbstractServiceProvider $events->listen( Saving::class, - function (Saving $event) { + function (Saving $event) use ($container) { $validator = new ValidateCustomLess( - $this->container->make('flarum.assets.forum'), - $this->container->make('flarum.locales'), - $this->container + $container->make('flarum.assets.forum'), + $container->make('flarum.locales'), + $container ); $validator->whenSettingsSaving($event); } @@ -186,10 +184,11 @@ class ForumServiceProvider extends AbstractServiceProvider * Populate the forum client routes. * * @param RouteCollection $routes + * @param Container $container */ - protected function populateRoutes(RouteCollection $routes) + protected function populateRoutes(RouteCollection $routes, Container $container) { - $factory = $this->container->make(RouteHandlerFactory::class); + $factory = $container->make(RouteHandlerFactory::class); $callback = include __DIR__.'/routes.php'; $callback($routes, $factory); @@ -199,11 +198,12 @@ class ForumServiceProvider extends AbstractServiceProvider * Determine the default route. * * @param RouteCollection $routes + * @param Container $container */ - protected function setDefaultRoute(RouteCollection $routes) + protected function setDefaultRoute(RouteCollection $routes, Container $container) { - $factory = $this->container->make(RouteHandlerFactory::class); - $defaultRoute = $this->container->make('flarum.settings')->get('default_route'); + $factory = $container->make(RouteHandlerFactory::class); + $defaultRoute = $container->make('flarum.settings')->get('default_route'); if (isset($routes->getRouteData()[0]['GET'][$defaultRoute]['handler'])) { $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler']; diff --git a/framework/core/src/Frontend/FrontendServiceProvider.php b/framework/core/src/Frontend/FrontendServiceProvider.php index 589724615..cb91a5076 100644 --- a/framework/core/src/Frontend/FrontendServiceProvider.php +++ b/framework/core/src/Frontend/FrontendServiceProvider.php @@ -14,19 +14,20 @@ use Flarum\Foundation\Paths; use Flarum\Frontend\Compiler\Source\SourceCollector; use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\View\Factory as ViewFactory; class FrontendServiceProvider extends AbstractServiceProvider { public function register() { - $this->container->singleton('flarum.assets.factory', function () { - return function (string $name) { - $paths = $this->container[Paths::class]; + $this->container->singleton('flarum.assets.factory', function (Container $container) { + return function (string $name) use ($container) { + $paths = $container[Paths::class]; $assets = new Assets( $name, - $this->container->make('filesystem')->disk('flarum-assets'), + $container->make('filesystem')->disk('flarum-assets'), $paths->storage ); @@ -41,17 +42,17 @@ class FrontendServiceProvider extends AbstractServiceProvider }; }); - $this->container->singleton('flarum.frontend.factory', function () { - return function (string $name) { - $frontend = $this->container->make(Frontend::class); + $this->container->singleton('flarum.frontend.factory', function (Container $container) { + return function (string $name) use ($container) { + $frontend = $container->make(Frontend::class); $frontend->content(function (Document $document) use ($name) { $document->layoutView = 'flarum::frontend.'.$name; }); - $frontend->content($this->container->make(Content\Assets::class)->forFrontend($name)); - $frontend->content($this->container->make(Content\CorePayload::class)); - $frontend->content($this->container->make(Content\Meta::class)); + $frontend->content($container->make(Content\Assets::class)->forFrontend($name)); + $frontend->content($container->make(Content\CorePayload::class)); + $frontend->content($container->make(Content\Meta::class)); return $frontend; }; @@ -61,13 +62,13 @@ class FrontendServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Container $container, ViewFactory $views) { $this->loadViewsFrom(__DIR__.'/../../views', 'flarum'); - $this->container->make(ViewFactory::class)->share([ - 'translator' => $this->container->make('translator'), - 'url' => $this->container->make(UrlGenerator::class) + $views->share([ + 'translator' => $container->make('translator'), + 'url' => $container->make(UrlGenerator::class) ]); } diff --git a/framework/core/src/Http/HttpServiceProvider.php b/framework/core/src/Http/HttpServiceProvider.php index eba6a5f8f..fee561746 100644 --- a/framework/core/src/Http/HttpServiceProvider.php +++ b/framework/core/src/Http/HttpServiceProvider.php @@ -16,6 +16,7 @@ use Flarum\Settings\SettingsRepositoryInterface; use Flarum\User\IdSlugDriver; use Flarum\User\User; use Flarum\User\UsernameSlugDriver; +use Illuminate\Contracts\Container\Container; use Illuminate\Support\Arr; class HttpServiceProvider extends AbstractServiceProvider @@ -29,7 +30,7 @@ class HttpServiceProvider extends AbstractServiceProvider return ['token']; }); - $this->container->bind(Middleware\CheckCsrfToken::class, function ($container) { + $this->container->bind(Middleware\CheckCsrfToken::class, function (Container $container) { return new Middleware\CheckCsrfToken($container->make('flarum.http.csrfExemptPaths')); }); @@ -45,23 +46,23 @@ class HttpServiceProvider extends AbstractServiceProvider ]; }); - $this->container->singleton('flarum.http.selectedSlugDrivers', function () { - $settings = $this->container->make(SettingsRepositoryInterface::class); + $this->container->singleton('flarum.http.selectedSlugDrivers', function (Container $container) { + $settings = $container->make(SettingsRepositoryInterface::class); $compiledDrivers = []; - foreach ($this->container->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) { + foreach ($container->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) { $driverKey = $settings->get("slug_driver_$resourceClass", 'default'); $driverClass = Arr::get($resourceDrivers, $driverKey, $resourceDrivers['default']); - $compiledDrivers[$resourceClass] = $this->container->make($driverClass); + $compiledDrivers[$resourceClass] = $container->make($driverClass); } return $compiledDrivers; }); - $this->container->bind(SlugManager::class, function () { - return new SlugManager($this->container->make('flarum.http.selectedSlugDrivers')); + $this->container->bind(SlugManager::class, function (Container $container) { + return new SlugManager($container->make('flarum.http.selectedSlugDrivers')); }); } diff --git a/framework/core/src/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index d9cb8af5a..814c42847 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Install; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; +use Illuminate\Contracts\Container\Container; class InstallServiceProvider extends AbstractServiceProvider { @@ -28,20 +29,19 @@ class InstallServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Container $container, RouteHandlerFactory $route) { $this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.install'); - $this->populateRoutes($this->container->make('flarum.install.routes')); + $this->populateRoutes($container->make('flarum.install.routes'), $route); } /** - * @param RouteCollection $routes + * @param RouteCollection $routes + * @param RouteHandlerFactory $route */ - protected function populateRoutes(RouteCollection $routes) + protected function populateRoutes(RouteCollection $routes, RouteHandlerFactory $route) { - $route = $this->container->make(RouteHandlerFactory::class); - $routes->get( '/{path:.*}', 'index', diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 0cc1d5f9a..96fafcc45 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -12,6 +12,7 @@ namespace Flarum\Locale; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Paths; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Symfony\Contracts\Translation\TranslatorInterface; @@ -22,25 +23,25 @@ class LocaleServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->singleton(LocaleManager::class, function () { + $this->container->singleton(LocaleManager::class, function (Container $container) { $locales = new LocaleManager( - $this->container->make('translator'), - $this->getCacheDir() + $container->make('translator'), + $this->getCacheDir($container) ); - $locales->addLocale($this->getDefaultLocale(), 'Default'); + $locales->addLocale($this->getDefaultLocale($container), 'Default'); return $locales; }); $this->container->alias(LocaleManager::class, 'flarum.locales'); - $this->container->singleton('translator', function () { + $this->container->singleton('translator', function (Container $container) { $translator = new Translator( - $this->getDefaultLocale(), + $this->getDefaultLocale($container), null, - $this->getCacheDir(), - $this->container['flarum.debug'] + $this->getCacheDir($container), + $container['flarum.debug'] ); $translator->setFallbackLocales(['en']); @@ -56,15 +57,15 @@ class LocaleServiceProvider extends AbstractServiceProvider $this->container->alias('translator', TranslatorInterface::class); } - private function getDefaultLocale(): string + private function getDefaultLocale(Container $container): string { - $repo = $this->container->make(SettingsRepositoryInterface::class); + $repo = $container->make(SettingsRepositoryInterface::class); return $repo->get('default_locale', 'en'); } - private function getCacheDir(): string + private function getCacheDir(Container $container): string { - return $this->container[Paths::class]->storage.'/locale'; + return $container[Paths::class]->storage.'/locale'; } } diff --git a/framework/core/src/Mail/MailServiceProvider.php b/framework/core/src/Mail/MailServiceProvider.php index f690bfe85..875c13a57 100644 --- a/framework/core/src/Mail/MailServiceProvider.php +++ b/framework/core/src/Mail/MailServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Mail; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Settings\SettingsRepositoryInterface; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Validation\Factory; use Illuminate\Mail\Mailer; use Illuminate\Support\Arr; @@ -29,31 +30,31 @@ class MailServiceProvider extends AbstractServiceProvider ]; }); - $this->container->singleton('mail.driver', function () { - $configured = $this->container->make('flarum.mail.configured_driver'); - $settings = $this->container->make(SettingsRepositoryInterface::class); - $validator = $this->container->make(Factory::class); + $this->container->singleton('mail.driver', function (Container $container) { + $configured = $container->make('flarum.mail.configured_driver'); + $settings = $container->make(SettingsRepositoryInterface::class); + $validator = $container->make(Factory::class); return $configured->validate($settings, $validator)->any() - ? $this->container->make(NullDriver::class) + ? $container->make(NullDriver::class) : $configured; }); $this->container->alias('mail.driver', DriverInterface::class); - $this->container->singleton('flarum.mail.configured_driver', function () { - $drivers = $this->container->make('mail.supported_drivers'); - $settings = $this->container->make(SettingsRepositoryInterface::class); + $this->container->singleton('flarum.mail.configured_driver', function (Container $container) { + $drivers = $container->make('mail.supported_drivers'); + $settings = $container->make(SettingsRepositoryInterface::class); $driverName = $settings->get('mail_driver'); $driverClass = Arr::get($drivers, $driverName); return $driverClass - ? $this->container->make($driverClass) - : $this->container->make(NullDriver::class); + ? $container->make($driverClass) + : $container->make(NullDriver::class); }); - $this->container->singleton('swift.mailer', function ($container) { + $this->container->singleton('swift.mailer', function (Container $container) { return new Swift_Mailer( $container->make('mail.driver')->buildTransport( $container->make(SettingsRepositoryInterface::class) @@ -61,7 +62,7 @@ class MailServiceProvider extends AbstractServiceProvider ); }); - $this->container->singleton('mailer', function ($container) { + $this->container->singleton('mailer', function (Container $container) { $mailer = new Mailer( 'flarum', $container['view'], diff --git a/framework/core/src/Notification/NotificationServiceProvider.php b/framework/core/src/Notification/NotificationServiceProvider.php index 859447430..333ead0c1 100644 --- a/framework/core/src/Notification/NotificationServiceProvider.php +++ b/framework/core/src/Notification/NotificationServiceProvider.php @@ -11,6 +11,7 @@ namespace Flarum\Notification; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; +use Illuminate\Contracts\Container\Container; class NotificationServiceProvider extends AbstractServiceProvider { @@ -36,28 +37,28 @@ class NotificationServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Container $container) { - $this->setNotificationDrivers(); - $this->setNotificationTypes(); + $this->setNotificationDrivers($container); + $this->setNotificationTypes($container); } /** * Register notification drivers. */ - protected function setNotificationDrivers() + protected function setNotificationDrivers(Container $container) { - foreach ($this->container->make('flarum.notification.drivers') as $driverName => $driver) { - NotificationSyncer::addNotificationDriver($driverName, $this->container->make($driver)); + foreach ($container->make('flarum.notification.drivers') as $driverName => $driver) { + NotificationSyncer::addNotificationDriver($driverName, $container->make($driver)); } } /** * Register notification types. */ - protected function setNotificationTypes() + protected function setNotificationTypes(Container $container) { - $blueprints = $this->container->make('flarum.notification.blueprints'); + $blueprints = $container->make('flarum.notification.blueprints'); foreach ($blueprints as $blueprint => $driversEnabledByDefault) { $this->addType($blueprint, $driversEnabledByDefault); diff --git a/framework/core/src/Post/PostServiceProvider.php b/framework/core/src/Post/PostServiceProvider.php index 9850ae70e..65f032de7 100644 --- a/framework/core/src/Post/PostServiceProvider.php +++ b/framework/core/src/Post/PostServiceProvider.php @@ -10,6 +10,7 @@ namespace Flarum\Post; use DateTime; +use Flarum\Formatter\Formatter; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Http\RequestUtil; use Flarum\Post\Access\ScopePostVisibility; @@ -42,12 +43,9 @@ class PostServiceProvider extends AbstractServiceProvider }); } - /** - * {@inheritdoc} - */ - public function boot() + public function boot(Formatter $formatter) { - CommentPost::setFormatter($this->container->make('flarum.formatter')); + CommentPost::setFormatter($formatter); $this->setPostTypes(); diff --git a/framework/core/src/Queue/QueueServiceProvider.php b/framework/core/src/Queue/QueueServiceProvider.php index 15a03a57f..c46da4f9a 100644 --- a/framework/core/src/Queue/QueueServiceProvider.php +++ b/framework/core/src/Queue/QueueServiceProvider.php @@ -15,7 +15,9 @@ use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\Paths; use Illuminate\Contracts\Cache\Factory as CacheFactory; +use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\Factory; use Illuminate\Contracts\Queue\Queue; use Illuminate\Queue\Connectors\ConnectorInterface; @@ -42,26 +44,26 @@ class QueueServiceProvider extends AbstractServiceProvider { // Register a simple connection factory that always returns the same // connection, as that is enough for our purposes. - $this->container->singleton(Factory::class, function () { + $this->container->singleton(Factory::class, function (Container $container) { return new QueueFactory(function () { - return $this->container->make('flarum.queue.connection'); + return $container->make('flarum.queue.connection'); }); }); // Extensions can override this binding if they want to make Flarum use // a different queuing backend. - $this->container->singleton('flarum.queue.connection', function ($container) { + $this->container->singleton('flarum.queue.connection', function (Container $container) { $queue = new SyncQueue; $queue->setContainer($container); return $queue; }); - $this->container->singleton(ExceptionHandling::class, function ($container) { + $this->container->singleton(ExceptionHandling::class, function (Container $container) { return new ExceptionHandler($container['log']); }); - $this->container->singleton(Worker::class, function ($container) { + $this->container->singleton(Worker::class, function (Container $container) { /** @var Config $config */ $config = $container->make(Config::class); @@ -77,12 +79,12 @@ class QueueServiceProvider extends AbstractServiceProvider // Override the Laravel native Listener, so that we can ignore the environment // option and force the binary to flarum. - $this->container->singleton(QueueListener::class, function ($container) { - return new Listener($container[Paths::class]->base); + $this->container->singleton(QueueListener::class, function (Container $container) { + return new Listener($container->make(Paths::class)->base); }); // Bind a simple cache manager that returns the cache store. - $this->container->singleton('cache', function ($container) { + $this->container->singleton('cache', function (Container $container) { return new class($container) implements CacheFactory { public function __construct($container) { @@ -124,8 +126,8 @@ class QueueServiceProvider extends AbstractServiceProvider protected function registerCommands() { - $this->container->extend('flarum.console.commands', function ($commands) { - $queue = $this->container->make(Queue::class); + $this->container->extend('flarum.console.commands', function ($commands, Container $container) { + $queue = $container->make(Queue::class); // There is no need to have the queue commands when using the sync driver. if ($queue instanceof SyncQueue) { @@ -138,16 +140,16 @@ class QueueServiceProvider extends AbstractServiceProvider }); } - public function boot() + public function boot(Dispatcher $events, Container $container) { - $this->container['events']->listen(JobFailed::class, function (JobFailed $event) { + $events->listen(JobFailed::class, function (JobFailed $event) use ($container) { /** @var Registry $registry */ - $registry = $this->container->make(Registry::class); + $registry = $container->make(Registry::class); $error = $registry->handle($event->exception); /** @var Reporter[] $reporters */ - $reporters = $this->container->tagged(Reporter::class); + $reporters = $container->tagged(Reporter::class); if ($error->shouldBeReported()) { foreach ($reporters as $reporter) { diff --git a/framework/core/src/Search/SearchServiceProvider.php b/framework/core/src/Search/SearchServiceProvider.php index 0547bdd51..26035c694 100644 --- a/framework/core/src/Search/SearchServiceProvider.php +++ b/framework/core/src/Search/SearchServiceProvider.php @@ -17,6 +17,7 @@ use Flarum\Foundation\ContainerUtil; use Flarum\User\Query as UserQuery; use Flarum\User\Search\Gambit\FulltextGambit as UserFulltextGambit; use Flarum\User\Search\UserSearcher; +use Illuminate\Contracts\Container\Container; use Illuminate\Support\Arr; class SearchServiceProvider extends AbstractServiceProvider @@ -53,31 +54,28 @@ class SearchServiceProvider extends AbstractServiceProvider }); } - /** - * {@inheritdoc} - */ - public function boot() + public function boot(Container $container) { - $fullTextGambits = $this->container->make('flarum.simple_search.fulltext_gambits'); + $fullTextGambits = $container->make('flarum.simple_search.fulltext_gambits'); foreach ($fullTextGambits as $searcher => $fullTextGambitClass) { - $this->container + $container ->when($searcher) ->needs(GambitManager::class) - ->give(function () use ($searcher, $fullTextGambitClass) { - $gambitManager = new GambitManager($this->container->make($fullTextGambitClass)); - foreach (Arr::get($this->container->make('flarum.simple_search.gambits'), $searcher, []) as $gambit) { - $gambitManager->add($this->container->make($gambit)); + ->give(function () use ($container, $searcher, $fullTextGambitClass) { + $gambitManager = new GambitManager($container->make($fullTextGambitClass)); + foreach (Arr::get($container->make('flarum.simple_search.gambits'), $searcher, []) as $gambit) { + $gambitManager->add($container->make($gambit)); } return $gambitManager; }); - $this->container + $container ->when($searcher) ->needs('$searchMutators') - ->give(function () use ($searcher) { - $searchMutators = Arr::get($this->container->make('flarum.simple_search.search_mutators'), $searcher, []); + ->give(function () use ($container, $searcher) { + $searchMutators = Arr::get($container->make('flarum.simple_search.search_mutators'), $searcher, []); return array_map(function ($mutator) { return ContainerUtil::wrapCallback($mutator, $this->container); diff --git a/framework/core/src/Settings/SettingsServiceProvider.php b/framework/core/src/Settings/SettingsServiceProvider.php index 29ab6bd95..4bfb8f466 100644 --- a/framework/core/src/Settings/SettingsServiceProvider.php +++ b/framework/core/src/Settings/SettingsServiceProvider.php @@ -10,6 +10,7 @@ namespace Flarum\Settings; use Flarum\Foundation\AbstractServiceProvider; +use Illuminate\Contracts\Container\Container; use Illuminate\Database\ConnectionInterface; class SettingsServiceProvider extends AbstractServiceProvider @@ -19,10 +20,10 @@ class SettingsServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->singleton(SettingsRepositoryInterface::class, function () { + $this->container->singleton(SettingsRepositoryInterface::class, function (Container $container) { return new MemoryCacheSettingsRepository( new DatabaseSettingsRepository( - $this->container->make(ConnectionInterface::class) + $container->make(ConnectionInterface::class) ) ); }); diff --git a/framework/core/src/Update/UpdateServiceProvider.php b/framework/core/src/Update/UpdateServiceProvider.php index f98c453b6..f9f1d3367 100644 --- a/framework/core/src/Update/UpdateServiceProvider.php +++ b/framework/core/src/Update/UpdateServiceProvider.php @@ -20,29 +20,25 @@ class UpdateServiceProvider extends AbstractServiceProvider */ public function register() { - $this->container->singleton('flarum.update.routes', function () { + $this->container->singleton('flarum.update.routes', function (RouteHandlerFactory $route) { $routes = new RouteCollection; - $this->populateRoutes($routes); + $this->populateRoutes($routes, $route); return $routes; }); } - /** - * {@inheritdoc} - */ public function boot() { $this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.update'); } /** - * @param RouteCollection $routes + * @param RouteCollection $routes + * @param RouteHandlerFactory $route */ - protected function populateRoutes(RouteCollection $routes) + protected function populateRoutes(RouteCollection $routes, RouteHandlerFactory $route) { - $route = $this->container->make(RouteHandlerFactory::class); - $routes->get( '/{path:.*}', 'index', diff --git a/framework/core/src/User/UserServiceProvider.php b/framework/core/src/User/UserServiceProvider.php index 558f61d8d..6e3160d60 100644 --- a/framework/core/src/User/UserServiceProvider.php +++ b/framework/core/src/User/UserServiceProvider.php @@ -24,6 +24,8 @@ use Flarum\User\DisplayName\UsernameDriver; use Flarum\User\Event\EmailChangeRequested; use Flarum\User\Event\Registered; use Flarum\User\Event\Saving; +use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Support\Arr; class UserServiceProvider extends AbstractServiceProvider @@ -59,16 +61,16 @@ class UserServiceProvider extends AbstractServiceProvider ]; }); - $this->container->singleton('flarum.user.display_name.driver', function () { - $drivers = $this->container->make('flarum.user.display_name.supported_drivers'); - $settings = $this->container->make(SettingsRepositoryInterface::class); + $this->container->singleton('flarum.user.display_name.driver', function (Container $container) { + $drivers = $container->make('flarum.user.display_name.supported_drivers'); + $settings = $container->make(SettingsRepositoryInterface::class); $driverName = $settings->get('display_name_driver', ''); $driverClass = Arr::get($drivers, $driverName); return $driverClass - ? $this->container->make($driverClass) - : $this->container->make(UsernameDriver::class); + ? $container->make($driverClass) + : $container->make(UsernameDriver::class); }); $this->container->alias('flarum.user.display_name.driver', DriverInterface::class); @@ -76,10 +78,10 @@ class UserServiceProvider extends AbstractServiceProvider protected function registerPasswordCheckers() { - $this->container->singleton('flarum.user.password_checkers', function () { + $this->container->singleton('flarum.user.password_checkers', function (Container $container) { return [ - 'standard' => function (User $user, $password) { - if ($this->container->make('hash')->check($password, $user->password)) { + 'standard' => function (User $user, $password) use ($container) { + if ($container->make('hash')->check($password, $user->password)) { return true; } } @@ -90,18 +92,16 @@ class UserServiceProvider extends AbstractServiceProvider /** * {@inheritdoc} */ - public function boot() + public function boot(Container $container, Dispatcher $events) { - foreach ($this->container->make('flarum.user.group_processors') as $callback) { - User::addGroupProcessor(ContainerUtil::wrapCallback($callback, $this->container)); + foreach ($container->make('flarum.user.group_processors') as $callback) { + User::addGroupProcessor(ContainerUtil::wrapCallback($callback, $container)); } - User::setHasher($this->container->make('hash')); - User::setPasswordCheckers($this->container->make('flarum.user.password_checkers')); - User::setGate($this->container->makeWith(Access\Gate::class, ['policyClasses' => $this->container->make('flarum.policies')])); - User::setDisplayNameDriver($this->container->make('flarum.user.display_name.driver')); - - $events = $this->container->make('events'); + User::setHasher($container->make('hash')); + User::setPasswordCheckers($container->make('flarum.user.password_checkers')); + User::setGate($container->makeWith(Access\Gate::class, ['policyClasses' => $container->make('flarum.policies')])); + User::setDisplayNameDriver($container->make('flarum.user.display_name.driver')); $events->listen(Saving::class, SelfDemotionGuard::class); $events->listen(Registered::class, AccountActivationMailer::class);