PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / league / container / src / ServiceProvider / ServiceProviderAggregate.php

ServiceProviderAggregate.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/league/container/src/ServiceProvider/ServiceProviderAggregate.php

77 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Imagify\Dependencies\League\Container\ServiceProvider;
6
7 use Generator;
8 use Imagify\Dependencies\League\Container\Exception\ContainerException;
9 use Imagify\Dependencies\League\Container\{ContainerAwareInterface, ContainerAwareTrait};
10
11 class ServiceProviderAggregate implements ServiceProviderAggregateInterface
12 {
13 use ContainerAwareTrait;
14
15 /**
16 * @var ServiceProviderInterface[]
17 */
18 protected $providers = [];
19
20 /**
21 * @var array
22 */
23 protected $registered = [];
24
25 public function add(ServiceProviderInterface $provider): ServiceProviderAggregateInterface
26 {
27 if (in_array($provider, $this->providers, true)) {
28 return $this;
29 }
30
31 $provider->setContainer($this->getContainer());
32
33 if ($provider instanceof BootableServiceProviderInterface) {
34 $provider->boot();
35 }
36
37 $this->providers[] = $provider;
38 return $this;
39 }
40
41 public function provides(string $service): bool
42 {
43 foreach ($this->getIterator() as $provider) {
44 if ($provider->provides($service)) {
45 return true;
46 }
47 }
48
49 return false;
50 }
51
52 public function getIterator(): Generator
53 {
54 yield from $this->providers;
55 }
56
57 public function register(string $service): void
58 {
59 if (false === $this->provides($service)) {
60 throw new ContainerException(
61 sprintf('(%s) is not provided by a service provider', $service)
62 );
63 }
64
65 foreach ($this->getIterator() as $provider) {
66 if (in_array($provider->getIdentifier(), $this->registered, true)) {
67 continue;
68 }
69
70 if ($provider->provides($service)) {
71 $provider->register();
72 $this->registered[] = $provider->getIdentifier();
73 }
74 }
75 }
76 }
77