|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasEvent\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\LaminasEvent\Factory\Listener\ListenerRegistrationTrait; |
|
8
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
|
9
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
|
10
|
|
|
use Laminas\ServiceManager\ServiceLocatorInterface; |
|
11
|
|
|
use Psr\Container\ContainerInterface; |
|
12
|
|
|
use Psr\EventDispatcher\ListenerProviderInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Alex Patterson <[email protected]> |
|
16
|
|
|
* @package Arp\LaminasEvent\Factory |
|
17
|
|
|
*/ |
|
18
|
|
|
abstract class AbstractEventDispatcherFactory extends AbstractFactory |
|
19
|
|
|
{ |
|
20
|
|
|
use ListenerRegistrationTrait; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Attempt to resolve or build the AddableListenerProviderInterface |
|
24
|
|
|
* |
|
25
|
|
|
* @param ContainerInterface&ServiceLocatorInterface $container |
|
26
|
|
|
* @param ListenerProviderInterface|string|array<mixed> $listenerProviderConfig |
|
27
|
|
|
* @param string $serviceName |
|
28
|
|
|
* |
|
29
|
|
|
* @return ListenerProviderInterface |
|
30
|
|
|
* |
|
31
|
|
|
* @throws ServiceNotCreatedException |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function getListenerProvider( |
|
34
|
|
|
ContainerInterface $container, |
|
35
|
|
|
$listenerProviderConfig, |
|
36
|
|
|
string $serviceName |
|
37
|
|
|
): ListenerProviderInterface { |
|
38
|
|
|
$listenerProvider = $listenerProviderConfig; |
|
39
|
|
|
|
|
40
|
|
|
if (is_string($listenerProviderConfig)) { |
|
41
|
|
|
$listenerProvider = $this->getService($container, $listenerProviderConfig, $serviceName); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (is_array($listenerProviderConfig)) { |
|
45
|
|
|
$listenerProvider = $this->buildService( |
|
46
|
|
|
$container, |
|
47
|
|
|
ListenerProviderInterface::class, |
|
48
|
|
|
$listenerProviderConfig, |
|
49
|
|
|
$serviceName |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if (!$listenerProvider instanceof ListenerProviderInterface) { |
|
54
|
|
|
throw new ServiceNotCreatedException( |
|
55
|
|
|
sprintf( |
|
56
|
|
|
'The listener provider must be an object of type \'%s\'; \'%s\' provided for service \'%s\'', |
|
57
|
|
|
ListenerProviderInterface::class, |
|
58
|
|
|
is_object($listenerProviderConfig) |
|
59
|
|
|
? get_class($listenerProviderConfig) |
|
60
|
|
|
: gettype($listenerProviderConfig), |
|
61
|
|
|
$serviceName |
|
62
|
|
|
) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $listenerProvider; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|