-
Notifications
You must be signed in to change notification settings - Fork 91
[ZF3] [bc-break] remove ControllerLoader, use ControllerManager instead #6
Changes from 1 commit
9d78688
00367b4
e875a0a
5e0828c
73c94e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ControllerLoaderFactory implements FactoryInterface | ||
class ControllerManagerFactory implements FactoryInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add description with the purpose of the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any suggestion description ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the SRP of SOLID describe what is this class responsible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
/** | ||
* Create the controller loader service | ||
|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old key must be preserved for bc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now it for 3.0, can be actually removed. |
||
'ControllerPluginManager' => 'Zend\Mvc\Service\ControllerPluginManagerFactory', | ||
'ConsoleAdapter' => 'Zend\Mvc\Service\ConsoleAdapterFactory', | ||
'ConsoleRouter' => 'Zend\Mvc\Service\RouterFactory', | ||
|
@@ -94,8 +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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, at ZF3, the old one ( ControllerLoader ) will no longer used. zendframework/zendframework#4962 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to add back closing "]", fixed now |
||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
$config = new ArrayObject(['di' => []]); | ||
$managerFactory = new ControllerManagerFactory(); | ||
$config = new ArrayObject(array('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,31 @@ 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() | ||
{ | ||
<<<<<<< HEAD:test/Service/ControllerLoaderFactoryTest.php | ||
$this->loader = $this->services->get('ControllerLoader'); | ||
$config = [ | ||
'invokables' => [ | ||
======= | ||
$this->manager = $this->services->get('ControllerManager'); | ||
$config = array( | ||
'invokables' => array( | ||
>>>>>>> remove ControllerLoader, use ControllerManager instead:test/Service/ControllerManagerFactoryTest.php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad rebase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||
'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 +117,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 +141,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 +166,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); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead create a new class and inherit the old one from the new one. By this way BC is preserved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is for ZF3, I thik it is ok to remove the old one /cc @weierophinney
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it and this could be merged in 2.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, and
ControllerLoaderFactory
marked as @deprecated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as zendframework/zend-authentication#2 (comment) , ControllerLoader actually removed for 3.0