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\ContainerExceptionInterface; |
12
|
|
|
use Psr\Container\ContainerInterface; |
13
|
|
|
use Psr\EventDispatcher\ListenerProviderInterface; |
14
|
|
|
|
15
|
|
|
abstract class AbstractEventDispatcherFactory extends AbstractFactory |
16
|
|
|
{ |
17
|
|
|
use ListenerRegistrationTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Attempt to resolve or build the AddableListenerProviderInterface |
21
|
|
|
* |
22
|
|
|
* @param ContainerInterface&ServiceLocatorInterface $container |
23
|
|
|
* @param ListenerProviderInterface|string|array<mixed> $listenerProviderConfig |
24
|
|
|
* @param string $serviceName |
25
|
|
|
* |
26
|
|
|
* @return ListenerProviderInterface |
27
|
|
|
* |
28
|
|
|
* @throws ServiceNotCreatedException |
29
|
|
|
* @throws ContainerExceptionInterface |
30
|
|
|
*/ |
31
|
|
|
protected function getListenerProvider( |
32
|
|
|
ContainerInterface $container, |
33
|
|
|
$listenerProviderConfig, |
34
|
|
|
string $serviceName |
35
|
|
|
): ListenerProviderInterface { |
36
|
|
|
$listenerProvider = $listenerProviderConfig; |
37
|
|
|
|
38
|
|
|
if (is_string($listenerProviderConfig)) { |
39
|
|
|
$listenerProvider = $this->getService($container, $listenerProviderConfig, $serviceName); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (is_array($listenerProviderConfig)) { |
43
|
|
|
$listenerProvider = $this->buildService( |
44
|
|
|
$container, |
45
|
|
|
ListenerProviderInterface::class, |
46
|
|
|
$listenerProviderConfig, |
47
|
|
|
$serviceName |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (!$listenerProvider instanceof ListenerProviderInterface) { |
52
|
|
|
throw new ServiceNotCreatedException( |
53
|
|
|
sprintf( |
54
|
|
|
'The listener provider must be an object of type \'%s\'; \'%s\' provided for service \'%s\'', |
55
|
|
|
ListenerProviderInterface::class, |
56
|
|
|
is_object($listenerProviderConfig) |
57
|
|
|
? get_class($listenerProviderConfig) |
58
|
|
|
: gettype($listenerProviderConfig), |
59
|
|
|
$serviceName |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $listenerProvider; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|