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

Aggregate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getListenersForEvent() 0 6 2
A attach() 0 4 1
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