1
0
mirror of https://github.com/flarum/core.git synced 2025-08-18 06:11:23 +02:00

Use Container contract where easily possible

Less usages of the Application god-class simplifies splitting it up.

Refs #2055.
This commit is contained in:
Franz Liedke
2020-04-21 16:47:10 +02:00
parent f0f301c5f4
commit 3f0f89afb1
5 changed files with 47 additions and 33 deletions

View File

@@ -9,9 +9,9 @@
namespace Flarum\Console\Event;
use Flarum\Foundation\Application;
use Illuminate\Console\Command;
use Symfony\Component\Console\Application as ConsoleApplication;
use Illuminate\Contracts\Container\Container;
use Symfony\Component\Console\Application;
/**
* @deprecated
@@ -19,22 +19,22 @@ use Symfony\Component\Console\Application as ConsoleApplication;
class Configuring
{
/**
* @var Application
* @var Container
*/
public $app;
/**
* @var ConsoleApplication
* @var Application
*/
public $console;
/**
* @param Application $app
* @param ConsoleApplication $console
* @param Container $container
* @param Application $console
*/
public function __construct(Application $app, ConsoleApplication $console)
public function __construct(Container $container, Application $console)
{
$this->app = $app;
$this->app = $container;
$this->console = $console;
}

View File

@@ -10,12 +10,12 @@
namespace Flarum\Console;
use Flarum\Console\Event\Configuring;
use Flarum\Foundation\Application;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\SiteInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -33,7 +33,7 @@ class Server
{
$app = $this->site->bootApp();
$console = new ConsoleApplication('Flarum', Application::VERSION);
$console = new Application('Flarum', \Flarum\Foundation\Application::VERSION);
foreach ($app->getConsoleCommands() as $command) {
$console->add($command);
@@ -47,29 +47,28 @@ class Server
/**
* @deprecated
*/
private function extend(ConsoleApplication $console)
private function extend(Application $console)
{
$app = Application::getInstance();
$container = \Illuminate\Container\Container::getInstance();
$this->handleErrors($app, $console);
$this->handleErrors($container, $console);
$events = $app->make(Dispatcher::class);
$events->dispatch(new Configuring($app, $console));
$events = $container->make(Dispatcher::class);
$events->dispatch(new Configuring($container, $console));
}
private function handleErrors(Application $app, ConsoleApplication $console)
private function handleErrors(Container $container, Application $console)
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($app) {
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($container) {
/** @var Registry $registry */
$registry = $app->make(Registry::class);
$registry = $container->make(Registry::class);
$error = $registry->handle($event->getError());
/** @var Reporter[] $reporters */
$reporters = $app->tagged(Reporter::class);
$reporters = $container->tagged(Reporter::class);
if ($error->shouldBeReported()) {
foreach ($reporters as $reporter) {