1 | <?php declare(strict_types=1); |
||
9 | class ServiceProviderAggregate implements ServiceProviderAggregateInterface |
||
10 | { |
||
11 | use ContainerAwareTrait; |
||
12 | |||
13 | /** |
||
14 | * @var \League\Container\ServiceProvider\ServiceProviderInterface[] |
||
15 | */ |
||
16 | protected $providers = []; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $registered = []; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | 21 | */ |
|
26 | public function add($provider): ServiceProviderAggregateInterface |
||
27 | 21 | { |
|
28 | 3 | if (is_string($provider) && $this->getContainer()->has($provider)) { |
|
29 | 3 | $provider = $this->getContainer()->get($provider); |
|
30 | } elseif (is_string($provider) && class_exists($provider)) { |
||
31 | 21 | $provider = new $provider; |
|
32 | 18 | } |
|
33 | 18 | ||
34 | if ($provider instanceof ContainerAwareInterface) { |
||
35 | 21 | $provider->setContainer($this->getContainer()); |
|
36 | 9 | } |
|
37 | 9 | ||
38 | if ($provider instanceof BootableServiceProviderInterface) { |
||
39 | 21 | $provider->boot(); |
|
40 | 18 | } |
|
41 | 18 | ||
42 | 18 | if ($provider instanceof ServiceProviderInterface) { |
|
43 | $this->providers[] = $provider; |
||
44 | 18 | ||
45 | return $this; |
||
46 | } |
||
47 | 3 | ||
48 | throw new ContainerException( |
||
49 | 'A service provider must be a fully qualified class name or instance ' . |
||
50 | 3 | 'of (\League\Container\ServiceProvider\ServiceProviderInterface)' |
|
51 | ); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | 33 | */ |
|
57 | public function provides(string $service): bool |
||
67 | 3 | ||
68 | 3 | /** |
|
69 | 3 | * {@inheritdoc} |
|
70 | */ |
||
71 | public function getIterator(): Generator |
||
79 | |||
80 | 15 | /** |
|
81 | 6 | * {@inheritdoc} |
|
82 | */ |
||
83 | public function register(string $service) |
||
101 | } |
||
102 |