fixed container bindings use of container (#2807)

This commit is contained in:
Daniël Klabbers 2021-04-29 21:33:51 +02:00 committed by GitHub
parent 53467fa5a1
commit d77cc5440b
23 changed files with 246 additions and 245 deletions

View File

@ -27,6 +27,7 @@ use Flarum\Http\RouteHandlerFactory;
use Flarum\Http\UrlGenerator; use Flarum\Http\UrlGenerator;
use Flarum\Locale\LocaleManager; use Flarum\Locale\LocaleManager;
use Flarum\Settings\Event\Saved; use Flarum\Settings\Event\Saved;
use Illuminate\Contracts\Container\Container;
use Laminas\Stratigility\MiddlewarePipe; use Laminas\Stratigility\MiddlewarePipe;
class AdminServiceProvider extends AbstractServiceProvider class AdminServiceProvider extends AbstractServiceProvider
@ -36,8 +37,8 @@ class AdminServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) {
return $url->addCollection('admin', $this->container->make('flarum.admin.routes'), 'admin'); return $url->addCollection('admin', $container->make('flarum.admin.routes'), 'admin');
}); });
$this->container->singleton('flarum.admin.routes', function () { $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( return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class), $container->make(Registry::class),
$this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class), $container['flarum.config']->inDebugMode() ? $container->make(WhoopsFormatter::class) : $container->make(ViewFormatter::class),
$this->container->tagged(Reporter::class) $container->tagged(Reporter::class)
); );
}); });
$this->container->bind('flarum.admin.route_resolver', function () { $this->container->bind('flarum.admin.route_resolver', function (Container $container) {
return new HttpMiddleware\ResolveRoute($this->container->make('flarum.admin.routes')); 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; $pipe = new MiddlewarePipe;
foreach ($this->container->make('flarum.admin.middleware') as $middleware) { foreach ($container->make('flarum.admin.middleware') as $middleware) {
$pipe->pipe($this->container->make($middleware)); $pipe->pipe($container->make($middleware));
} }
$pipe->pipe(new HttpMiddleware\ExecuteRoute()); $pipe->pipe(new HttpMiddleware\ExecuteRoute());
@ -86,9 +87,9 @@ class AdminServiceProvider extends AbstractServiceProvider
return $pipe; return $pipe;
}); });
$this->container->bind('flarum.assets.admin', function () { $this->container->bind('flarum.assets.admin', function (Container $container) {
/** @var \Flarum\Frontend\Assets $assets */ /** @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) { $assets->js(function (SourceCollector $sources) {
$sources->addFile(__DIR__.'/../../js/dist/admin.js'); $sources->addFile(__DIR__.'/../../js/dist/admin.js');
@ -98,17 +99,17 @@ class AdminServiceProvider extends AbstractServiceProvider
$sources->addFile(__DIR__.'/../../less/admin.less'); $sources->addFile(__DIR__.'/../../less/admin.less');
}); });
$this->container->make(AddTranslations::class)->forFrontend('admin')->to($assets); $container->make(AddTranslations::class)->forFrontend('admin')->to($assets);
$this->container->make(AddLocaleAssets::class)->to($assets); $container->make(AddLocaleAssets::class)->to($assets);
return $assets; return $assets;
}); });
$this->container->bind('flarum.frontend.admin', function () { $this->container->bind('flarum.frontend.admin', function (Container $container) {
/** @var \Flarum\Frontend\Frontend $frontend */ /** @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; return $frontend;
}); });

View File

@ -21,6 +21,7 @@ use Flarum\Http\Middleware as HttpMiddleware;
use Flarum\Http\RouteCollection; use Flarum\Http\RouteCollection;
use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteHandlerFactory;
use Flarum\Http\UrlGenerator; use Flarum\Http\UrlGenerator;
use Illuminate\Contracts\Container\Container;
use Laminas\Stratigility\MiddlewarePipe; use Laminas\Stratigility\MiddlewarePipe;
class ApiServiceProvider extends AbstractServiceProvider class ApiServiceProvider extends AbstractServiceProvider
@ -30,8 +31,8 @@ class ApiServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) {
return $url->addCollection('api', $this->container->make('flarum.api.routes'), 'api'); return $url->addCollection('api', $container->make('flarum.api.routes'), 'api');
}); });
$this->container->singleton('flarum.api.routes', function () { $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')); 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( return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class), $container->make(Registry::class),
new JsonApiFormatter($this->container['flarum.config']->inDebugMode()), new JsonApiFormatter($container['flarum.config']->inDebugMode()),
$this->container->tagged(Reporter::class) $container->tagged(Reporter::class)
); );
}); });
$this->container->bind('flarum.api.route_resolver', function () { $this->container->bind('flarum.api.route_resolver', function (Container $container) {
return new HttpMiddleware\ResolveRoute($this->container->make('flarum.api.routes')); 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; $pipe = new MiddlewarePipe;
foreach ($this->container->make('flarum.api.middleware') as $middleware) { 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()); $pipe->pipe(new HttpMiddleware\ExecuteRoute());
@ -106,13 +107,13 @@ class ApiServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Container $container)
{ {
$this->setNotificationSerializers(); $this->setNotificationSerializers();
AbstractSerializeController::setContainer($this->container); AbstractSerializeController::setContainer($container);
AbstractSerializer::setContainer($this->container); AbstractSerializer::setContainer($container);
} }
/** /**

View File

@ -13,13 +13,14 @@ use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Bus\Dispatcher as BaseDispatcher; use Illuminate\Bus\Dispatcher as BaseDispatcher;
use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract; use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract; use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Factory as QueueFactoryContract; use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
class BusServiceProvider extends AbstractServiceProvider class BusServiceProvider extends AbstractServiceProvider
{ {
public function register() 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 new Dispatcher($container, function ($connection = null) use ($container) {
return $container[QueueFactoryContract::class]->connection($connection); return $container[QueueFactoryContract::class]->connection($connection);
}); });

View File

@ -18,6 +18,7 @@ use Flarum\Foundation\Console\InfoCommand;
use Illuminate\Console\Scheduling\Schedule as LaravelSchedule; use Illuminate\Console\Scheduling\Schedule as LaravelSchedule;
use Illuminate\Console\Scheduling\ScheduleListCommand; use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand; use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Contracts\Container\Container;
class ConsoleServiceProvider extends AbstractServiceProvider class ConsoleServiceProvider extends AbstractServiceProvider
{ {
@ -32,8 +33,8 @@ class ConsoleServiceProvider extends AbstractServiceProvider
define('ARTISAN_BINARY', 'flarum'); define('ARTISAN_BINARY', 'flarum');
} }
$this->container->singleton(LaravelSchedule::class, function () { $this->container->singleton(LaravelSchedule::class, function (Container $container) {
return $this->container->make(Schedule::class); return $container->make(Schedule::class);
}); });
$this->container->singleton('flarum.console.commands', function () { $this->container->singleton('flarum.console.commands', function () {
@ -56,11 +57,11 @@ class ConsoleServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritDoc} * {@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']); $event = $schedule->command($scheduled['command'], $scheduled['args']);
$scheduled['callback']($event); $scheduled['callback']($event);
} }

View File

@ -10,6 +10,7 @@
namespace Flarum\Database; namespace Flarum\Database;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Capsule\Manager; use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\ConnectionResolverInterface;
@ -21,10 +22,10 @@ class DatabaseServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->singleton(Manager::class, function ($container) { $this->container->singleton(Manager::class, function (Container $container) {
$manager = new Manager($container); $manager = new Manager($container);
$config = $this->container['flarum']->config('database'); $config = $container['flarum']->config('database');
$config['engine'] = 'InnoDB'; $config['engine'] = 'InnoDB';
$config['prefix_indexes'] = true; $config['prefix_indexes'] = true;
@ -33,7 +34,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider
return $manager; return $manager;
}); });
$this->container->singleton(ConnectionResolverInterface::class, function ($container) { $this->container->singleton(ConnectionResolverInterface::class, function (Container $container) {
$manager = $container->make(Manager::class); $manager = $container->make(Manager::class);
$manager->setAsGlobal(); $manager->setAsGlobal();
$manager->bootEloquent(); $manager->bootEloquent();
@ -46,7 +47,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider
$this->container->alias(ConnectionResolverInterface::class, 'db'); $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); $resolver = $container->make(ConnectionResolverInterface::class);
return $resolver->connection(); return $resolver->connection();
@ -55,7 +56,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider
$this->container->alias(ConnectionInterface::class, 'db.connection'); $this->container->alias(ConnectionInterface::class, 'db.connection');
$this->container->alias(ConnectionInterface::class, 'flarum.db'); $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'); return new DatabaseMigrationRepository($container['flarum.db'], 'migrations');
}); });
@ -64,15 +65,12 @@ class DatabaseServiceProvider extends AbstractServiceProvider
}); });
} }
/** public function boot(Container $container)
* {@inheritdoc}
*/
public function boot()
{ {
AbstractModel::setConnectionResolver($this->container->make(ConnectionResolverInterface::class)); AbstractModel::setConnectionResolver($container->make(ConnectionResolverInterface::class));
AbstractModel::setEventDispatcher($this->container->make('events')); 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) { $modelClass::saving(function ($instance) use ($checkers) {
foreach ($checkers as $checker) { foreach ($checkers as $checker) {
if ($checker($instance) === true) { if ($checker($instance) === true) {

View File

@ -12,16 +12,12 @@ namespace Flarum\Discussion;
use Flarum\Discussion\Access\ScopeDiscussionVisibility; use Flarum\Discussion\Access\ScopeDiscussionVisibility;
use Flarum\Discussion\Event\Renamed; use Flarum\Discussion\Event\Renamed;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Events\Dispatcher;
class DiscussionServiceProvider extends AbstractServiceProvider class DiscussionServiceProvider extends AbstractServiceProvider
{ {
/** public function boot(Dispatcher $events)
* {@inheritdoc}
*/
public function boot()
{ {
$events = $this->container->make('events');
$events->subscribe(DiscussionMetadataUpdater::class); $events->subscribe(DiscussionMetadataUpdater::class);
$events->listen( $events->listen(

View File

@ -11,6 +11,7 @@ namespace Flarum\Extension;
use Flarum\Extension\Event\Disabling; use Flarum\Extension\Event\Disabling;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Events\Dispatcher;
class ExtensionServiceProvider extends AbstractServiceProvider class ExtensionServiceProvider extends AbstractServiceProvider
{ {
@ -34,9 +35,9 @@ class ExtensionServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Dispatcher $events)
{ {
$this->container->make('events')->listen( $events->listen(
Disabling::class, Disabling::class,
DefaultLanguagePackGuard::class DefaultLanguagePackGuard::class
); );

View File

@ -12,6 +12,7 @@ namespace Flarum\Filesystem;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths; use Flarum\Foundation\Paths;
use Flarum\Http\UrlGenerator; use Flarum\Http\UrlGenerator;
use Illuminate\Contracts\Container\Container;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
class FilesystemServiceProvider extends AbstractServiceProvider class FilesystemServiceProvider extends AbstractServiceProvider
@ -46,17 +47,17 @@ class FilesystemServiceProvider extends AbstractServiceProvider
return []; return [];
}); });
$this->container->singleton('flarum.filesystem.resolved_drivers', function () { $this->container->singleton('flarum.filesystem.resolved_drivers', function (Container $container) {
return array_map(function ($driverClass) { return array_map(function ($driverClass) use ($container) {
return $this->container->make($driverClass); return $container->make($driverClass);
}, $this->container->make('flarum.filesystem.drivers')); }, $container->make('flarum.filesystem.drivers'));
}); });
$this->container->singleton('filesystem', function () { $this->container->singleton('filesystem', function (Container $container) {
return new FilesystemManager( return new FilesystemManager(
$this->container, $container,
$this->container->make('flarum.filesystem.disks'), $container->make('flarum.filesystem.disks'),
$this->container->make('flarum.filesystem.resolved_drivers') $container->make('flarum.filesystem.resolved_drivers')
); );
}); });
} }

View File

@ -17,6 +17,7 @@ use Flarum\Post\Filter as PostFilter;
use Flarum\Post\Filter\PostFilterer; use Flarum\Post\Filter\PostFilterer;
use Flarum\User\Filter\UserFilterer; use Flarum\User\Filter\UserFilterer;
use Flarum\User\Query as UserQuery; use Flarum\User\Query as UserQuery;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
class FilterServiceProvider extends AbstractServiceProvider 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, // 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 // 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'); $filters = $this->container->make('flarum.filter.filters');
foreach ($filters as $filterer => $filterClasses) { foreach ($filters as $filterer => $filterClasses) {
$this->container $container
->when($filterer) ->when($filterer)
->needs('$filters') ->needs('$filters')
->give(function () use ($filterClasses) { ->give(function () use ($filterClasses) {
@ -77,13 +78,13 @@ class FilterServiceProvider extends AbstractServiceProvider
return $compiled; return $compiled;
}); });
$this->container $container
->when($filterer) ->when($filterer)
->needs('$filterMutators') ->needs('$filterMutators')
->give(function () use ($filterer) { ->give(function () use ($container, $filterer) {
return array_map(function ($filterMutatorClass) { return array_map(function ($filterMutatorClass) {
return ContainerUtil::wrapCallback($filterMutatorClass, $this->container); 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, []));
}); });
} }
} }

View File

@ -24,7 +24,7 @@ class FormatterServiceProvider extends AbstractServiceProvider
$this->container->singleton('flarum.formatter', function (Container $container) { $this->container->singleton('flarum.formatter', function (Container $container) {
return new Formatter( return new Formatter(
new Repository($container->make('cache.filestore')), new Repository($container->make('cache.filestore')),
$this->container[Paths::class]->storage.'/formatter' $container[Paths::class]->storage.'/formatter'
); );
}); });

View File

@ -31,6 +31,9 @@ use Flarum\Locale\LocaleManager;
use Flarum\Settings\Event\Saved; use Flarum\Settings\Event\Saved;
use Flarum\Settings\Event\Saving; use Flarum\Settings\Event\Saving;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\View\Factory;
use Laminas\Stratigility\MiddlewarePipe; use Laminas\Stratigility\MiddlewarePipe;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -41,19 +44,19 @@ class ForumServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->extend(UrlGenerator::class, function (UrlGenerator $url) { $this->container->extend(UrlGenerator::class, function (UrlGenerator $url, Container $container) {
return $url->addCollection('forum', $this->container->make('flarum.forum.routes')); 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; $routes = new RouteCollection;
$this->populateRoutes($routes); $this->populateRoutes($routes, $container);
return $routes; return $routes;
}); });
$this->container->afterResolving('flarum.forum.routes', function (RouteCollection $routes) { $this->container->afterResolving('flarum.forum.routes', function (RouteCollection $routes, Container $container) {
$this->setDefaultRoute($routes); $this->setDefaultRoute($routes, $container);
}); });
$this->container->singleton('flarum.forum.middleware', function () { $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( return new HttpMiddleware\HandleErrors(
$this->container->make(Registry::class), $container->make(Registry::class),
$this->container['flarum.config']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(ViewFormatter::class), $container['flarum.config']->inDebugMode() ? $container->make(WhoopsFormatter::class) : $container->make(ViewFormatter::class),
$this->container->tagged(Reporter::class) $container->tagged(Reporter::class)
); );
}); });
$this->container->bind('flarum.forum.route_resolver', function () { $this->container->bind('flarum.forum.route_resolver', function (Container $container) {
return new HttpMiddleware\ResolveRoute($this->container->make('flarum.forum.routes')); 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; $pipe = new MiddlewarePipe;
foreach ($this->container->make('flarum.forum.middleware') as $middleware) { foreach ($container->make('flarum.forum.middleware') as $middleware) {
$pipe->pipe($this->container->make($middleware)); $pipe->pipe($container->make($middleware));
} }
$pipe->pipe(new HttpMiddleware\ExecuteRoute()); $pipe->pipe(new HttpMiddleware\ExecuteRoute());
@ -97,55 +100,50 @@ class ForumServiceProvider extends AbstractServiceProvider
return $pipe; return $pipe;
}); });
$this->container->bind('flarum.assets.forum', function () { $this->container->bind('flarum.assets.forum', function (Container $container) {
/** @var Assets $assets */ /** @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->addFile(__DIR__.'/../../js/dist/forum.js');
$sources->addString(function () { $sources->addString(function () use ($container) {
return $this->container->make(Formatter::class)->getJs(); 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->addFile(__DIR__.'/../../less/forum.less');
$sources->addString(function () { $sources->addString(function () use ($container) {
return $this->container->make(SettingsRepositoryInterface::class)->get('custom_less', ''); return $container->make(SettingsRepositoryInterface::class)->get('custom_less', '');
}); });
}); });
$this->container->make(AddTranslations::class)->forFrontend('forum')->to($assets); $container->make(AddTranslations::class)->forFrontend('forum')->to($assets);
$this->container->make(AddLocaleAssets::class)->to($assets); $container->make(AddLocaleAssets::class)->to($assets);
return $assets; return $assets;
}); });
$this->container->bind('flarum.frontend.forum', function () { $this->container->bind('flarum.frontend.forum', function (Container $container) {
return $this->container->make('flarum.frontend.factory')('forum'); return $container->make('flarum.frontend.factory')('forum');
}); });
} }
/** public function boot(Container $container, Dispatcher $events, Factory $view)
* {@inheritdoc}
*/
public function boot()
{ {
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum'); $this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum');
$this->container->make('view')->share([ $view->share([
'translator' => $this->container->make(TranslatorInterface::class), 'translator' => $container->make(TranslatorInterface::class),
'settings' => $this->container->make(SettingsRepositoryInterface::class) 'settings' => $container->make(SettingsRepositoryInterface::class)
]); ]);
$events = $this->container->make('events');
$events->listen( $events->listen(
[Enabled::class, Disabled::class, ClearingCache::class], [Enabled::class, Disabled::class, ClearingCache::class],
function () { function () use ($container) {
$recompile = new RecompileFrontendAssets( $recompile = new RecompileFrontendAssets(
$this->container->make('flarum.assets.forum'), $container->make('flarum.assets.forum'),
$this->container->make(LocaleManager::class) $container->make(LocaleManager::class)
); );
$recompile->flush(); $recompile->flush();
} }
@ -153,17 +151,17 @@ class ForumServiceProvider extends AbstractServiceProvider
$events->listen( $events->listen(
Saved::class, Saved::class,
function (Saved $event) { function (Saved $event) use ($container) {
$recompile = new RecompileFrontendAssets( $recompile = new RecompileFrontendAssets(
$this->container->make('flarum.assets.forum'), $container->make('flarum.assets.forum'),
$this->container->make(LocaleManager::class) $container->make(LocaleManager::class)
); );
$recompile->whenSettingsSaved($event); $recompile->whenSettingsSaved($event);
$validator = new ValidateCustomLess( $validator = new ValidateCustomLess(
$this->container->make('flarum.assets.forum'), $container->make('flarum.assets.forum'),
$this->container->make('flarum.locales'), $container->make('flarum.locales'),
$this->container $container
); );
$validator->whenSettingsSaved($event); $validator->whenSettingsSaved($event);
} }
@ -171,11 +169,11 @@ class ForumServiceProvider extends AbstractServiceProvider
$events->listen( $events->listen(
Saving::class, Saving::class,
function (Saving $event) { function (Saving $event) use ($container) {
$validator = new ValidateCustomLess( $validator = new ValidateCustomLess(
$this->container->make('flarum.assets.forum'), $container->make('flarum.assets.forum'),
$this->container->make('flarum.locales'), $container->make('flarum.locales'),
$this->container $container
); );
$validator->whenSettingsSaving($event); $validator->whenSettingsSaving($event);
} }
@ -186,10 +184,11 @@ class ForumServiceProvider extends AbstractServiceProvider
* Populate the forum client routes. * Populate the forum client routes.
* *
* @param RouteCollection $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 = include __DIR__.'/routes.php';
$callback($routes, $factory); $callback($routes, $factory);
@ -199,11 +198,12 @@ class ForumServiceProvider extends AbstractServiceProvider
* Determine the default route. * Determine the default route.
* *
* @param RouteCollection $routes * @param RouteCollection $routes
* @param Container $container
*/ */
protected function setDefaultRoute(RouteCollection $routes) protected function setDefaultRoute(RouteCollection $routes, Container $container)
{ {
$factory = $this->container->make(RouteHandlerFactory::class); $factory = $container->make(RouteHandlerFactory::class);
$defaultRoute = $this->container->make('flarum.settings')->get('default_route'); $defaultRoute = $container->make('flarum.settings')->get('default_route');
if (isset($routes->getRouteData()[0]['GET'][$defaultRoute]['handler'])) { if (isset($routes->getRouteData()[0]['GET'][$defaultRoute]['handler'])) {
$toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler']; $toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute]['handler'];

View File

@ -14,19 +14,20 @@ use Flarum\Foundation\Paths;
use Flarum\Frontend\Compiler\Source\SourceCollector; use Flarum\Frontend\Compiler\Source\SourceCollector;
use Flarum\Http\UrlGenerator; use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\Factory as ViewFactory;
class FrontendServiceProvider extends AbstractServiceProvider class FrontendServiceProvider extends AbstractServiceProvider
{ {
public function register() public function register()
{ {
$this->container->singleton('flarum.assets.factory', function () { $this->container->singleton('flarum.assets.factory', function (Container $container) {
return function (string $name) { return function (string $name) use ($container) {
$paths = $this->container[Paths::class]; $paths = $container[Paths::class];
$assets = new Assets( $assets = new Assets(
$name, $name,
$this->container->make('filesystem')->disk('flarum-assets'), $container->make('filesystem')->disk('flarum-assets'),
$paths->storage $paths->storage
); );
@ -41,17 +42,17 @@ class FrontendServiceProvider extends AbstractServiceProvider
}; };
}); });
$this->container->singleton('flarum.frontend.factory', function () { $this->container->singleton('flarum.frontend.factory', function (Container $container) {
return function (string $name) { return function (string $name) use ($container) {
$frontend = $this->container->make(Frontend::class); $frontend = $container->make(Frontend::class);
$frontend->content(function (Document $document) use ($name) { $frontend->content(function (Document $document) use ($name) {
$document->layoutView = 'flarum::frontend.'.$name; $document->layoutView = 'flarum::frontend.'.$name;
}); });
$frontend->content($this->container->make(Content\Assets::class)->forFrontend($name)); $frontend->content($container->make(Content\Assets::class)->forFrontend($name));
$frontend->content($this->container->make(Content\CorePayload::class)); $frontend->content($container->make(Content\CorePayload::class));
$frontend->content($this->container->make(Content\Meta::class)); $frontend->content($container->make(Content\Meta::class));
return $frontend; return $frontend;
}; };
@ -61,13 +62,13 @@ class FrontendServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Container $container, ViewFactory $views)
{ {
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum'); $this->loadViewsFrom(__DIR__.'/../../views', 'flarum');
$this->container->make(ViewFactory::class)->share([ $views->share([
'translator' => $this->container->make('translator'), 'translator' => $container->make('translator'),
'url' => $this->container->make(UrlGenerator::class) 'url' => $container->make(UrlGenerator::class)
]); ]);
} }

View File

@ -16,6 +16,7 @@ use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\IdSlugDriver; use Flarum\User\IdSlugDriver;
use Flarum\User\User; use Flarum\User\User;
use Flarum\User\UsernameSlugDriver; use Flarum\User\UsernameSlugDriver;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
class HttpServiceProvider extends AbstractServiceProvider class HttpServiceProvider extends AbstractServiceProvider
@ -29,7 +30,7 @@ class HttpServiceProvider extends AbstractServiceProvider
return ['token']; 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')); return new Middleware\CheckCsrfToken($container->make('flarum.http.csrfExemptPaths'));
}); });
@ -45,23 +46,23 @@ class HttpServiceProvider extends AbstractServiceProvider
]; ];
}); });
$this->container->singleton('flarum.http.selectedSlugDrivers', function () { $this->container->singleton('flarum.http.selectedSlugDrivers', function (Container $container) {
$settings = $this->container->make(SettingsRepositoryInterface::class); $settings = $container->make(SettingsRepositoryInterface::class);
$compiledDrivers = []; $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'); $driverKey = $settings->get("slug_driver_$resourceClass", 'default');
$driverClass = Arr::get($resourceDrivers, $driverKey, $resourceDrivers['default']); $driverClass = Arr::get($resourceDrivers, $driverKey, $resourceDrivers['default']);
$compiledDrivers[$resourceClass] = $this->container->make($driverClass); $compiledDrivers[$resourceClass] = $container->make($driverClass);
} }
return $compiledDrivers; return $compiledDrivers;
}); });
$this->container->bind(SlugManager::class, function () { $this->container->bind(SlugManager::class, function (Container $container) {
return new SlugManager($this->container->make('flarum.http.selectedSlugDrivers')); return new SlugManager($container->make('flarum.http.selectedSlugDrivers'));
}); });
} }

View File

@ -12,6 +12,7 @@ namespace Flarum\Install;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Http\RouteCollection; use Flarum\Http\RouteCollection;
use Flarum\Http\RouteHandlerFactory; use Flarum\Http\RouteHandlerFactory;
use Illuminate\Contracts\Container\Container;
class InstallServiceProvider extends AbstractServiceProvider class InstallServiceProvider extends AbstractServiceProvider
{ {
@ -28,20 +29,19 @@ class InstallServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Container $container, RouteHandlerFactory $route)
{ {
$this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.install'); $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( $routes->get(
'/{path:.*}', '/{path:.*}',
'index', 'index',

View File

@ -12,6 +12,7 @@ namespace Flarum\Locale;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths; use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -22,25 +23,25 @@ class LocaleServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->singleton(LocaleManager::class, function () { $this->container->singleton(LocaleManager::class, function (Container $container) {
$locales = new LocaleManager( $locales = new LocaleManager(
$this->container->make('translator'), $container->make('translator'),
$this->getCacheDir() $this->getCacheDir($container)
); );
$locales->addLocale($this->getDefaultLocale(), 'Default'); $locales->addLocale($this->getDefaultLocale($container), 'Default');
return $locales; return $locales;
}); });
$this->container->alias(LocaleManager::class, 'flarum.locales'); $this->container->alias(LocaleManager::class, 'flarum.locales');
$this->container->singleton('translator', function () { $this->container->singleton('translator', function (Container $container) {
$translator = new Translator( $translator = new Translator(
$this->getDefaultLocale(), $this->getDefaultLocale($container),
null, null,
$this->getCacheDir(), $this->getCacheDir($container),
$this->container['flarum.debug'] $container['flarum.debug']
); );
$translator->setFallbackLocales(['en']); $translator->setFallbackLocales(['en']);
@ -56,15 +57,15 @@ class LocaleServiceProvider extends AbstractServiceProvider
$this->container->alias('translator', TranslatorInterface::class); $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'); 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';
} }
} }

View File

@ -11,6 +11,7 @@ namespace Flarum\Mail;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Validation\Factory; use Illuminate\Contracts\Validation\Factory;
use Illuminate\Mail\Mailer; use Illuminate\Mail\Mailer;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
@ -29,31 +30,31 @@ class MailServiceProvider extends AbstractServiceProvider
]; ];
}); });
$this->container->singleton('mail.driver', function () { $this->container->singleton('mail.driver', function (Container $container) {
$configured = $this->container->make('flarum.mail.configured_driver'); $configured = $container->make('flarum.mail.configured_driver');
$settings = $this->container->make(SettingsRepositoryInterface::class); $settings = $container->make(SettingsRepositoryInterface::class);
$validator = $this->container->make(Factory::class); $validator = $container->make(Factory::class);
return $configured->validate($settings, $validator)->any() return $configured->validate($settings, $validator)->any()
? $this->container->make(NullDriver::class) ? $container->make(NullDriver::class)
: $configured; : $configured;
}); });
$this->container->alias('mail.driver', DriverInterface::class); $this->container->alias('mail.driver', DriverInterface::class);
$this->container->singleton('flarum.mail.configured_driver', function () { $this->container->singleton('flarum.mail.configured_driver', function (Container $container) {
$drivers = $this->container->make('mail.supported_drivers'); $drivers = $container->make('mail.supported_drivers');
$settings = $this->container->make(SettingsRepositoryInterface::class); $settings = $container->make(SettingsRepositoryInterface::class);
$driverName = $settings->get('mail_driver'); $driverName = $settings->get('mail_driver');
$driverClass = Arr::get($drivers, $driverName); $driverClass = Arr::get($drivers, $driverName);
return $driverClass return $driverClass
? $this->container->make($driverClass) ? $container->make($driverClass)
: $this->container->make(NullDriver::class); : $container->make(NullDriver::class);
}); });
$this->container->singleton('swift.mailer', function ($container) { $this->container->singleton('swift.mailer', function (Container $container) {
return new Swift_Mailer( return new Swift_Mailer(
$container->make('mail.driver')->buildTransport( $container->make('mail.driver')->buildTransport(
$container->make(SettingsRepositoryInterface::class) $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( $mailer = new Mailer(
'flarum', 'flarum',
$container['view'], $container['view'],

View File

@ -11,6 +11,7 @@ namespace Flarum\Notification;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint;
use Illuminate\Contracts\Container\Container;
class NotificationServiceProvider extends AbstractServiceProvider class NotificationServiceProvider extends AbstractServiceProvider
{ {
@ -36,28 +37,28 @@ class NotificationServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Container $container)
{ {
$this->setNotificationDrivers(); $this->setNotificationDrivers($container);
$this->setNotificationTypes(); $this->setNotificationTypes($container);
} }
/** /**
* Register notification drivers. * Register notification drivers.
*/ */
protected function setNotificationDrivers() protected function setNotificationDrivers(Container $container)
{ {
foreach ($this->container->make('flarum.notification.drivers') as $driverName => $driver) { foreach ($container->make('flarum.notification.drivers') as $driverName => $driver) {
NotificationSyncer::addNotificationDriver($driverName, $this->container->make($driver)); NotificationSyncer::addNotificationDriver($driverName, $container->make($driver));
} }
} }
/** /**
* Register notification types. * 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) { foreach ($blueprints as $blueprint => $driversEnabledByDefault) {
$this->addType($blueprint, $driversEnabledByDefault); $this->addType($blueprint, $driversEnabledByDefault);

View File

@ -10,6 +10,7 @@
namespace Flarum\Post; namespace Flarum\Post;
use DateTime; use DateTime;
use Flarum\Formatter\Formatter;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Http\RequestUtil; use Flarum\Http\RequestUtil;
use Flarum\Post\Access\ScopePostVisibility; use Flarum\Post\Access\ScopePostVisibility;
@ -42,12 +43,9 @@ class PostServiceProvider extends AbstractServiceProvider
}); });
} }
/** public function boot(Formatter $formatter)
* {@inheritdoc}
*/
public function boot()
{ {
CommentPost::setFormatter($this->container->make('flarum.formatter')); CommentPost::setFormatter($formatter);
$this->setPostTypes(); $this->setPostTypes();

View File

@ -15,7 +15,9 @@ use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\Paths; use Flarum\Foundation\Paths;
use Illuminate\Contracts\Cache\Factory as CacheFactory; use Illuminate\Contracts\Cache\Factory as CacheFactory;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling; use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Queue\Factory; use Illuminate\Contracts\Queue\Factory;
use Illuminate\Contracts\Queue\Queue; use Illuminate\Contracts\Queue\Queue;
use Illuminate\Queue\Connectors\ConnectorInterface; use Illuminate\Queue\Connectors\ConnectorInterface;
@ -42,26 +44,26 @@ class QueueServiceProvider extends AbstractServiceProvider
{ {
// Register a simple connection factory that always returns the same // Register a simple connection factory that always returns the same
// connection, as that is enough for our purposes. // 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 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 // Extensions can override this binding if they want to make Flarum use
// a different queuing backend. // 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 = new SyncQueue;
$queue->setContainer($container); $queue->setContainer($container);
return $queue; return $queue;
}); });
$this->container->singleton(ExceptionHandling::class, function ($container) { $this->container->singleton(ExceptionHandling::class, function (Container $container) {
return new ExceptionHandler($container['log']); return new ExceptionHandler($container['log']);
}); });
$this->container->singleton(Worker::class, function ($container) { $this->container->singleton(Worker::class, function (Container $container) {
/** @var Config $config */ /** @var Config $config */
$config = $container->make(Config::class); $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 // Override the Laravel native Listener, so that we can ignore the environment
// option and force the binary to flarum. // option and force the binary to flarum.
$this->container->singleton(QueueListener::class, function ($container) { $this->container->singleton(QueueListener::class, function (Container $container) {
return new Listener($container[Paths::class]->base); return new Listener($container->make(Paths::class)->base);
}); });
// Bind a simple cache manager that returns the cache store. // 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 { return new class($container) implements CacheFactory {
public function __construct($container) public function __construct($container)
{ {
@ -124,8 +126,8 @@ class QueueServiceProvider extends AbstractServiceProvider
protected function registerCommands() protected function registerCommands()
{ {
$this->container->extend('flarum.console.commands', function ($commands) { $this->container->extend('flarum.console.commands', function ($commands, Container $container) {
$queue = $this->container->make(Queue::class); $queue = $container->make(Queue::class);
// There is no need to have the queue commands when using the sync driver. // There is no need to have the queue commands when using the sync driver.
if ($queue instanceof SyncQueue) { 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 */ /** @var Registry $registry */
$registry = $this->container->make(Registry::class); $registry = $container->make(Registry::class);
$error = $registry->handle($event->exception); $error = $registry->handle($event->exception);
/** @var Reporter[] $reporters */ /** @var Reporter[] $reporters */
$reporters = $this->container->tagged(Reporter::class); $reporters = $container->tagged(Reporter::class);
if ($error->shouldBeReported()) { if ($error->shouldBeReported()) {
foreach ($reporters as $reporter) { foreach ($reporters as $reporter) {

View File

@ -17,6 +17,7 @@ use Flarum\Foundation\ContainerUtil;
use Flarum\User\Query as UserQuery; use Flarum\User\Query as UserQuery;
use Flarum\User\Search\Gambit\FulltextGambit as UserFulltextGambit; use Flarum\User\Search\Gambit\FulltextGambit as UserFulltextGambit;
use Flarum\User\Search\UserSearcher; use Flarum\User\Search\UserSearcher;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
class SearchServiceProvider extends AbstractServiceProvider class SearchServiceProvider extends AbstractServiceProvider
@ -53,31 +54,28 @@ class SearchServiceProvider extends AbstractServiceProvider
}); });
} }
/** public function boot(Container $container)
* {@inheritdoc}
*/
public function boot()
{ {
$fullTextGambits = $this->container->make('flarum.simple_search.fulltext_gambits'); $fullTextGambits = $container->make('flarum.simple_search.fulltext_gambits');
foreach ($fullTextGambits as $searcher => $fullTextGambitClass) { foreach ($fullTextGambits as $searcher => $fullTextGambitClass) {
$this->container $container
->when($searcher) ->when($searcher)
->needs(GambitManager::class) ->needs(GambitManager::class)
->give(function () use ($searcher, $fullTextGambitClass) { ->give(function () use ($container, $searcher, $fullTextGambitClass) {
$gambitManager = new GambitManager($this->container->make($fullTextGambitClass)); $gambitManager = new GambitManager($container->make($fullTextGambitClass));
foreach (Arr::get($this->container->make('flarum.simple_search.gambits'), $searcher, []) as $gambit) { foreach (Arr::get($container->make('flarum.simple_search.gambits'), $searcher, []) as $gambit) {
$gambitManager->add($this->container->make($gambit)); $gambitManager->add($container->make($gambit));
} }
return $gambitManager; return $gambitManager;
}); });
$this->container $container
->when($searcher) ->when($searcher)
->needs('$searchMutators') ->needs('$searchMutators')
->give(function () use ($searcher) { ->give(function () use ($container, $searcher) {
$searchMutators = Arr::get($this->container->make('flarum.simple_search.search_mutators'), $searcher, []); $searchMutators = Arr::get($container->make('flarum.simple_search.search_mutators'), $searcher, []);
return array_map(function ($mutator) { return array_map(function ($mutator) {
return ContainerUtil::wrapCallback($mutator, $this->container); return ContainerUtil::wrapCallback($mutator, $this->container);

View File

@ -10,6 +10,7 @@
namespace Flarum\Settings; namespace Flarum\Settings;
use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
class SettingsServiceProvider extends AbstractServiceProvider class SettingsServiceProvider extends AbstractServiceProvider
@ -19,10 +20,10 @@ class SettingsServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->singleton(SettingsRepositoryInterface::class, function () { $this->container->singleton(SettingsRepositoryInterface::class, function (Container $container) {
return new MemoryCacheSettingsRepository( return new MemoryCacheSettingsRepository(
new DatabaseSettingsRepository( new DatabaseSettingsRepository(
$this->container->make(ConnectionInterface::class) $container->make(ConnectionInterface::class)
) )
); );
}); });

View File

@ -20,17 +20,14 @@ class UpdateServiceProvider extends AbstractServiceProvider
*/ */
public function register() public function register()
{ {
$this->container->singleton('flarum.update.routes', function () { $this->container->singleton('flarum.update.routes', function (RouteHandlerFactory $route) {
$routes = new RouteCollection; $routes = new RouteCollection;
$this->populateRoutes($routes); $this->populateRoutes($routes, $route);
return $routes; return $routes;
}); });
} }
/**
* {@inheritdoc}
*/
public function boot() public function boot()
{ {
$this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.update'); $this->loadViewsFrom(__DIR__.'/../../views/install', 'flarum.update');
@ -38,11 +35,10 @@ class UpdateServiceProvider extends AbstractServiceProvider
/** /**
* @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( $routes->get(
'/{path:.*}', '/{path:.*}',
'index', 'index',

View File

@ -24,6 +24,8 @@ use Flarum\User\DisplayName\UsernameDriver;
use Flarum\User\Event\EmailChangeRequested; use Flarum\User\Event\EmailChangeRequested;
use Flarum\User\Event\Registered; use Flarum\User\Event\Registered;
use Flarum\User\Event\Saving; use Flarum\User\Event\Saving;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
class UserServiceProvider extends AbstractServiceProvider class UserServiceProvider extends AbstractServiceProvider
@ -59,16 +61,16 @@ class UserServiceProvider extends AbstractServiceProvider
]; ];
}); });
$this->container->singleton('flarum.user.display_name.driver', function () { $this->container->singleton('flarum.user.display_name.driver', function (Container $container) {
$drivers = $this->container->make('flarum.user.display_name.supported_drivers'); $drivers = $container->make('flarum.user.display_name.supported_drivers');
$settings = $this->container->make(SettingsRepositoryInterface::class); $settings = $container->make(SettingsRepositoryInterface::class);
$driverName = $settings->get('display_name_driver', ''); $driverName = $settings->get('display_name_driver', '');
$driverClass = Arr::get($drivers, $driverName); $driverClass = Arr::get($drivers, $driverName);
return $driverClass return $driverClass
? $this->container->make($driverClass) ? $container->make($driverClass)
: $this->container->make(UsernameDriver::class); : $container->make(UsernameDriver::class);
}); });
$this->container->alias('flarum.user.display_name.driver', DriverInterface::class); $this->container->alias('flarum.user.display_name.driver', DriverInterface::class);
@ -76,10 +78,10 @@ class UserServiceProvider extends AbstractServiceProvider
protected function registerPasswordCheckers() protected function registerPasswordCheckers()
{ {
$this->container->singleton('flarum.user.password_checkers', function () { $this->container->singleton('flarum.user.password_checkers', function (Container $container) {
return [ return [
'standard' => function (User $user, $password) { 'standard' => function (User $user, $password) use ($container) {
if ($this->container->make('hash')->check($password, $user->password)) { if ($container->make('hash')->check($password, $user->password)) {
return true; return true;
} }
} }
@ -90,18 +92,16 @@ class UserServiceProvider extends AbstractServiceProvider
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot() public function boot(Container $container, Dispatcher $events)
{ {
foreach ($this->container->make('flarum.user.group_processors') as $callback) { foreach ($container->make('flarum.user.group_processors') as $callback) {
User::addGroupProcessor(ContainerUtil::wrapCallback($callback, $this->container)); User::addGroupProcessor(ContainerUtil::wrapCallback($callback, $container));
} }
User::setHasher($this->container->make('hash')); User::setHasher($container->make('hash'));
User::setPasswordCheckers($this->container->make('flarum.user.password_checkers')); User::setPasswordCheckers($container->make('flarum.user.password_checkers'));
User::setGate($this->container->makeWith(Access\Gate::class, ['policyClasses' => $this->container->make('flarum.policies')])); User::setGate($container->makeWith(Access\Gate::class, ['policyClasses' => $container->make('flarum.policies')]));
User::setDisplayNameDriver($this->container->make('flarum.user.display_name.driver')); User::setDisplayNameDriver($container->make('flarum.user.display_name.driver'));
$events = $this->container->make('events');
$events->listen(Saving::class, SelfDemotionGuard::class); $events->listen(Saving::class, SelfDemotionGuard::class);
$events->listen(Registered::class, AccountActivationMailer::class); $events->listen(Registered::class, AccountActivationMailer::class);