From e6ef0bc39c218c171982c220be79e0818b9097a9 Mon Sep 17 00:00:00 2001 From: Thomas Rieschl Date: Wed, 2 Feb 2022 13:39:08 +0100 Subject: [PATCH] add ControllerManager::class as resolvable service, change 'ControllerManager' to an alias Signed-off-by: Thomas Rieschl --- src/Service/ServiceListenerFactory.php | 106 +++++++++--------- .../InvalidControllerTypeTrait.php | 4 +- test/ApplicationTest.php | 2 +- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/Service/ServiceListenerFactory.php b/src/Service/ServiceListenerFactory.php index 721c0fb7..a114f73b 100644 --- a/src/Service/ServiceListenerFactory.php +++ b/src/Service/ServiceListenerFactory.php @@ -5,6 +5,7 @@ use Interop\Container\ContainerInterface; use Laminas\ModuleManager\Listener\ServiceListener; use Laminas\ModuleManager\Listener\ServiceListenerInterface; +use Laminas\Mvc\Controller\ControllerManager; use Laminas\Mvc\View; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Factory\FactoryInterface; @@ -29,62 +30,63 @@ class ServiceListenerFactory implements FactoryInterface */ protected $defaultServiceConfig = [ 'aliases' => [ - 'application' => 'Application', - 'Config' => 'config', - 'configuration' => 'config', - 'Configuration' => 'config', - 'HttpDefaultRenderingStrategy' => View\Http\DefaultRenderingStrategy::class, - 'MiddlewareListener' => 'Laminas\Mvc\MiddlewareListener', - 'request' => 'Request', - 'response' => 'Response', - 'RouteListener' => 'Laminas\Mvc\RouteListener', - 'SendResponseListener' => 'Laminas\Mvc\SendResponseListener', - 'View' => 'Laminas\View\View', - 'ViewFeedRenderer' => 'Laminas\View\Renderer\FeedRenderer', - 'ViewJsonRenderer' => 'Laminas\View\Renderer\JsonRenderer', - 'ViewPhpRendererStrategy' => 'Laminas\View\Strategy\PhpRendererStrategy', - 'ViewPhpRenderer' => 'Laminas\View\Renderer\PhpRenderer', - 'ViewRenderer' => 'Laminas\View\Renderer\PhpRenderer', - 'Laminas\Mvc\Controller\PluginManager' => 'ControllerPluginManager', - 'Laminas\Mvc\View\Http\InjectTemplateListener' => 'InjectTemplateListener', - 'Laminas\View\Renderer\RendererInterface' => 'Laminas\View\Renderer\PhpRenderer', - 'Laminas\View\Resolver\TemplateMapResolver' => 'ViewTemplateMapResolver', - 'Laminas\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack', - 'Laminas\View\Resolver\AggregateResolver' => 'ViewResolver', - 'Laminas\View\Resolver\ResolverInterface' => 'ViewResolver', + 'application' => 'Application', + 'Config' => 'config', + 'configuration' => 'config', + 'Configuration' => 'config', + 'HttpDefaultRenderingStrategy' => View\Http\DefaultRenderingStrategy::class, + 'MiddlewareListener' => 'Laminas\Mvc\MiddlewareListener', + 'request' => 'Request', + 'response' => 'Response', + 'RouteListener' => 'Laminas\Mvc\RouteListener', + 'SendResponseListener' => 'Laminas\Mvc\SendResponseListener', + 'View' => 'Laminas\View\View', + 'ViewFeedRenderer' => 'Laminas\View\Renderer\FeedRenderer', + 'ViewJsonRenderer' => 'Laminas\View\Renderer\JsonRenderer', + 'ViewPhpRendererStrategy' => 'Laminas\View\Strategy\PhpRendererStrategy', + 'ViewPhpRenderer' => 'Laminas\View\Renderer\PhpRenderer', + 'ViewRenderer' => 'Laminas\View\Renderer\PhpRenderer', + 'Laminas\Mvc\Controller\PluginManager' => 'ControllerPluginManager', + 'Laminas\Mvc\View\Http\InjectTemplateListener' => 'InjectTemplateListener', + 'Laminas\View\Renderer\RendererInterface' => 'Laminas\View\Renderer\PhpRenderer', + 'Laminas\View\Resolver\TemplateMapResolver' => 'ViewTemplateMapResolver', + 'Laminas\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack', + 'Laminas\View\Resolver\AggregateResolver' => 'ViewResolver', + 'Laminas\View\Resolver\ResolverInterface' => 'ViewResolver', + 'ControllerManager' => ControllerManager::class, ], 'invokables' => [], 'factories' => [ - 'Application' => ApplicationFactory::class, - 'config' => 'Laminas\Mvc\Service\ConfigFactory', - 'ControllerManager' => 'Laminas\Mvc\Service\ControllerManagerFactory', - 'ControllerPluginManager' => 'Laminas\Mvc\Service\ControllerPluginManagerFactory', - 'DispatchListener' => 'Laminas\Mvc\Service\DispatchListenerFactory', - 'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class, - 'HttpMethodListener' => 'Laminas\Mvc\Service\HttpMethodListenerFactory', - 'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class, - 'HttpViewManager' => 'Laminas\Mvc\Service\HttpViewManagerFactory', - 'InjectTemplateListener' => 'Laminas\Mvc\Service\InjectTemplateListenerFactory', - 'PaginatorPluginManager' => 'Laminas\Mvc\Service\PaginatorPluginManagerFactory', - 'Request' => 'Laminas\Mvc\Service\RequestFactory', - 'Response' => 'Laminas\Mvc\Service\ResponseFactory', - 'ViewHelperManager' => 'Laminas\Mvc\Service\ViewHelperManagerFactory', - View\Http\DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, - 'ViewFeedStrategy' => 'Laminas\Mvc\Service\ViewFeedStrategyFactory', - 'ViewJsonStrategy' => 'Laminas\Mvc\Service\ViewJsonStrategyFactory', - 'ViewManager' => 'Laminas\Mvc\Service\ViewManagerFactory', - 'ViewResolver' => 'Laminas\Mvc\Service\ViewResolverFactory', - 'ViewTemplateMapResolver' => 'Laminas\Mvc\Service\ViewTemplateMapResolverFactory', - 'ViewTemplatePathStack' => 'Laminas\Mvc\Service\ViewTemplatePathStackFactory', - 'ViewPrefixPathStackResolver' => 'Laminas\Mvc\Service\ViewPrefixPathStackResolverFactory', - 'Laminas\Mvc\MiddlewareListener' => InvokableFactory::class, - 'Laminas\Mvc\RouteListener' => InvokableFactory::class, - 'Laminas\Mvc\SendResponseListener' => SendResponseListenerFactory::class, - 'Laminas\View\Renderer\FeedRenderer' => InvokableFactory::class, - 'Laminas\View\Renderer\JsonRenderer' => InvokableFactory::class, - 'Laminas\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class, + 'Application' => ApplicationFactory::class, + 'config' => 'Laminas\Mvc\Service\ConfigFactory', + ControllerManager::class => 'Laminas\Mvc\Service\ControllerManagerFactory', + 'ControllerPluginManager' => 'Laminas\Mvc\Service\ControllerPluginManagerFactory', + 'DispatchListener' => 'Laminas\Mvc\Service\DispatchListenerFactory', + 'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class, + 'HttpMethodListener' => 'Laminas\Mvc\Service\HttpMethodListenerFactory', + 'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class, + 'HttpViewManager' => 'Laminas\Mvc\Service\HttpViewManagerFactory', + 'InjectTemplateListener' => 'Laminas\Mvc\Service\InjectTemplateListenerFactory', + 'PaginatorPluginManager' => 'Laminas\Mvc\Service\PaginatorPluginManagerFactory', + 'Request' => 'Laminas\Mvc\Service\RequestFactory', + 'Response' => 'Laminas\Mvc\Service\ResponseFactory', + 'ViewHelperManager' => 'Laminas\Mvc\Service\ViewHelperManagerFactory', + View\Http\DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class, + 'ViewFeedStrategy' => 'Laminas\Mvc\Service\ViewFeedStrategyFactory', + 'ViewJsonStrategy' => 'Laminas\Mvc\Service\ViewJsonStrategyFactory', + 'ViewManager' => 'Laminas\Mvc\Service\ViewManagerFactory', + 'ViewResolver' => 'Laminas\Mvc\Service\ViewResolverFactory', + 'ViewTemplateMapResolver' => 'Laminas\Mvc\Service\ViewTemplateMapResolverFactory', + 'ViewTemplatePathStack' => 'Laminas\Mvc\Service\ViewTemplatePathStackFactory', + 'ViewPrefixPathStackResolver' => 'Laminas\Mvc\Service\ViewPrefixPathStackResolverFactory', + 'Laminas\Mvc\MiddlewareListener' => InvokableFactory::class, + 'Laminas\Mvc\RouteListener' => InvokableFactory::class, + 'Laminas\Mvc\SendResponseListener' => SendResponseListenerFactory::class, + 'Laminas\View\Renderer\FeedRenderer' => InvokableFactory::class, + 'Laminas\View\Renderer\JsonRenderer' => InvokableFactory::class, + 'Laminas\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class, 'Laminas\View\Strategy\PhpRendererStrategy' => ViewPhpRendererStrategyFactory::class, - 'Laminas\View\View' => ViewFactory::class, + 'Laminas\View\View' => ViewFactory::class, ], ]; diff --git a/test/Application/InvalidControllerTypeTrait.php b/test/Application/InvalidControllerTypeTrait.php index 71901195..df37cf54 100644 --- a/test/Application/InvalidControllerTypeTrait.php +++ b/test/Application/InvalidControllerTypeTrait.php @@ -49,10 +49,10 @@ public function prepareApplication() $serviceConfig, [ 'aliases' => [ - 'ControllerLoader' => 'ControllerManager', + 'ControllerLoader' => ControllerManager::class, ], 'factories' => [ - 'ControllerManager' => function ($services) { + ControllerManager::class => function ($services) { return new ControllerManager($services, ['factories' => [ 'bad' => function () { return new stdClass(); diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index ee0612cd..fa2a03e9 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -317,7 +317,7 @@ public function setupBadController($addService = true, $action = 'test') $router->addRoute('bad', $route); if ($addService) { - $this->serviceManager->setFactory('ControllerManager', function ($services) { + $this->serviceManager->setFactory(ControllerManager::class, function ($services) { return new ControllerManager($services, ['factories' => [ 'bad' => function () { return new Controller\TestAsset\BadController();