1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 13:40:20 +02:00

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 40b47de9e1
commit fcb5778705
23 changed files with 246 additions and 245 deletions

View File

@@ -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) {