Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Make use of class names instead of strings for services #292

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 67 additions & 49 deletions src/Service/ServiceListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
namespace Zend\Mvc\Service;

use Interop\Container\ContainerInterface;
use Zend\Http\PhpEnvironment\Request as HttpRequest;
use Zend\Http\PhpEnvironment\Response as HttpResponse;
use Zend\ModuleManager\Listener\ServiceListener;
use Zend\ModuleManager\Listener\ServiceListenerInterface;
use Zend\Mvc\Controller\ControllerManager;
use Zend\Mvc\Controller\PluginManager as ControllerPluginManager;
use Zend\Mvc\View;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Factory\FactoryInterface;
Expand All @@ -35,62 +39,76 @@ class ServiceListenerFactory implements FactoryInterface
*/
protected $defaultServiceConfig = [
'aliases' => [
'application' => 'Application',
'application' => \Zend\Mvc\Application::class,
'Application' => \Zend\Mvc\Application::class,
'Config' => 'config',
'configuration' => 'config',
'Configuration' => 'config',
'ControllerManager' => ControllerManager::class,
'ControllerPluginManager' => ControllerPluginManager::class,
'DispatchListener' => \Zend\Mvc\DispatchListener::class,
'HttpDefaultRenderingStrategy' => View\Http\DefaultRenderingStrategy::class,
'MiddlewareListener' => 'Zend\Mvc\MiddlewareListener',
'request' => 'Request',
'response' => 'Response',
'RouteListener' => 'Zend\Mvc\RouteListener',
'SendResponseListener' => 'Zend\Mvc\SendResponseListener',
'View' => 'Zend\View\View',
'ViewFeedRenderer' => 'Zend\View\Renderer\FeedRenderer',
'ViewJsonRenderer' => 'Zend\View\Renderer\JsonRenderer',
'ViewPhpRendererStrategy' => 'Zend\View\Strategy\PhpRendererStrategy',
'ViewPhpRenderer' => 'Zend\View\Renderer\PhpRenderer',
'ViewRenderer' => 'Zend\View\Renderer\PhpRenderer',
'Zend\Mvc\Controller\PluginManager' => 'ControllerPluginManager',
'Zend\Mvc\View\Http\InjectTemplateListener' => 'InjectTemplateListener',
'Zend\View\Renderer\RendererInterface' => 'Zend\View\Renderer\PhpRenderer',
'Zend\View\Resolver\TemplateMapResolver' => 'ViewTemplateMapResolver',
'Zend\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack',
'Zend\View\Resolver\AggregateResolver' => 'ViewResolver',
'Zend\View\Resolver\ResolverInterface' => 'ViewResolver',
'HttpExceptionStrategy' => View\Http\ExceptionStrategy::class,
'HttpMethodListener' => \Zend\Mvc\HttpMethodListener::class,
'HttpRouteNotFoundStrategy' => View\Http\RouteNotFoundStrategy::class,
'HttpViewManager' => View\Http\ViewManager::class,
'InjectTemplateListener' => View\Http\InjectTemplateListener::class,
'MiddlewareListener' => \Zend\Mvc\MiddlewareListener::class,
'request' => HttpRequest::class,
'Request' => HttpRequest::class,
'response' => HttpResponse::class,
'Response' => HttpResponse::class,
'RouteListener' => \Zend\Mvc\RouteListener::class,
'SendResponseListener' => \Zend\Mvc\SendResponseListener::class,
'View' => \Zend\View\View::class,
'ViewFeedStrategy' => \Zend\View\Strategy\FeedStrategy::class,
'ViewFeedRenderer' => \Zend\View\Renderer\FeedRenderer::class,
'ViewHelperManager' => \Zend\View\HelperPluginManager::class,
'ViewJsonStrategy' => \Zend\View\Strategy\JsonStrategy::class,
'ViewJsonRenderer' => \Zend\View\Renderer\JsonRenderer::class,
'ViewManager' => View\Http\ViewManager::class,
'ViewPhpRenderer' => \Zend\View\Renderer\PhpRenderer::class,
'ViewPhpRendererStrategy' => \Zend\View\Strategy\PhpRendererStrategy::class,
'ViewPrefixPathStackResolver' => \Zend\View\Resolver\PrefixPathStackResolver::class,
'ViewRenderer' => \Zend\View\Renderer\PhpRenderer::class,
'ViewResolver' => \Zend\View\Resolver\AggregateResolver::class,
'ViewTemplateMapResolver' => \Zend\View\Resolver\TemplateMapResolver::class,
'ViewTemplatePathStack' => \Zend\View\Resolver\TemplatePathStack::class,
\Zend\View\Renderer\RendererInterface::class => \Zend\View\Renderer\PhpRenderer::class,
\Zend\View\Resolver\ResolverInterface::class => \Zend\View\Resolver\AggregateResolver::class,
'Zend\View\ViewHelperManager' => \Zend\View\View::class,
],
'invokables' => [],
'factories' => [
'Application' => ApplicationFactory::class,
'config' => 'Zend\Mvc\Service\ConfigFactory',
'ControllerManager' => 'Zend\Mvc\Service\ControllerManagerFactory',
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
'DispatchListener' => 'Zend\Mvc\Service\DispatchListenerFactory',
'HttpExceptionStrategy' => HttpExceptionStrategyFactory::class,
'HttpMethodListener' => 'Zend\Mvc\Service\HttpMethodListenerFactory',
'HttpRouteNotFoundStrategy' => HttpRouteNotFoundStrategyFactory::class,
'HttpViewManager' => 'Zend\Mvc\Service\HttpViewManagerFactory',
'InjectTemplateListener' => 'Zend\Mvc\Service\InjectTemplateListenerFactory',
'PaginatorPluginManager' => 'Zend\Mvc\Service\PaginatorPluginManagerFactory',
'Request' => 'Zend\Mvc\Service\RequestFactory',
'Response' => 'Zend\Mvc\Service\ResponseFactory',
'ViewHelperManager' => 'Zend\Mvc\Service\ViewHelperManagerFactory',
View\Http\DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class,
'ViewFeedStrategy' => 'Zend\Mvc\Service\ViewFeedStrategyFactory',
'ViewJsonStrategy' => 'Zend\Mvc\Service\ViewJsonStrategyFactory',
'ViewManager' => 'Zend\Mvc\Service\ViewManagerFactory',
'ViewResolver' => 'Zend\Mvc\Service\ViewResolverFactory',
'ViewTemplateMapResolver' => 'Zend\Mvc\Service\ViewTemplateMapResolverFactory',
'ViewTemplatePathStack' => 'Zend\Mvc\Service\ViewTemplatePathStackFactory',
'ViewPrefixPathStackResolver' => 'Zend\Mvc\Service\ViewPrefixPathStackResolverFactory',
'Zend\Mvc\MiddlewareListener' => InvokableFactory::class,
'Zend\Mvc\RouteListener' => InvokableFactory::class,
'Zend\Mvc\SendResponseListener' => SendResponseListenerFactory::class,
'Zend\View\Renderer\FeedRenderer' => InvokableFactory::class,
'Zend\View\Renderer\JsonRenderer' => InvokableFactory::class,
'Zend\View\Renderer\PhpRenderer' => ViewPhpRendererFactory::class,
'Zend\View\Strategy\PhpRendererStrategy' => ViewPhpRendererStrategyFactory::class,
'Zend\View\View' => ViewFactory::class,
'config' => ConfigFactory::class,
'PaginatorPluginManager' => PaginatorPluginManagerFactory::class,
ControllerManager::class => ControllerManagerFactory::class,
ControllerPluginManager::class => ControllerPluginManagerFactory::class,
HttpRequest::class => RequestFactory::class,
HttpResponse::class => ResponseFactory::class,
View\Http\DefaultRenderingStrategy::class => HttpDefaultRenderingStrategyFactory::class,
View\Http\ExceptionStrategy::class => HttpExceptionStrategyFactory::class,
View\Http\InjectTemplateListener::class => InjectTemplateListenerFactory::class,
View\Http\RouteNotFoundStrategy::class => HttpRouteNotFoundStrategyFactory::class,
View\Http\ViewManager::class => HttpViewManagerFactory::class,
\Zend\Mvc\Application::class => ApplicationFactory::class,
\Zend\Mvc\DispatchListener::class => DispatchListenerFactory::class,
\Zend\Mvc\HttpMethodListener::class => HttpMethodListenerFactory::class,
\Zend\Mvc\MiddlewareListener::class => InvokableFactory::class,
\Zend\Mvc\RouteListener::class => InvokableFactory::class,
\Zend\Mvc\SendResponseListener::class => SendResponseListenerFactory::class,
\Zend\View\Renderer\FeedRenderer::class => InvokableFactory::class,
\Zend\View\Renderer\JsonRenderer::class => InvokableFactory::class,
\Zend\View\Renderer\PhpRenderer::class => ViewPhpRendererFactory::class,
\Zend\View\Resolver\AggregateResolver::class => ViewResolverFactory::class,
\Zend\View\Resolver\PrefixPathStackResolver::class => ViewPrefixPathStackResolverFactory::class,
\Zend\View\Resolver\TemplateMapResolver::class => ViewTemplateMapResolverFactory::class,
\Zend\View\Resolver\TemplatePathStack::class => ViewTemplatePathStackFactory::class,
\Zend\View\Strategy\PhpRendererStrategy::class => ViewPhpRendererStrategyFactory::class,
\Zend\View\Strategy\FeedStrategy::class => ViewFeedStrategyFactory::class,
\Zend\View\Strategy\JsonStrategy::class => ViewJsonStrategyFactory::class,
\Zend\View\HelperPluginManager::class => ViewHelperManagerFactory::class,
\Zend\View\View::class => ViewFactory::class,
],
];

Expand Down
5 changes: 3 additions & 2 deletions test/Application/InvalidControllerTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public function prepareApplication()
$serviceConfig,
[
'aliases' => [
'ControllerLoader' => 'ControllerManager',
'ControllerLoader' => 'ControllerManagerClosure',
'ControllerManager' => 'ControllerManagerClosure',
],
'factories' => [
'ControllerManager' => function ($services) {
'ControllerManagerClosure' => function ($services) {
return new ControllerManager($services, ['factories' => [
'bad' => function () {
return new stdClass();
Expand Down
2 changes: 1 addition & 1 deletion test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,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();
Expand Down