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

Commit 9d78688

Browse files
committed
remove ControllerLoader, use ControllerManager instead
1 parent 150af6c commit 9d78688

10 files changed

+58
-55
lines changed

src/DispatchListener.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public function onDispatch(MvcEvent $e)
6565
$controllerName = $routeMatch->getParam('controller', 'not-found');
6666
$application = $e->getApplication();
6767
$events = $application->getEventManager();
68-
$controllerLoader = $application->getServiceManager()->get('ControllerManager');
68+
$controllerManager = $application->getServiceManager()->get('ControllerManager');
6969

70-
if (!$controllerLoader->has($controllerName)) {
70+
if (!$controllerManager->has($controllerName)) {
7171
$return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_NOT_FOUND, $controllerName, $e, $application);
7272
return $this->complete($return, $e);
7373
}
7474

7575
try {
76-
$controller = $controllerLoader->get($controllerName);
76+
$controller = $controllerManager->get($controllerName);
7777
} catch (InvalidControllerException $exception) {
7878
$return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, $exception);
7979
return $this->complete($return, $e);

src/Service/ControllerLoaderFactory.php renamed to src/Service/ControllerManagerFactory.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Zend\ServiceManager\FactoryInterface;
1414
use Zend\ServiceManager\ServiceLocatorInterface;
1515

16-
class ControllerLoaderFactory implements FactoryInterface
16+
class ControllerManagerFactory implements FactoryInterface
1717
{
1818
/**
1919
* Create the controller loader service
@@ -33,16 +33,16 @@ class ControllerLoaderFactory implements FactoryInterface
3333
*/
3434
public function createService(ServiceLocatorInterface $serviceLocator)
3535
{
36-
$controllerLoader = new ControllerManager();
37-
$controllerLoader->setServiceLocator($serviceLocator);
38-
$controllerLoader->addPeeringServiceManager($serviceLocator);
36+
$controllerManager = new ControllerManager();
37+
$controllerManager->setServiceLocator($serviceLocator);
38+
$controllerManager->addPeeringServiceManager($serviceLocator);
3939

4040
$config = $serviceLocator->get('Config');
4141

4242
if (isset($config['di']) && isset($config['di']['allowed_controllers']) && $serviceLocator->has('Di')) {
43-
$controllerLoader->addAbstractFactory($serviceLocator->get('DiStrictAbstractServiceFactory'));
43+
$controllerManager->addAbstractFactory($serviceLocator->get('DiStrictAbstractServiceFactory'));
4444
}
4545

46-
return $controllerLoader;
46+
return $controllerManager;
4747
}
4848
}

src/Service/ModuleManagerFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
5050
'getServiceConfig'
5151
);
5252
$serviceListener->addServiceManager(
53-
'ControllerLoader',
53+
'ControllerManager',
5454
'controllers',
5555
'Zend\ModuleManager\Feature\ControllerProviderInterface',
5656
'getControllerConfig'

src/Service/ServiceListenerFactory.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ServiceListenerFactory implements FactoryInterface
4444
'factories' => [
4545
'Application' => 'Zend\Mvc\Service\ApplicationFactory',
4646
'Config' => 'Zend\Mvc\Service\ConfigFactory',
47-
'ControllerLoader' => 'Zend\Mvc\Service\ControllerLoaderFactory',
47+
'ControllerManager' => 'Zend\Mvc\Service\ControllerManagerFactory',
4848
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory',
4949
'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory',
5050
'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory',
@@ -94,8 +94,6 @@ class ServiceListenerFactory implements FactoryInterface
9494
'Zend\View\Resolver\TemplatePathStack' => 'ViewTemplatePathStack',
9595
'Zend\View\Resolver\AggregateResolver' => 'ViewResolver',
9696
'Zend\View\Resolver\ResolverInterface' => 'ViewResolver',
97-
'ControllerManager' => 'ControllerLoader',
98-
],
9997
'abstract_factories' => [
10098
'Zend\Form\FormAbstractServiceFactory',
10199
],

test/ApplicationTest.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public function setupPathController($addService = true)
233233
]);
234234
$router->addRoute('path', $route);
235235
if ($addService) {
236-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
237-
$controllerLoader->setFactory('path', function () {
236+
$controllerManager = $this->serviceManager->get('ControllerManager');
237+
$controllerManager->setFactory('path', function () {
238238
return new TestAsset\PathController;
239239
});
240240
}
@@ -256,8 +256,8 @@ public function setupActionController()
256256
]);
257257
$router->addRoute('sample', $route);
258258

259-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
260-
$controllerLoader->setFactory('sample', function () {
259+
$controllerManager = $this->serviceManager->get('ControllerManager');
260+
$controllerManager->setFactory('sample', function () {
261261
return new Controller\TestAsset\SampleController;
262262
});
263263
$this->application->bootstrap();
@@ -279,8 +279,8 @@ public function setupBadController($addService = true)
279279
$router->addRoute('bad', $route);
280280

281281
if ($addService) {
282-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
283-
$controllerLoader->setFactory('bad', function () {
282+
$controllerManager = $this->serviceManager->get('ControllerManager');
283+
$controllerManager->setFactory('bad', function () {
284284
return new Controller\TestAsset\BadController;
285285
});
286286
}
@@ -383,7 +383,7 @@ public function testExceptionsRaisedInDispatchableShouldRaiseDispatchErrorEvent(
383383
public function testInabilityToRetrieveControllerShouldTriggerExceptionError()
384384
{
385385
$this->setupBadController(false);
386-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
386+
$controllerManager = $this->serviceManager->get('ControllerManager');
387387
$response = $this->application->getResponse();
388388
$events = $this->application->getEventManager();
389389
$events->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) {
@@ -423,10 +423,10 @@ public function testInabilityToRetrieveControllerShouldTriggerDispatchError()
423423
*/
424424
public function testInvalidControllerTypeShouldTriggerDispatchError()
425425
{
426-
$this->serviceManager->get('ControllerLoader');
426+
$this->serviceManager->get('ControllerManager');
427427
$this->setupBadController(false);
428-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
429-
$controllerLoader->setFactory('bad', function () {
428+
$controllerManager = $this->serviceManager->get('ControllerManager');
429+
$controllerManager->setFactory('bad', function () {
430430
return new stdClass;
431431
});
432432
$response = $this->application->getResponse();
@@ -473,7 +473,7 @@ public function testRoutingFailureShouldTriggerDispatchError()
473473
public function testLocatorExceptionShouldTriggerDispatchError()
474474
{
475475
$this->setupPathController(false);
476-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
476+
$controllerManager = $this->serviceManager->get('ControllerManager');
477477
$response = new Response();
478478
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($response) {
479479
return $response;
@@ -570,7 +570,7 @@ public function testApplicationShouldBeEventTargetAtFinishEvent()
570570
public function testOnDispatchErrorEventPassedToTriggersShouldBeTheOriginalOne()
571571
{
572572
$this->setupPathController(false);
573-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
573+
$controllerManager = $this->serviceManager->get('ControllerManager');
574574
$model = $this->getMock('Zend\View\Model\ViewModel');
575575
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($model) {
576576
$e->setResult($model);

test/Controller/Plugin/ForwardTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ public function setUp()
7878
return $controller;
7979
});
8080
$controllers->setServiceLocator($services);
81-
$controllerLoader = function () use ($controllers) {
81+
$controllerManager = function () use ($controllers) {
8282
return $controllers;
8383
};
84-
$services->add('ControllerLoader', $controllerLoader);
85-
$services->add('ControllerManager', $controllerLoader);
84+
$services->add('ControllerManager', $controllerManager);
8685
$services->add('ControllerPluginManager', function () use ($plugins) {
8786
return $plugins;
8887
});

test/Controller/TestAsset/ControllerLoaderAbstractFactory.php renamed to test/Controller/TestAsset/ControllerManagerAbstractFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Zend\ServiceManager\AbstractFactoryInterface;
1313
use Zend\ServiceManager\ServiceLocatorInterface;
1414

15-
class ControllerLoaderAbstractFactory implements AbstractFactoryInterface
15+
class ControllerManagerAbstractFactory implements AbstractFactoryInterface
1616
{
1717
protected $classmap = array(
1818
'path' => 'ZendTest\Mvc\TestAsset\PathController',

test/Controller/TestAsset/UnlocatableControllerLoaderAbstractFactory.php renamed to test/Controller/TestAsset/UnlocatableControllerManagerAbstractFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Zend\ServiceManager\AbstractFactoryInterface;
1313
use Zend\ServiceManager\ServiceLocatorInterface;
1414

15-
class UnlocatableControllerLoaderAbstractFactory implements AbstractFactoryInterface
15+
class UnlocatableControllerManagerAbstractFactory implements AbstractFactoryInterface
1616
{
1717
public function canCreateServiceWithName(ServiceLocatorInterface $sl, $cName, $rName)
1818
{

test/DispatchListenerTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public function setupPathController()
7979
$this->application->bootstrap();
8080
}
8181

82-
public function testControllerLoaderComposedOfAbstractFactory()
82+
public function testControllerManagerComposedOfAbstractFactory()
8383
{
8484
$this->setupPathController();
8585

86-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
87-
$controllerLoader->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\ControllerLoaderAbstractFactory');
86+
$controllerManager = $this->serviceManager->get('ControllerManager');
87+
$controllerManager->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\ControllerManagerAbstractFactory');
8888

8989
$log = [];
9090
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use (&$log) {
@@ -102,12 +102,12 @@ public function testControllerLoaderComposedOfAbstractFactory()
102102
$this->assertSame(200, $return->getStatusCode());
103103
}
104104

105-
public function testUnlocatableControllerLoaderComposedOfAbstractFactory()
105+
public function testUnlocatableControllerManagerComposedOfAbstractFactory()
106106
{
107107
$this->setupPathController();
108108

109-
$controllerLoader = $this->serviceManager->get('ControllerLoader');
110-
$controllerLoader->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\UnlocatableControllerLoaderAbstractFactory');
109+
$controllerManager = $this->serviceManager->get('ControllerManager');
110+
$controllerManager->addAbstractFactory('ZendTest\Mvc\Controller\TestAsset\UnlocatableControllerManagerAbstractFactory');
111111

112112
$log = [];
113113
$this->application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use (&$log) {

test/Service/ControllerLoaderFactoryTest.php renamed to test/Service/ControllerManagerFactoryTest.php

+25-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use ArrayObject;
1313
use PHPUnit_Framework_TestCase as TestCase;
14-
use Zend\Mvc\Service\ControllerLoaderFactory;
14+
use Zend\Mvc\Service\ControllerManagerFactory;
1515
use Zend\Mvc\Service\ControllerPluginManagerFactory;
1616
use Zend\Mvc\Service\DiFactory;
1717
use Zend\Mvc\Service\DiStrictAbstractServiceFactoryFactory;
@@ -22,7 +22,7 @@
2222
use Zend\ServiceManager\ServiceManager;
2323
use Zend\Mvc\Exception;
2424

25-
class ControllerLoaderFactoryTest extends TestCase
25+
class ControllerManagerFactoryTest extends TestCase
2626
{
2727
/**
2828
* @var ServiceManager
@@ -32,15 +32,15 @@ class ControllerLoaderFactoryTest extends TestCase
3232
/**
3333
* @var \Zend\Mvc\Controller\ControllerManager
3434
*/
35-
protected $loader;
35+
protected $manager;
3636

3737
public function setUp()
3838
{
39-
$loaderFactory = new ControllerLoaderFactory();
40-
$config = new ArrayObject(['di' => []]);
39+
$managerFactory = new ControllerManagerFactory();
40+
$config = new ArrayObject(array('di' => []);
4141
$this->services = new ServiceManager();
4242
$this->services->setService('Zend\ServiceManager\ServiceLocatorInterface', $this->services);
43-
$this->services->setFactory('ControllerLoader', $loaderFactory);
43+
$this->services->setFactory('ControllerManager', $managerFactory);
4444
$this->services->setService('Config', $config);
4545
$this->services->setFactory('ControllerPluginManager', new ControllerPluginManagerFactory());
4646
$this->services->setFactory('Di', new DiFactory());
@@ -53,13 +53,13 @@ public function setUp()
5353

5454
public function testCannotLoadInvalidDispatchable()
5555
{
56-
$this->loader = $this->services->get('ControllerLoader');
56+
$this->manager = $this->services->get('ControllerManager');
5757

5858
// Ensure the class exists and can be autoloaded
5959
$this->assertTrue(class_exists('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass'));
6060

6161
try {
62-
$this->loader->get('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass');
62+
$this->manager->get('ZendTest\Mvc\Service\TestAsset\InvalidDispatchableClass');
6363
$this->fail('Retrieving the invalid dispatchable should fail');
6464
} catch (\Exception $e) {
6565
do {
@@ -70,25 +70,31 @@ public function testCannotLoadInvalidDispatchable()
7070

7171
public function testCannotLoadControllerFromPeer()
7272
{
73-
$this->loader = $this->services->get('ControllerLoader');
73+
$this->manager = $this->services->get('ControllerManager');
7474
$this->services->setService('foo', $this);
7575

7676
$this->setExpectedException('Zend\ServiceManager\Exception\ExceptionInterface');
77-
$this->loader->get('foo');
77+
$this->manager->get('foo');
7878
}
7979

8080
public function testControllerLoadedCanBeInjectedWithValuesFromPeer()
8181
{
82+
<<<<<<< HEAD:test/Service/ControllerLoaderFactoryTest.php
8283
$this->loader = $this->services->get('ControllerLoader');
8384
$config = [
8485
'invokables' => [
86+
=======
87+
$this->manager = $this->services->get('ControllerManager');
88+
$config = array(
89+
'invokables' => array(
90+
>>>>>>> remove ControllerLoader, use ControllerManager instead:test/Service/ControllerManagerFactoryTest.php
8591
'ZendTest\Dispatchable' => 'ZendTest\Mvc\Service\TestAsset\Dispatchable',
8692
],
8793
];
8894
$config = new Config($config);
89-
$config->configureServiceManager($this->loader);
95+
$config->configureServiceManager($this->manager);
9096

91-
$controller = $this->loader->get('ZendTest\Dispatchable');
97+
$controller = $this->manager->get('ZendTest\Dispatchable');
9298
$this->assertInstanceOf('ZendTest\Mvc\Service\TestAsset\Dispatchable', $controller);
9399
$this->assertSame($this->services, $controller->getServiceLocator());
94100
$this->assertSame($this->services->get('EventManager'), $controller->getEventManager());
@@ -111,12 +117,12 @@ public function testWillInstantiateControllersFromDiAbstractFactoryWhenWhitelist
111117
]);
112118
$this->services->setAllowOverride(true);
113119
$this->services->setService('Config', $config);
114-
$this->loader = $this->services->get('ControllerLoader');
120+
$this->manager = $this->services->get('ControllerManager');
115121

116-
$this->assertTrue($this->loader->has('my-controller'));
122+
$this->assertTrue($this->manager->has('my-controller'));
117123
// invalid controller exception (because we're getting an \stdClass after all)
118124
$this->setExpectedException('Zend\Mvc\Exception\InvalidControllerException');
119-
$this->loader->get('my-controller');
125+
$this->manager->get('my-controller');
120126
}
121127

122128
public function testWillNotInstantiateControllersFromDiAbstractFactoryWhenNotWhitelisted()
@@ -135,9 +141,9 @@ public function testWillNotInstantiateControllersFromDiAbstractFactoryWhenNotWhi
135141
]);
136142
$this->services->setAllowOverride(true);
137143
$this->services->setService('Config', $config);
138-
$this->loader = $this->services->get('ControllerLoader');
144+
$this->manager = $this->services->get('ControllerManager');
139145
$this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException');
140-
$this->loader->get('evil-controller');
146+
$this->manager->get('evil-controller');
141147
}
142148

143149
public function testWillFetchDiDependenciesFromControllerLoaderServiceManager()
@@ -160,12 +166,12 @@ public function testWillFetchDiDependenciesFromControllerLoaderServiceManager()
160166
]);
161167
$this->services->setAllowOverride(true);
162168
$this->services->setService('Config', $config);
163-
$this->loader = $this->services->get('ControllerLoader');
169+
$this->manager = $this->services->get('ControllerManager');
164170

165171
$testService = new \stdClass();
166172
$this->services->setService('stdClass', $testService);
167173
// invalid controller exception (because we're not getting a \Zend\Stdlib\DispatchableInterface after all)
168-
$controller = $this->loader->get($controllerName);
174+
$controller = $this->manager->get($controllerName);
169175
$this->assertSame($testService, $controller->injectedValue);
170176
}
171177

0 commit comments

Comments
 (0)