|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @author cbleek |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Auth\Factory\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Interop\Container\ContainerInterface; |
|
14
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
15
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
16
|
|
|
use Zend\Log\LoggerInterface; |
|
17
|
|
|
use Auth\Controller\IndexController; |
|
18
|
|
|
use Auth\Form\Register; |
|
19
|
|
|
|
|
20
|
|
|
class IndexControllerFactory implements FactoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create an IndexController controller |
|
26
|
|
|
* |
|
27
|
|
|
* @param ContainerInterface $container |
|
28
|
|
|
* @param string $requestedName |
|
29
|
|
|
* @param null|array $options |
|
30
|
|
|
* |
|
31
|
|
|
* @return IndexController |
|
32
|
|
|
* @throws ServiceNotFoundException if unable to resolve the service. |
|
33
|
|
|
* @throws ServiceNotCreatedException if an exception is raised when |
|
34
|
|
|
* creating a service. |
|
35
|
|
|
* @throws ContainerException if any other error occurs |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$auth = $container->get('AuthenticationService'); |
|
40
|
|
|
$formElementManager = $container->get('formElementManager'); |
|
41
|
|
|
$loginForm = $formElementManager->get('Auth\Form\Login'); |
|
42
|
|
|
|
|
43
|
|
|
/* @var $logger LoggerInterface*/ |
|
44
|
|
|
$logger = $container->get('Core/Log'); |
|
45
|
|
|
|
|
46
|
|
|
/* @var $options \Auth\Options\ModuleOptions */ |
|
47
|
|
|
$options = $container->get('Auth/Options'); |
|
48
|
|
|
|
|
49
|
|
|
$forms[IndexController::LOGIN] = $loginForm; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
if ($options->getEnableRegistration()) { |
|
52
|
|
|
/* @var $registerForm Register */ |
|
53
|
|
|
$registerForm = $formElementManager->get('Auth\Form\Register'); |
|
54
|
|
|
$forms[IndexController::REGISTER] = $registerForm; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$controller = new IndexController($auth, $logger, $forms, $options); |
|
58
|
|
|
return $controller; |
|
59
|
|
|
} |
|
60
|
|
|
/** |
|
61
|
|
|
* Create controller |
|
62
|
|
|
* |
|
63
|
|
|
* @param ServiceLocatorInterface $controllerManager |
|
64
|
|
|
* |
|
65
|
|
|
* @return IndexController |
|
66
|
|
|
*/ |
|
67
|
|
|
public function createService(ServiceLocatorInterface $controllerManager) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this($controllerManager->getServiceLocator(), UserStatusFieldset::class); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.