diff --git a/Module.php b/Module.php index eb7ad717..0e0cfa4f 100644 --- a/Module.php +++ b/Module.php @@ -67,8 +67,6 @@ public function getServiceConfig() 'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter', ), 'invokables' => array( - 'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db', - 'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Authentication\Storage\Db', 'zfcuser_user_service' => 'ZfcUser\Service\User', 'zfcuser_register_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods', ), @@ -89,6 +87,9 @@ public function getServiceConfig() 'zfcuser_register_form' => 'ZfcUser\Factory\Form\Register', 'zfcuser_change_password_form' => 'ZfcUser\Factory\Form\ChangePassword', 'zfcuser_change_email_form' => 'ZfcUser\Factory\Form\ChangeEmail', + + 'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Factory\Authentication\Adapter\DbFactory', + 'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Factory\Authentication\Storage\DbFactory', ), ); } diff --git a/src/ZfcUser/Authentication/Adapter/Db.php b/src/ZfcUser/Authentication/Adapter/Db.php index c8a5b24e..a4f0db06 100644 --- a/src/ZfcUser/Authentication/Adapter/Db.php +++ b/src/ZfcUser/Authentication/Adapter/Db.php @@ -12,7 +12,7 @@ use ZfcUser\Mapper\User as UserMapperInterface; use ZfcUser\Options\AuthenticationOptionsInterface; -class Db extends AbstractAdapter implements ServiceManagerAwareInterface +class Db extends AbstractAdapter { /** * @var UserMapperInterface diff --git a/src/ZfcUser/Authentication/Storage/Db.php b/src/ZfcUser/Authentication/Storage/Db.php index d218e87e..f396630e 100644 --- a/src/ZfcUser/Authentication/Storage/Db.php +++ b/src/ZfcUser/Authentication/Storage/Db.php @@ -8,7 +8,7 @@ use Zend\ServiceManager\ServiceManager; use ZfcUser\Mapper\UserInterface as UserMapper; -class Db implements Storage\StorageInterface, ServiceManagerAwareInterface +class Db implements Storage\StorageInterface { /** * @var StorageInterface diff --git a/src/ZfcUser/Controller/UserController.php b/src/ZfcUser/Controller/UserController.php index e9bbd143..48c42df0 100644 --- a/src/ZfcUser/Controller/UserController.php +++ b/src/ZfcUser/Controller/UserController.php @@ -4,6 +4,7 @@ use Zend\Form\FormInterface; use Zend\Mvc\Controller\AbstractActionController; +use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Stdlib\ResponseInterface as Response; use Zend\Stdlib\Parameters; use Zend\View\Model\ViewModel; @@ -60,6 +61,11 @@ class UserController extends AbstractActionController */ protected $redirectCallback; + /** + * @var ServiceLocatorInterface + */ + protected $serviceLocator; + /** * @param callable $redirectCallback */ @@ -348,7 +354,7 @@ public function changeEmailAction() public function getUserService() { if (!$this->userService) { - $this->userService = $this->getServiceLocator()->get('zfcuser_user_service'); + $this->userService = $this->serviceLocator->get('zfcuser_user_service'); } return $this->userService; } @@ -362,7 +368,7 @@ public function setUserService(UserService $userService) public function getRegisterForm() { if (!$this->registerForm) { - $this->setRegisterForm($this->getServiceLocator()->get('zfcuser_register_form')); + $this->setRegisterForm($this->serviceLocator->get('zfcuser_register_form')); } return $this->registerForm; } @@ -375,7 +381,7 @@ public function setRegisterForm(FormInterface$registerForm) public function getLoginForm() { if (!$this->loginForm) { - $this->setLoginForm($this->getServiceLocator()->get('zfcuser_login_form')); + $this->setLoginForm($this->serviceLocator->get('zfcuser_login_form')); } return $this->loginForm; } @@ -395,7 +401,7 @@ public function setLoginForm(FormInterface $loginForm) public function getChangePasswordForm() { if (!$this->changePasswordForm) { - $this->setChangePasswordForm($this->getServiceLocator()->get('zfcuser_change_password_form')); + $this->setChangePasswordForm($this->serviceLocator->get('zfcuser_change_password_form')); } return $this->changePasswordForm; } @@ -426,7 +432,7 @@ public function setOptions(UserControllerOptionsInterface $options) public function getOptions() { if (!$this->options instanceof UserControllerOptionsInterface) { - $this->setOptions($this->getServiceLocator()->get('zfcuser_module_options')); + $this->setOptions($this->serviceLocator->get('zfcuser_module_options')); } return $this->options; } @@ -438,7 +444,7 @@ public function getOptions() public function getChangeEmailForm() { if (!$this->changeEmailForm) { - $this->setChangeEmailForm($this->getServiceLocator()->get('zfcuser_change_email_form')); + $this->setChangeEmailForm($this->serviceLocator->get('zfcuser_change_email_form')); } return $this->changeEmailForm; } diff --git a/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php b/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php new file mode 100644 index 00000000..9766089f --- /dev/null +++ b/src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php @@ -0,0 +1,24 @@ +setServiceManager($serviceLocator); + return $db; + } +} diff --git a/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php b/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php new file mode 100644 index 00000000..fa8a274f --- /dev/null +++ b/src/ZfcUser/Factory/Authentication/Storage/DbFactory.php @@ -0,0 +1,24 @@ +setServiceManager($serviceLocator); + return $db; + } +} diff --git a/src/ZfcUser/Factory/Controller/UserControllerFactory.php b/src/ZfcUser/Factory/Controller/UserControllerFactory.php index 78ed0305..782ebfb6 100644 --- a/src/ZfcUser/Factory/Controller/UserControllerFactory.php +++ b/src/ZfcUser/Factory/Controller/UserControllerFactory.php @@ -33,6 +33,14 @@ public function createService(ServiceLocatorInterface $controllerManager) /* @var UserController $controller */ $controller = new UserController($redirectCallback); + $controller->setServiceLocator($serviceManager); + + $controller->setChangeEmailForm($this->serviceLocator->get('zfcuser_change_email_form')); + $controller->setOptions($this->serviceLocator->get('zfcuser_module_options')); + $controller->setChangePasswordForm($this->serviceLocator->get('zfcuser_change_password_form')); + $controller->setLoginForm($this->serviceLocator->get('zfcuser_login_form')); + $controller->setRegisterForm($this->serviceLocator->get('zfcuser_register_form')); + $controller->setUserService($this->serviceLocator->get('zfcuser_user_service')); return $controller; } diff --git a/tests/ZfcUserTest/Controller/UserControllerTest.php b/tests/ZfcUserTest/Controller/UserControllerTest.php index c08759f1..f4072312 100644 --- a/tests/ZfcUserTest/Controller/UserControllerTest.php +++ b/tests/ZfcUserTest/Controller/UserControllerTest.php @@ -964,7 +964,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid, * @depend testActionControllHasIdentity */ public function testSetterGetterServices( - $methode, + $method, $useServiceLocator, $servicePrototype, $serviceName, @@ -984,34 +984,21 @@ public function testSetterGetterServices( if ($useServiceLocator) { $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); - $formElementManager = $this->getMock('Zend\Form\FormElementManager'); - # Forms now use the FormElementManager so we need mock accordingly - if ($servicePrototype instanceof Form) { - $serviceLocator->expects($this->once()) - ->method('get') - ->with('FormElementManager') - ->will($this->returnValue($formElementManager)); - $formElementManager->expects($this->once()) - ->method('get') - ->with($serviceName) - ->will($this->returnValue($servicePrototype)); - } else { - $serviceLocator->expects($this->once()) - ->method('get') - ->with($serviceName) - ->will($this->returnValue($servicePrototype)); - } + $serviceLocator->expects($this->once()) + ->method('get') + ->with($serviceName) + ->will($this->returnValue($servicePrototype)); $controller->setServiceLocator($serviceLocator); } else { - call_user_func(array($controller, 'set' . $methode), $servicePrototype); + call_user_func(array($controller, 'set' . $method), $servicePrototype); } - $result = call_user_func(array($controller, 'get' . $methode)); + $result = call_user_func(array($controller, 'get' . $method)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); // we need two check for every case - $result = call_user_func(array($controller, 'get' . $methode)); + $result = call_user_func(array($controller, 'get' . $method)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); } @@ -1107,7 +1094,7 @@ public function providerTestSetterGetterServices () return array( - // $methode, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback + // $method, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback array('UserService', true, new UserService(), 'zfcuser_user_service' ), array('UserService', false, new UserService(), null ), array('RegisterForm', true, new Form(), 'zfcuser_register_form' ),