Skip to content

Commit

Permalink
Merge pull request #637 from Eye4web/hotfix/servicemanager
Browse files Browse the repository at this point in the history
Hotfix/servicemanager
  • Loading branch information
Danielss89 committed May 5, 2016
2 parents fd103f7 + c447f6e commit 647e2fc
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 32 deletions.
5 changes: 3 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
Expand All @@ -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',
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcUser/Authentication/Adapter/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcUser/Authentication/Storage/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/ZfcUser/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +61,11 @@ class UserController extends AbstractActionController
*/
protected $redirectCallback;

/**
* @var ServiceLocatorInterface
*/
protected $serviceLocator;

/**
* @param callable $redirectCallback
*/
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/ZfcUser/Factory/Authentication/Adapter/DbFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ZfcUser\Factory\Authentication\Adapter;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Authentication\Adapter\Db;

class DbFactory implements FactoryInterface
{

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$db = new Db();
$db->setServiceManager($serviceLocator);
return $db;
}
}
24 changes: 24 additions & 0 deletions src/ZfcUser/Factory/Authentication/Storage/DbFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ZfcUser\Factory\Authentication\Storage;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Authentication\Storage\Db;

class DbFactory implements FactoryInterface
{

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$db = new Db();
$db->setServiceManager($serviceLocator);
return $db;
}
}
8 changes: 8 additions & 0 deletions src/ZfcUser/Factory/Controller/UserControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
31 changes: 9 additions & 22 deletions tests/ZfcUserTest/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid,
* @depend testActionControllHasIdentity
*/
public function testSetterGetterServices(
$methode,
$method,
$useServiceLocator,
$servicePrototype,
$serviceName,
Expand All @@ -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);
}
Expand Down Expand Up @@ -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' ),
Expand Down

0 comments on commit 647e2fc

Please sign in to comment.