|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @author cbleek |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Auth\Factory\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
14
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
15
|
|
|
use Zend\Log\LoggerInterface; |
|
16
|
|
|
use Auth\Controller\IndexController; |
|
17
|
|
|
use Auth\Form\Register; |
|
18
|
|
|
|
|
19
|
|
|
class IndexControllerFactory implements FactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Create controller |
|
23
|
|
|
* |
|
24
|
|
|
* @param ServiceLocatorInterface $controllerManager |
|
25
|
|
|
* |
|
26
|
|
|
* @return IndexController |
|
27
|
|
|
*/ |
|
28
|
|
|
public function createService(ServiceLocatorInterface $controllerManager) |
|
29
|
|
|
{ |
|
30
|
|
|
/* @var ServiceLocatorInterface $serviceLocator */ |
|
31
|
|
|
$serviceLocator = $controllerManager->getServiceLocator(); |
|
|
|
|
|
|
32
|
|
|
$auth = $serviceLocator->get('AuthenticationService'); |
|
33
|
|
|
$loginForm = $serviceLocator->get('Auth\Form\Login'); |
|
34
|
|
|
|
|
35
|
|
|
/* @var $logger LoggerInterface*/ |
|
36
|
|
|
$logger = $serviceLocator->get('Core/Log'); |
|
37
|
|
|
|
|
38
|
|
|
/* @var $options \Auth\Options\ModuleOptions */ |
|
39
|
|
|
$options = $serviceLocator->get('Auth/Options'); |
|
40
|
|
|
|
|
41
|
|
|
$forms[IndexController::LOGIN] = $loginForm; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
if ($options->getEnableRegistration()) { |
|
44
|
|
|
/* @var $registerForm Register */ |
|
45
|
|
|
$registerForm = $serviceLocator->get('Auth\Form\Register'); |
|
46
|
|
|
|
|
47
|
|
|
/* @var \Zend\ServiceManager\AbstractPluginManager $serviceLocator */ |
|
48
|
|
|
/* @var \Zend\Mvc\MvcEvent $event */ |
|
49
|
|
|
#$event = $controllerManager->getServiceLocator()->get('application')->getMvcEvent(); |
|
|
|
|
|
|
50
|
|
|
#$lang = $event->getRouteMatch(); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
#$registerForm->setAttribute("action", $this->s); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$forms[IndexController::REGISTER] = $registerForm; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$controller = new IndexController($auth, $logger, $forms, $options); |
|
|
|
|
|
|
58
|
|
|
return $controller; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: