|
1
|
|
|
<?php |
|
2
|
|
|
namespace LmcUser\Authentication\Adapter; |
|
3
|
|
|
|
|
4
|
|
|
use Interop\Container\ContainerInterface; |
|
5
|
|
|
use Interop\Container\Exception\ContainerException; |
|
6
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
|
7
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
|
8
|
|
|
use Laminas\ServiceManager\Factory\FactoryInterface; |
|
9
|
|
|
use Laminas\ServiceManager\ServiceLocatorInterface; |
|
10
|
|
|
use LmcUser\Authentication\Adapter\AdapterChain; |
|
11
|
|
|
use LmcUser\Options\ModuleOptions; |
|
12
|
|
|
use LmcUser\Authentication\Adapter\Exception\OptionsNotFoundException; |
|
13
|
|
|
|
|
14
|
|
|
class AdapterChainServiceFactory implements FactoryInterface |
|
15
|
|
|
{ |
|
16
|
|
|
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null) |
|
17
|
|
|
{ |
|
18
|
|
|
$chain = new AdapterChain(); |
|
19
|
|
|
$chain->setEventManager($serviceLocator->get('EventManager')); |
|
20
|
|
|
|
|
21
|
|
|
$options = $this->getOptions($serviceLocator); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
//iterate and attach multiple adapters and events if offered |
|
24
|
|
|
foreach ($options->getAuthAdapters() as $priority => $adapterName) { |
|
25
|
|
|
$adapter = $serviceLocator->get($adapterName); |
|
26
|
|
|
|
|
27
|
|
|
if (is_callable(array($adapter, 'authenticate'))) { |
|
28
|
|
|
$chain->getEventManager()->attach('authenticate', array($adapter, 'authenticate'), $priority); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (is_callable(array($adapter, 'logout'))) { |
|
32
|
|
|
$chain->getEventManager()->attach('logout', array($adapter, 'logout'), $priority); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return $chain; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ModuleOptions |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $options; |
|
43
|
|
|
|
|
44
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->__invoke($serviceLocator, null); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* set options |
|
52
|
|
|
* |
|
53
|
|
|
* @param ModuleOptions $options |
|
54
|
|
|
* @return AdapterChainServiceFactory |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setOptions(ModuleOptions $options) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->options = $options; |
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* get options |
|
64
|
|
|
* |
|
65
|
|
|
* @param ServiceLocatorInterface $serviceLocator (optional) Service Locator |
|
66
|
|
|
* @return ModuleOptions $options |
|
67
|
|
|
* @throws OptionsNotFoundException If options tried to retrieve without being set but no SL was provided |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getOptions(ServiceLocatorInterface $serviceLocator = null) |
|
70
|
|
|
{ |
|
71
|
|
|
if (!$this->options) { |
|
72
|
|
|
if (!$serviceLocator) { |
|
73
|
|
|
throw new OptionsNotFoundException( |
|
74
|
|
|
'Options were tried to retrieve but not set ' . |
|
75
|
|
|
'and no service locator was provided' |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->setOptions($serviceLocator->get('lmcuser_module_options')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->options; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: