diff --git a/config/autoload/services.global.php b/config/autoload/services.global.php index d7f56ed6..841a389a 100644 --- a/config/autoload/services.global.php +++ b/config/autoload/services.global.php @@ -1,6 +1,8 @@ InvokableFactory::class, // View - 'Zend\Expressive\FinalHandler' => ContentBasedErrorHandlerFactory::class, + ContentBasedErrorHandler::class => AnnotatedFactory::class, + ErrorHandlerManager::class => ErrorHandlerManagerFactory::class, Template\TemplateRendererInterface::class => Twig\TwigRendererFactory::class, ], 'aliases' => [ Router\RouterInterface::class => Router\FastRouteRouter::class, + 'Zend\Expressive\FinalHandler' => ContentBasedErrorHandler::class, ], ], diff --git a/module/Common/src/Expressive/ContentBasedErrorHandler.php b/module/Common/src/Expressive/ContentBasedErrorHandler.php index 7dbe2509..dbd3d900 100644 --- a/module/Common/src/Expressive/ContentBasedErrorHandler.php +++ b/module/Common/src/Expressive/ContentBasedErrorHandler.php @@ -1,27 +1,29 @@ errorHandlerManager = $errorHandlerManager; } /** @@ -51,11 +53,11 @@ class ContentBasedErrorHandler extends AbstractPluginManager implements ErrorHan $accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : self::DEFAULT_CONTENT; $accepts = explode(',', $accepts); foreach ($accepts as $accept) { - if (! $this->has($accept)) { + if (! $this->errorHandlerManager->has($accept)) { continue; } - return $this->get($accept); + return $this->errorHandlerManager->get($accept); } // If it wasn't possible to find an error handler for accepted content type, use default one if registered diff --git a/module/Common/src/Expressive/ErrorHandlerManager.php b/module/Common/src/Expressive/ErrorHandlerManager.php new file mode 100644 index 00000000..5cce0095 --- /dev/null +++ b/module/Common/src/Expressive/ErrorHandlerManager.php @@ -0,0 +1,21 @@ +get('config')['error_handler']; $plugins = isset($config['plugins']) ? $config['plugins'] : []; - return new ContentBasedErrorHandler($container, $plugins); + return new ErrorHandlerManager($container, $plugins); } } diff --git a/module/Common/src/Expressive/ErrorHandlerManagerInterface.php b/module/Common/src/Expressive/ErrorHandlerManagerInterface.php new file mode 100644 index 00000000..371cbbf4 --- /dev/null +++ b/module/Common/src/Expressive/ErrorHandlerManagerInterface.php @@ -0,0 +1,9 @@ +