diff --git a/src/DispatchListener.php b/src/DispatchListener.php index 202244cb7..b14407500 100644 --- a/src/DispatchListener.php +++ b/src/DispatchListener.php @@ -65,15 +65,15 @@ public function onDispatch(MvcEvent $e) $controllerName = $routeMatch->getParam('controller', 'not-found'); $application = $e->getApplication(); $events = $application->getEventManager(); - $controllerLoader = $application->getServiceManager()->get('ControllerManager'); + $controllerManager = $application->getServiceManager()->get('ControllerManager'); - if (!$controllerLoader->has($controllerName)) { + if (!$controllerManager->has($controllerName)) { $return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_NOT_FOUND, $controllerName, $e, $application); return $this->complete($return, $e); } try { - $controller = $controllerLoader->get($controllerName); + $controller = $controllerManager->get($controllerName); } catch (InvalidControllerException $exception) { $return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, $exception); return $this->complete($return, $e); diff --git a/src/Service/ControllerLoaderFactory.php b/src/Service/ControllerManagerFactory.php similarity index 76% rename from src/Service/ControllerLoaderFactory.php rename to src/Service/ControllerManagerFactory.php index cf5cda2d0..20574f43f 100644 --- a/src/Service/ControllerLoaderFactory.php +++ b/src/Service/ControllerManagerFactory.php @@ -13,10 +13,10 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class ControllerLoaderFactory implements FactoryInterface +class ControllerManagerFactory implements FactoryInterface { /** - * Create the controller loader service + * Create the controller manager service * * Creates and returns an instance of ControllerManager. The * only controllers this manager will allow are those defined in the @@ -33,16 +33,16 @@ class ControllerLoaderFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $controllerLoader = new ControllerManager(); - $controllerLoader->setServiceLocator($serviceLocator); - $controllerLoader->addPeeringServiceManager($serviceLocator); + $controllerManager = new ControllerManager(); + $controllerManager->setServiceLocator($serviceLocator); + $controllerManager->addPeeringServiceManager($serviceLocator); $config = $serviceLocator->get('Config'); if (isset($config['di']) && isset($config['di']['allowed_controllers']) && $serviceLocator->has('Di')) { - $controllerLoader->addAbstractFactory($serviceLocator->get('DiStrictAbstractServiceFactory')); + $controllerManager->addAbstractFactory($serviceLocator->get('DiStrictAbstractServiceFactory')); } - return $controllerLoader; + return $controllerManager; } } diff --git a/src/Service/ModuleManagerFactory.php b/src/Service/ModuleManagerFactory.php index ae2bd4d5c..53b71e450 100644 --- a/src/Service/ModuleManagerFactory.php +++ b/src/Service/ModuleManagerFactory.php @@ -50,7 +50,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) 'getServiceConfig' ); $serviceListener->addServiceManager( - 'ControllerLoader', + 'ControllerManager', 'controllers', 'Zend\ModuleManager\Feature\ControllerProviderInterface', 'getControllerConfig' diff --git a/src/Service/ServiceListenerFactory.php b/src/Service/ServiceListenerFactory.php index 299c2b3f0..6dc7fa88c 100644 --- a/src/Service/ServiceListenerFactory.php +++ b/src/Service/ServiceListenerFactory.php @@ -44,7 +44,7 @@ class ServiceListenerFactory implements FactoryInterface 'factories' => [ 'Application' => 'Zend\Mvc\Service\ApplicationFactory', 'Config' => 'Zend\Mvc\Service\ConfigFactory', - 'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory', + 'ControllerManager' => 'Zend\Mvc\Service\ControllerManagerFactory', 'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory', 'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory', 'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory', @@ -94,7 +94,6 @@ class ServiceListenerFactory implements FactoryInterface 'Zend\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack', 'Zend\View\Resolver\AggregateResolver' => 'ViewResolver', 'Zend\View\Resolver\ResolverInterface' => 'ViewResolver', - 'ControllerManager' => 'ControllerLoader', ], 'abstract_factories' => [ 'Zend\Form\FormAbstractServiceFactory', diff --git a/test/ApplicationTest.php b/test/ApplicationTest.php index bc2960b19..164e99ca8 100644 --- a/test/ApplicationTest.php +++ b/test/ApplicationTest.php @@ -233,8 +233,8 @@ public function setupPathController($addService = true) ]); $router->addRoute('path', $route); if ($addService) { - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->setFactory('path', function () { + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->setFactory('path', function () { return new TestAsset\PathController; }); } @@ -256,8 +256,8 @@ public function setupActionController() ]); $router->addRoute('sample', $route); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->setFactory('sample', function () { + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->setFactory('sample', function () { return new Controller\TestAsset\SampleController; }); $this->application->bootstrap(); @@ -279,8 +279,8 @@ public function setupBadController($addService = true) $router->addRoute('bad', $route); if ($addService) { - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->setFactory('bad', function () { + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->setFactory('bad', function () { return new Controller\TestAsset\BadController; }); } @@ -383,7 +383,7 @@ public function testExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEvent( public function testInabilityToRetrieveControllerShouldTriggerExceptionError() { $this->setupBadController(false); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); + $controllerManager = $this->serviceManager->get('ControllerManager'); $response = $this->application->getResponse(); $events = $this->application->getEventManager(); $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { @@ -423,10 +423,10 @@ public function testInabilityToRetrieveControllerShouldTriggerDispatchError() */ public function testInvalidControllerTypeShouldTriggerDispatchError() { - $this->serviceManager->get('ControllerLoader'); + $this->serviceManager->get('ControllerManager'); $this->setupBadController(false); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->setFactory('bad', function () { + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->setFactory('bad', function () { return new stdClass; }); $response = $this->application->getResponse(); @@ -473,7 +473,7 @@ public function testRoutingFailureShouldTriggerDispatchError() public function testLocatorExceptionShouldTriggerDispatchError() { $this->setupPathController(false); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); + $controllerManager = $this->serviceManager->get('ControllerManager'); $response = new Response(); $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) { return $response; @@ -570,7 +570,7 @@ public function testApplicationShouldBeEventTargetAtFinishEvent() public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne() { $this->setupPathController(false); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); + $controllerManager = $this->serviceManager->get('ControllerManager'); $model = $this->getMock('Zend\View\Model\ViewModel'); $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($model) { $e->setResult($model); diff --git a/test/Controller/Plugin/ForwardTest.php b/test/Controller/Plugin/ForwardTest.php index 7fb37e265..2df5e1473 100644 --- a/test/Controller/Plugin/ForwardTest.php +++ b/test/Controller/Plugin/ForwardTest.php @@ -78,11 +78,10 @@ public function setUp() return $controller; }); $controllers->setServiceLocator($services); - $controllerLoader = function () use ($controllers) { + $controllerManager = function () use ($controllers) { return $controllers; }; - $services->add('ControllerLoader', $controllerLoader); - $services->add('ControllerManager', $controllerLoader); + $services->add('ControllerManager', $controllerManager); $services->add('ControllerPluginManager', function () use ($plugins) { return $plugins; }); diff --git a/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php b/test/Controller/TestAsset/ControllerManagerAbstractFactory.php similarity index 92% rename from test/Controller/TestAsset/ControllerLoaderAbstractFactory.php rename to test/Controller/TestAsset/ControllerManagerAbstractFactory.php index 9dc280d44..d403bae37 100644 --- a/test/Controller/TestAsset/ControllerLoaderAbstractFactory.php +++ b/test/Controller/TestAsset/ControllerManagerAbstractFactory.php @@ -12,7 +12,7 @@ use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class ControllerLoaderAbstractFactory implements AbstractFactoryInterface +class ControllerManagerAbstractFactory implements AbstractFactoryInterface { protected $classmap = array( 'path' => 'ZendTest\Mvc\TestAsset\PathController', diff --git a/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php b/test/Controller/TestAsset/UnlocatableControllerManagerAbstractFactory.php similarity index 88% rename from test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php rename to test/Controller/TestAsset/UnlocatableControllerManagerAbstractFactory.php index f31b8da53..1e8100471 100644 --- a/test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php +++ b/test/Controller/TestAsset/UnlocatableControllerManagerAbstractFactory.php @@ -12,7 +12,7 @@ use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class UnlocatableControllerLoaderAbstractFactory implements AbstractFactoryInterface +class UnlocatableControllerManagerAbstractFactory implements AbstractFactoryInterface { public function canCreateServiceWithName(ServiceLocatorInterface $sl, $cName, $rName) { diff --git a/test/DispatchListenerTest.php b/test/DispatchListenerTest.php index d7b84d614..ed4c54249 100644 --- a/test/DispatchListenerTest.php +++ b/test/DispatchListenerTest.php @@ -79,12 +79,12 @@ public function setupPathController() $this->application->bootstrap(); } - public function testControllerLoaderComposedOfAbstractFactory() + public function testControllerManagerComposedOfAbstractFactory() { $this->setupPathController(); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\ControllerLoaderAbstractFactory'); + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\ControllerManagerAbstractFactory'); $log = []; $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use (&$log) { @@ -102,12 +102,12 @@ public function testControllerLoaderComposedOfAbstractFactory() $this->assertSame(200, $return->getStatusCode()); } - public function testUnlocatableControllerLoaderComposedOfAbstractFactory() + public function testUnlocatableControllerManagerComposedOfAbstractFactory() { $this->setupPathController(); - $controllerLoader = $this->serviceManager->get('ControllerLoader'); - $controllerLoader->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\UnlocatableControllerLoaderAbstractFactory'); + $controllerManager = $this->serviceManager->get('ControllerManager'); + $controllerManager->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\UnlocatableControllerManagerAbstractFactory'); $log = []; $this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use (&$log) { diff --git a/test/Service/ControllerLoaderFactoryTest.php b/test/Service/ControllerManagerFactoryTest.php similarity index 84% rename from test/Service/ControllerLoaderFactoryTest.php rename to test/Service/ControllerManagerFactoryTest.php index d7ae43002..06451bb4c 100644 --- a/test/Service/ControllerLoaderFactoryTest.php +++ b/test/Service/ControllerManagerFactoryTest.php @@ -11,7 +11,7 @@ use ArrayObject; use PHPUnit_Framework_TestCase as TestCase; -use Zend\Mvc\Service\ControllerLoaderFactory; +use Zend\Mvc\Service\ControllerManagerFactory; use Zend\Mvc\Service\ControllerPluginManagerFactory; use Zend\Mvc\Service\DiFactory; use Zend\Mvc\Service\DiStrictAbstractServiceFactoryFactory; @@ -22,7 +22,7 @@ use Zend\ServiceManager\ServiceManager; use Zend\Mvc\Exception; -class ControllerLoaderFactoryTest extends TestCase +class ControllerManagerFactoryTest extends TestCase { /** * @var ServiceManager @@ -32,15 +32,15 @@ class ControllerLoaderFactoryTest extends TestCase /** * @var \Zend\Mvc\Controller\ControllerManager */ - protected $loader; + protected $manager; public function setUp() { - $loaderFactory = new ControllerLoaderFactory(); + $managerFactory = new ControllerManagerFactory(); $config = new ArrayObject(['di' => []]); $this->services = new ServiceManager(); $this->services->setService('Zend\ServiceManager\ServiceLocatorInterface', $this->services); - $this->services->setFactory('ControllerLoader', $loaderFactory); + $this->services->setFactory('ControllerManager', $managerFactory); $this->services->setService('Config', $config); $this->services->setFactory('ControllerPluginManager', new ControllerPluginManagerFactory()); $this->services->setFactory('Di', new DiFactory()); @@ -53,13 +53,13 @@ public function setUp() public function testCannotLoadInvalidDispatchable() { - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); // Ensure the class exists and can be autoloaded $this->assertTrue(class_exists('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass')); try { - $this->loader->get('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass'); + $this->manager->get('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass'); $this->fail('Retrieving the invalid dispatchable should fail'); } catch (\Exception $e) { do { @@ -70,25 +70,25 @@ public function testCannotLoadInvalidDispatchable() public function testCannotLoadControllerFromPeer() { - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); $this->services->setService('foo', $this); $this->setExpectedException('Zend\ServiceManager\Exception\ExceptionInterface'); - $this->loader->get('foo'); + $this->manager->get('foo'); } public function testControllerLoadedCanBeInjectedWithValuesFromPeer() { - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); $config = [ 'invokables' => [ 'ZendTest\Dispatchable' => 'ZendTest\Mvc\Service\TestAsset\Dispatchable', ], ]; $config = new Config($config); - $config->configureServiceManager($this->loader); + $config->configureServiceManager($this->manager); - $controller = $this->loader->get('ZendTest\Dispatchable'); + $controller = $this->manager->get('ZendTest\Dispatchable'); $this->assertInstanceOf('ZendTest\Mvc\Service\TestAsset\Dispatchable', $controller); $this->assertSame($this->services, $controller->getServiceLocator()); $this->assertSame($this->services->get('EventManager'), $controller->getEventManager()); @@ -111,12 +111,12 @@ public function testWillInstantiateControllersFromDiAbstractFactoryWhenWhitelist ]); $this->services->setAllowOverride(true); $this->services->setService('Config', $config); - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); - $this->assertTrue($this->loader->has('my-controller')); + $this->assertTrue($this->manager->has('my-controller')); // invalid controller exception (because we're getting an \stdClass after all) $this->setExpectedException('Zend\Mvc\Exception\InvalidControllerException'); - $this->loader->get('my-controller'); + $this->manager->get('my-controller'); } public function testWillNotInstantiateControllersFromDiAbstractFactoryWhenNotWhitelisted() @@ -135,9 +135,9 @@ public function testWillNotInstantiateControllersFromDiAbstractFactoryWhenNotWhi ]); $this->services->setAllowOverride(true); $this->services->setService('Config', $config); - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); $this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException'); - $this->loader->get('evil-controller'); + $this->manager->get('evil-controller'); } public function testWillFetchDiDependenciesFromControllerLoaderServiceManager() @@ -160,12 +160,12 @@ public function testWillFetchDiDependenciesFromControllerLoaderServiceManager() ]); $this->services->setAllowOverride(true); $this->services->setService('Config', $config); - $this->loader = $this->services->get('ControllerLoader'); + $this->manager = $this->services->get('ControllerManager'); $testService = new \stdClass(); $this->services->setService('stdClass', $testService); // invalid controller exception (because we're not getting a \Zend\Stdlib\DispatchableInterface after all) - $controller = $this->loader->get($controllerName); + $controller = $this->manager->get($controllerName); $this->assertSame($testService, $controller->injectedValue); }