engelsystem/src/Exceptions/ExceptionsServiceProvider.php

59 lines
1.8 KiB
PHP
Raw Normal View History

2017-10-31 13:40:13 +01:00
<?php
namespace Engelsystem\Exceptions;
use Engelsystem\Container\ServiceProvider;
2017-11-24 15:08:43 +01:00
use Engelsystem\Exceptions\Handlers\HandlerInterface;
use Engelsystem\Exceptions\Handlers\Legacy;
use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
use Engelsystem\Exceptions\Handlers\Whoops;
use Whoops\Run as WhoopsRunner;
2017-10-31 13:40:13 +01:00
class ExceptionsServiceProvider extends ServiceProvider
{
public function register()
{
2017-11-24 15:08:43 +01:00
$errorHandler = $this->app->make(Handler::class);
$this->addProductionHandler($errorHandler);
$this->addDevelopmentHandler($errorHandler);
2017-10-31 13:40:13 +01:00
$this->app->instance('error.handler', $errorHandler);
2017-11-20 17:08:05 +01:00
$this->app->bind(Handler::class, 'error.handler');
2017-11-24 15:08:43 +01:00
$errorHandler->register();
}
public function boot()
{
/** @var Handler $handler */
$handler = $this->app->get('error.handler');
$request = $this->app->get('request');
$handler->setRequest($request);
}
/**
* @param Handler $errorHandler
*/
protected function addProductionHandler($errorHandler)
{
$handler = $this->app->make(Legacy::class);
$this->app->instance('error.handler.production', $handler);
$errorHandler->setHandler(Handler::ENV_PRODUCTION, $handler);
$this->app->bind(HandlerInterface::class, 'error.handler.production');
}
/**
* @param Handler $errorHandler
*/
protected function addDevelopmentHandler($errorHandler)
{
$handler = $this->app->make(LegacyDevelopment::class);
if (class_exists(WhoopsRunner::class)) {
$handler = $this->app->make(Whoops::class);
}
$this->app->instance('error.handler.development', $handler);
$errorHandler->setHandler(Handler::ENV_DEVELOPMENT, $handler);
2017-10-31 13:40:13 +01:00
}
}