
| Current Path : /var/www/html/vendor/league/container/src/ServiceProvider/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/league/container/src/ServiceProvider/ServiceProviderAggregate.php |
<?php
declare(strict_types=1);
namespace League\Container\ServiceProvider;
use Generator;
use League\Container\Exception\ContainerException;
use League\Container\{ContainerAwareInterface, ContainerAwareTrait};
class ServiceProviderAggregate implements ServiceProviderAggregateInterface
{
use ContainerAwareTrait;
/**
* @var ServiceProviderInterface[]
*/
protected $providers = [];
/**
* @var array
*/
protected $registered = [];
public function add(ServiceProviderInterface $provider): ServiceProviderAggregateInterface
{
if (in_array($provider, $this->providers, true)) {
return $this;
}
if ($provider instanceof ContainerAwareInterface) {
$provider->setContainer($this->getContainer());
}
if ($provider instanceof BootableServiceProviderInterface) {
$provider->boot();
}
$this->providers[] = $provider;
return $this;
}
public function provides(string $service): bool
{
foreach ($this->getIterator() as $provider) {
if ($provider->provides($service)) {
return true;
}
}
return false;
}
public function getIterator(): Generator
{
yield from $this->providers;
}
public function register(string $service): void
{
if (false === $this->provides($service)) {
throw new ContainerException(
sprintf('(%s) is not provided by a service provider', $service)
);
}
foreach ($this->getIterator() as $provider) {
if (in_array($provider->getIdentifier(), $this->registered, true)) {
continue;
}
if ($provider->provides($service)) {
$provider->register();
$this->registered[] = $provider->getIdentifier();
}
}
}
}