From 046fb718925eca81dfec5711fa2a217ee24a8f38 Mon Sep 17 00:00:00 2001 From: Bastian Date: Tue, 25 Apr 2017 15:37:42 +0200 Subject: [PATCH] TASK: Tweak retrieval of GraylogService in Exception handler --- Classes/Error/GraylogExceptionHandler.php | 31 +++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Classes/Error/GraylogExceptionHandler.php b/Classes/Error/GraylogExceptionHandler.php index ccb27d7..5986624 100644 --- a/Classes/Error/GraylogExceptionHandler.php +++ b/Classes/Error/GraylogExceptionHandler.php @@ -8,6 +8,7 @@ use Neos\Flow\Annotations as Flow; use Neos\Flow\Error\ProductionExceptionHandler; +use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy; use Yeebase\Graylog\GraylogService; /** @@ -28,13 +29,8 @@ class GraylogExceptionHandler extends ProductionExceptionHandler */ protected function echoExceptionWeb($exception) { - - if ($this->graylogService === null) { - $this->graylogService = new GraylogService(); - } - if (isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) { - $this->graylogService->logException($exception); + $this->getGraylogService()->logException($exception); } parent::echoExceptionWeb($exception); @@ -46,14 +42,27 @@ protected function echoExceptionWeb($exception) */ protected function echoExceptionCli($exception) { - if ($this->graylogService === null) { - $this->graylogService = new GraylogService(); - } - if (isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) { - $this->graylogService->logException($exception); + $this->getGraylogService()->logException($exception); } parent::echoExceptionCli($exception); } + + /** + * Returns an instance of the injected GraylogService (including a fallback to a manually instantiated instance + * if Dependency Injection is not (yet) available) + * + * @return GraylogService + */ + private function getGraylogService() + { + if ($this->graylogService instanceof GraylogService) { + return $this->graylogService; + } elseif ($this->graylogService instanceof DependencyProxy) { + return $this->graylogService->_activateDependency(); + } else { + return new GraylogService(); + } + } }