-
Notifications
You must be signed in to change notification settings - Fork 8
/
AggregateProvider.php
44 lines (38 loc) · 1.24 KB
/
AggregateProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Fig\EventDispatcher;
use Psr\EventDispatcher\ListenerProviderInterface;
/**
* An aggregate provider encapsulates multiple other providers and concatenates their responses.
*
* Be aware that any ordering of listeners in different sub-providers is ignored, and providers are
* iterated in the order in which they were added. That is, all listeners from the first provider
* added will be returned to the caller, then all listeners from the second provider, and so on.
*/
class AggregateProvider implements ListenerProviderInterface
{
/**
* @var array
*/
protected $providers = [];
public function getListenersForEvent(object $event): iterable
{
/** @var ListenerProviderInterface $provider */
foreach ($this->providers as $provider) {
yield from $provider->getListenersForEvent($event);
}
}
/**
* Enqueues a listener provider to this set.
*
* @param ListenerProviderInterface $provider
* The provider to add.
* @return AggregateProvider
* The called object.
*/
public function addProvider(ListenerProviderInterface $provider): self
{
$this->providers[] = $provider;
return $this;
}
}