Completed
Push — master ( b9492e...31cd44 )
by Alexander
11:15
created

Aggregate::attach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yiisoft\EventDispatcher\Provider;
4
5
use Psr\EventDispatcher\ListenerProviderInterface;
6
7
/**
8
 * Aggregate is a listener provider that allows combining
9
 * multiple listener providers.
10
 */
11
final class Aggregate implements ListenerProviderInterface
12
{
13
    /**
14
     * @var ListenerProviderInterface[]
15
     */
16
    private $providers;
17
18
    public function getListenersForEvent(object $event): iterable
19
    {
20
        foreach ($this->providers as $provider) {
21
            yield from $provider->getListenersForEvent($event);
22
        }
23
    }
24
25
    /**
26
     * Adds provider as a source for event listeners
27
     *
28
     * @param ListenerProviderInterface $provider
29
     */
30
    public function attach(ListenerProviderInterface $provider): void
31
    {
32
        $this->providers[] = $provider;
33
    }
34
}
35