Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / league / container / src / ServiceProvider / ServiceProviderAggregate.php
1 <?php
2
3 namespace League\Container\ServiceProvider;
4
5 use League\Container\ContainerAwareInterface;
6 use League\Container\ContainerAwareTrait;
7
8 class ServiceProviderAggregate implements ServiceProviderAggregateInterface
9 {
10     use ContainerAwareTrait;
11
12     /**
13      * @var array
14      */
15     protected $providers = [];
16
17     /**
18      * @var array
19      */
20     protected $registered = [];
21
22     /**
23      * {@inheritdoc}
24      */
25     public function add($provider)
26     {
27         if (is_string($provider) && class_exists($provider)) {
28             $provider = new $provider;
29         }
30
31         if ($provider instanceof ContainerAwareInterface) {
32             $provider->setContainer($this->getContainer());
33         }
34
35         if ($provider instanceof BootableServiceProviderInterface) {
36             $provider->boot();
37         }
38
39         if ($provider instanceof ServiceProviderInterface) {
40             foreach ($provider->provides() as $service) {
41                 $this->providers[$service] = $provider;
42             }
43
44             return $this;
45         }
46
47         throw new \InvalidArgumentException(
48             'A service provider must be a fully qualified class name or instance ' .
49             'of (\League\Container\ServiceProvider\ServiceProviderInterface)'
50         );
51     }
52
53     /**
54      * {@inheritdoc}
55      */
56     public function provides($service)
57     {
58         return array_key_exists($service, $this->providers);
59     }
60
61     /**
62      * {@inheritdoc}
63      */
64     public function register($service)
65     {
66         if (! array_key_exists($service, $this->providers)) {
67             throw new \InvalidArgumentException(
68                 sprintf('(%s) is not provided by a service provider', $service)
69             );
70         }
71
72         $provider  = $this->providers[$service];
73         $signature = get_class($provider);
74
75         if ($provider instanceof SignatureServiceProviderInterface) {
76             $signature = $provider->getSignature();
77         }
78
79         // ensure that the provider hasn't already been invoked by any other service request
80         if (in_array($signature, $this->registered)) {
81             return;
82         }
83
84         $provider->register();
85
86         $this->registered[] = $signature;
87     }
88 }