ListenerProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace OpenEngine\EventDispatcher;
4
5
use OpenEngine\EventDispatcher\Interfaces\ListenerProviderConfigInterface;
6
use Psr\EventDispatcher\ListenerProviderInterface;
7
8
/**
9
 * Mapper from an event to the listeners that are applicable to that event.
10
 */
11
class ListenerProvider implements ListenerProviderInterface
12
{
13
    /**
14
     * @var ListenerProviderConfigInterface
15
     */
16
    private $config;
17
18
    /**
19
     * ListenerProvider constructor.
20
     * @param ListenerProviderConfigInterface $config
21
     */
22
    public function __construct(ListenerProviderConfigInterface $config)
23
    {
24
        $this->config = $config;
25
    }
26
27
    /**
28
     * @param object $event
29
     *   An event for which to return the relevant listeners.
30
     * @return iterable[callable]
31
     *   An iterable (array, iterator, or generator) of callables.  Each
32
     *   callable MUST be type-compatible with $event.
33
     */
34
    public function getListenersForEvent(object $event): iterable
35
    {
36
        return $this->config->getListeners(\get_class($event));
37
    }
38
}
39