summaryrefslogtreecommitdiff
path: root/src/Exceptions/ExceptionsServiceProvider.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-11-28 15:43:51 +0100
committerGitHub <noreply@github.com>2017-11-28 15:43:51 +0100
commit599f2fd264bfc7b1b6826fe206442806e317340f (patch)
tree50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /src/Exceptions/ExceptionsServiceProvider.php
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parenteda7f7788ea8012bd8be46405c56a666c11f3fa5 (diff)
Merge pull request #365 from engelsystem/feature-igel-rewrite
Feature igel rewrite
Diffstat (limited to 'src/Exceptions/ExceptionsServiceProvider.php')
-rw-r--r--src/Exceptions/ExceptionsServiceProvider.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Exceptions/ExceptionsServiceProvider.php b/src/Exceptions/ExceptionsServiceProvider.php
new file mode 100644
index 00000000..a9bc2b17
--- /dev/null
+++ b/src/Exceptions/ExceptionsServiceProvider.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Engelsystem\Exceptions;
+
+use Engelsystem\Container\ServiceProvider;
+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;
+
+class ExceptionsServiceProvider extends ServiceProvider
+{
+ public function register()
+ {
+ $errorHandler = $this->app->make(Handler::class);
+ $this->addProductionHandler($errorHandler);
+ $this->addDevelopmentHandler($errorHandler);
+ $this->app->instance('error.handler', $errorHandler);
+ $this->app->bind(Handler::class, 'error.handler');
+ $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);
+ }
+}