Skip to content

Commit 647e2fc

Browse files
committed
Merge pull request #637 from Eye4web/hotfix/servicemanager
Hotfix/servicemanager
2 parents fd103f7 + c447f6e commit 647e2fc

8 files changed

Lines changed: 82 additions & 32 deletions

File tree

Module.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public function getServiceConfig()
6767
'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
6868
),
6969
'invokables' => array(
70-
'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db',
71-
'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Authentication\Storage\Db',
7270
'zfcuser_user_service' => 'ZfcUser\Service\User',
7371
'zfcuser_register_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
7472
),
@@ -89,6 +87,9 @@ public function getServiceConfig()
8987
'zfcuser_register_form' => 'ZfcUser\Factory\Form\Register',
9088
'zfcuser_change_password_form' => 'ZfcUser\Factory\Form\ChangePassword',
9189
'zfcuser_change_email_form' => 'ZfcUser\Factory\Form\ChangeEmail',
90+
91+
'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Factory\Authentication\Adapter\DbFactory',
92+
'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Factory\Authentication\Storage\DbFactory',
9293
),
9394
);
9495
}

src/ZfcUser/Authentication/Adapter/Db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use ZfcUser\Mapper\User as UserMapperInterface;
1313
use ZfcUser\Options\AuthenticationOptionsInterface;
1414

15-
class Db extends AbstractAdapter implements ServiceManagerAwareInterface
15+
class Db extends AbstractAdapter
1616
{
1717
/**
1818
* @var UserMapperInterface

src/ZfcUser/Authentication/Storage/Db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Zend\ServiceManager\ServiceManager;
99
use ZfcUser\Mapper\UserInterface as UserMapper;
1010

11-
class Db implements Storage\StorageInterface, ServiceManagerAwareInterface
11+
class Db implements Storage\StorageInterface
1212
{
1313
/**
1414
* @var StorageInterface

src/ZfcUser/Controller/UserController.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Zend\Form\FormInterface;
66
use Zend\Mvc\Controller\AbstractActionController;
7+
use Zend\ServiceManager\ServiceLocatorInterface;
78
use Zend\Stdlib\ResponseInterface as Response;
89
use Zend\Stdlib\Parameters;
910
use Zend\View\Model\ViewModel;
@@ -60,6 +61,11 @@ class UserController extends AbstractActionController
6061
*/
6162
protected $redirectCallback;
6263

64+
/**
65+
* @var ServiceLocatorInterface
66+
*/
67+
protected $serviceLocator;
68+
6369
/**
6470
* @param callable $redirectCallback
6571
*/
@@ -348,7 +354,7 @@ public function changeEmailAction()
348354
public function getUserService()
349355
{
350356
if (!$this->userService) {
351-
$this->userService = $this->getServiceLocator()->get('zfcuser_user_service');
357+
$this->userService = $this->serviceLocator->get('zfcuser_user_service');
352358
}
353359
return $this->userService;
354360
}
@@ -362,7 +368,7 @@ public function setUserService(UserService $userService)
362368
public function getRegisterForm()
363369
{
364370
if (!$this->registerForm) {
365-
$this->setRegisterForm($this->getServiceLocator()->get('zfcuser_register_form'));
371+
$this->setRegisterForm($this->serviceLocator->get('zfcuser_register_form'));
366372
}
367373
return $this->registerForm;
368374
}
@@ -375,7 +381,7 @@ public function setRegisterForm(FormInterface$registerForm)
375381
public function getLoginForm()
376382
{
377383
if (!$this->loginForm) {
378-
$this->setLoginForm($this->getServiceLocator()->get('zfcuser_login_form'));
384+
$this->setLoginForm($this->serviceLocator->get('zfcuser_login_form'));
379385
}
380386
return $this->loginForm;
381387
}
@@ -395,7 +401,7 @@ public function setLoginForm(FormInterface $loginForm)
395401
public function getChangePasswordForm()
396402
{
397403
if (!$this->changePasswordForm) {
398-
$this->setChangePasswordForm($this->getServiceLocator()->get('zfcuser_change_password_form'));
404+
$this->setChangePasswordForm($this->serviceLocator->get('zfcuser_change_password_form'));
399405
}
400406
return $this->changePasswordForm;
401407
}
@@ -426,7 +432,7 @@ public function setOptions(UserControllerOptionsInterface $options)
426432
public function getOptions()
427433
{
428434
if (!$this->options instanceof UserControllerOptionsInterface) {
429-
$this->setOptions($this->getServiceLocator()->get('zfcuser_module_options'));
435+
$this->setOptions($this->serviceLocator->get('zfcuser_module_options'));
430436
}
431437
return $this->options;
432438
}
@@ -438,7 +444,7 @@ public function getOptions()
438444
public function getChangeEmailForm()
439445
{
440446
if (!$this->changeEmailForm) {
441-
$this->setChangeEmailForm($this->getServiceLocator()->get('zfcuser_change_email_form'));
447+
$this->setChangeEmailForm($this->serviceLocator->get('zfcuser_change_email_form'));
442448
}
443449
return $this->changeEmailForm;
444450
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ZfcUser\Factory\Authentication\Adapter;
4+
5+
use Zend\ServiceManager\FactoryInterface;
6+
use Zend\ServiceManager\ServiceLocatorInterface;
7+
use ZfcUser\Authentication\Adapter\Db;
8+
9+
class DbFactory implements FactoryInterface
10+
{
11+
12+
/**
13+
* Create service
14+
*
15+
* @param ServiceLocatorInterface $serviceLocator
16+
* @return mixed
17+
*/
18+
public function createService(ServiceLocatorInterface $serviceLocator)
19+
{
20+
$db = new Db();
21+
$db->setServiceManager($serviceLocator);
22+
return $db;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ZfcUser\Factory\Authentication\Storage;
4+
5+
use Zend\ServiceManager\FactoryInterface;
6+
use Zend\ServiceManager\ServiceLocatorInterface;
7+
use ZfcUser\Authentication\Storage\Db;
8+
9+
class DbFactory implements FactoryInterface
10+
{
11+
12+
/**
13+
* Create service
14+
*
15+
* @param ServiceLocatorInterface $serviceLocator
16+
* @return mixed
17+
*/
18+
public function createService(ServiceLocatorInterface $serviceLocator)
19+
{
20+
$db = new Db();
21+
$db->setServiceManager($serviceLocator);
22+
return $db;
23+
}
24+
}

src/ZfcUser/Factory/Controller/UserControllerFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public function createService(ServiceLocatorInterface $controllerManager)
3333

3434
/* @var UserController $controller */
3535
$controller = new UserController($redirectCallback);
36+
$controller->setServiceLocator($serviceManager);
37+
38+
$controller->setChangeEmailForm($this->serviceLocator->get('zfcuser_change_email_form'));
39+
$controller->setOptions($this->serviceLocator->get('zfcuser_module_options'));
40+
$controller->setChangePasswordForm($this->serviceLocator->get('zfcuser_change_password_form'));
41+
$controller->setLoginForm($this->serviceLocator->get('zfcuser_login_form'));
42+
$controller->setRegisterForm($this->serviceLocator->get('zfcuser_register_form'));
43+
$controller->setUserService($this->serviceLocator->get('zfcuser_user_service'));
3644

3745
return $controller;
3846
}

tests/ZfcUserTest/Controller/UserControllerTest.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ public function testChangeEmailAction($status, $postRedirectGetReturn, $isValid,
964964
* @depend testActionControllHasIdentity
965965
*/
966966
public function testSetterGetterServices(
967-
$methode,
967+
$method,
968968
$useServiceLocator,
969969
$servicePrototype,
970970
$serviceName,
@@ -984,34 +984,21 @@ public function testSetterGetterServices(
984984

985985
if ($useServiceLocator) {
986986
$serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface');
987-
$formElementManager = $this->getMock('Zend\Form\FormElementManager');
988-
# Forms now use the FormElementManager so we need mock accordingly
989-
if ($servicePrototype instanceof Form) {
990-
$serviceLocator->expects($this->once())
991-
->method('get')
992-
->with('FormElementManager')
993-
->will($this->returnValue($formElementManager));
994-
$formElementManager->expects($this->once())
995-
->method('get')
996-
->with($serviceName)
997-
->will($this->returnValue($servicePrototype));
998-
} else {
999-
$serviceLocator->expects($this->once())
1000-
->method('get')
1001-
->with($serviceName)
1002-
->will($this->returnValue($servicePrototype));
1003-
}
987+
$serviceLocator->expects($this->once())
988+
->method('get')
989+
->with($serviceName)
990+
->will($this->returnValue($servicePrototype));
1004991
$controller->setServiceLocator($serviceLocator);
1005992
} else {
1006-
call_user_func(array($controller, 'set' . $methode), $servicePrototype);
993+
call_user_func(array($controller, 'set' . $method), $servicePrototype);
1007994
}
1008995

1009-
$result = call_user_func(array($controller, 'get' . $methode));
996+
$result = call_user_func(array($controller, 'get' . $method));
1010997
$this->assertInstanceOf(get_class($servicePrototype), $result);
1011998
$this->assertSame($servicePrototype, $result);
1012999

10131000
// we need two check for every case
1014-
$result = call_user_func(array($controller, 'get' . $methode));
1001+
$result = call_user_func(array($controller, 'get' . $method));
10151002
$this->assertInstanceOf(get_class($servicePrototype), $result);
10161003
$this->assertSame($servicePrototype, $result);
10171004
}
@@ -1107,7 +1094,7 @@ public function providerTestSetterGetterServices ()
11071094

11081095

11091096
return array(
1110-
// $methode, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback
1097+
// $method, $useServiceLocator, $servicePrototype, $serviceName, $loginFormCallback
11111098
array('UserService', true, new UserService(), 'zfcuser_user_service' ),
11121099
array('UserService', false, new UserService(), null ),
11131100
array('RegisterForm', true, new Form(), 'zfcuser_register_form' ),

0 commit comments

Comments
 (0)