mirror of
https://github.com/flarum/core.git
synced 2025-05-07 07:55:44 +02:00
added ability to re-use existing error handling stack
This commit is contained in:
parent
a0ace316e8
commit
21f54c5562
@ -32,21 +32,15 @@ class Configuring
|
|||||||
* @var ConsoleApplication
|
* @var ConsoleApplication
|
||||||
*/
|
*/
|
||||||
public $console;
|
public $console;
|
||||||
/**
|
|
||||||
* @var EventDispatcher
|
|
||||||
*/
|
|
||||||
public $eventDispatcher;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Application $app
|
* @param Application $app
|
||||||
* @param ConsoleApplication $console
|
* @param ConsoleApplication $console
|
||||||
* @param EventDispatcher $eventDispatcher
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Application $app, ConsoleApplication $console, EventDispatcher $eventDispatcher)
|
public function __construct(Application $app, ConsoleApplication $console)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->console = $console;
|
$this->console = $console;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,9 +13,13 @@ namespace Flarum\Console;
|
|||||||
|
|
||||||
use Flarum\Console\Event\Configuring;
|
use Flarum\Console\Event\Configuring;
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
|
use Flarum\Foundation\ErrorHandling\Reporter;
|
||||||
use Flarum\Foundation\SiteInterface;
|
use Flarum\Foundation\SiteInterface;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||||
|
use Symfony\Component\Console\ConsoleEvents;
|
||||||
|
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
|
|
||||||
class Server
|
class Server
|
||||||
@ -46,8 +50,31 @@ class Server
|
|||||||
{
|
{
|
||||||
$app = Application::getInstance();
|
$app = Application::getInstance();
|
||||||
|
|
||||||
|
$this->handleErrors($app, $console);
|
||||||
|
|
||||||
$events = $app->make(Dispatcher::class);
|
$events = $app->make(Dispatcher::class);
|
||||||
$events->fire(new Configuring($app, $console, $dispatcher = new EventDispatcher()));
|
|
||||||
|
$events->fire(new Configuring($app, $console));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleErrors(Application $app, ConsoleApplication $console)
|
||||||
|
{
|
||||||
|
$dispatcher = new EventDispatcher();
|
||||||
|
|
||||||
|
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($app) {
|
||||||
|
/** @var Registry $registry */
|
||||||
|
$registry = $app->make(Registry::class);
|
||||||
|
|
||||||
|
$error = $registry->handle($event->getError());
|
||||||
|
|
||||||
|
$reporters = $app->tagged(Reporter::class);
|
||||||
|
|
||||||
|
if ($error->shouldBeReported()) {
|
||||||
|
foreach ($reporters as $reporter) {
|
||||||
|
$reporter->report($error->getException());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$console->setDispatcher($dispatcher);
|
$console->setDispatcher($dispatcher);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user