DigiComp.FlowSymfonyBridge..../Classes/ObjectManagement/ChainedContainer.php

36 lines
886 B
PHP
Raw Normal View History

<?php
namespace DigiComp\FlowSymfonyBridge\Messenger\ObjectManagement;
use Psr\Container\ContainerInterface;
class ChainedContainer implements ContainerInterface
{
private array $childContainers;
public function __construct(ContainerInterface ...$childContainers)
{
$this->childContainers = $childContainers;
}
public function get(string $id)
{
foreach ($this->childContainers as $childContainer) {
if ($childContainer->has($id)) {
return $childContainer->get($id);
}
}
throw new \InvalidArgumentException('Service id is unknown: ' . $id);
}
2023-02-18 22:53:05 +01:00
public function has(string $id): bool
{
foreach ($this->childContainers as $childContainer) {
if ($childContainer->has($id)) {
return true;
}
}
return false;
}
}