*/ class SourceChain implements DefinitionSource, MutableDefinitionSource { /** @var DefinitionSource[] */ private $sources; /** @var DefinitionSource */ private $rootSource; /** @var MutableDefinitionSource|null */ private $mutableSource; /** * @param DefinitionSource[] $sources */ public function __construct(array $sources) { // We want a numerically indexed array to ease the traversal later $this->sources = array_values($sources); $this->rootSource = $this; } /** * {@inheritdoc} * * @param int $startIndex Use this parameter to start looking from a specific * point in the source chain. */ public function getDefinition(string $name, int $startIndex = 0) { $count = count($this->sources); for ($i = $startIndex; $i < $count; ++$i) { $source = $this->sources[$i]; $definition = $source->getDefinition($name); if ($definition) { if ($definition instanceof ExtendsPreviousDefinition) { $this->resolveExtendedDefinition($definition, $i); } return $definition; } } return null; } public function getDefinitions(): array { $names = []; foreach ($this->sources as $source) { $names = array_merge($names, $source->getDefinitions()); } $names = array_keys($names); $definitions = array_combine($names, array_map(function (string $name) { return $this->getDefinition($name); }, $names)); return $definitions; } public function addDefinition(Definition $definition) { if (! $this->mutableSource) { throw new \LogicException("The container's definition source has not been initialized correctly"); } $this->mutableSource->addDefinition($definition); } private function resolveExtendedDefinition(ExtendsPreviousDefinition $definition, int $currentIndex) { // Look in the next sources only (else infinite recursion, and we can only extend // entries defined in the previous definition files - a previous == next here because // the array was reversed ;) ) $subDefinition = $this->getDefinition($definition->getName(), $currentIndex + 1); if ($subDefinition) { $definition->setExtendedDefinition($subDefinition); } } public function setMutableDefinitionSource(MutableDefinitionSource $mutableSource) { $this->mutableSource = $mutableSource; array_unshift($this->sources, $mutableSource); } } __halt_compiler();----SIGNATURE:----wKy7cnUhAaeCQDT0tpoCHkDhWRqdxShQdeQbo9L6bsNRGhwjtoglvtWjpgFQ7tDM7EAwFSRbJlwijClf2T2RulAEglzMtfwJ7M3ZQnWCON3T6WenLRJifgTFcv+rJ5MdnrlssN8sC6ViBB2qoiuPy+n5/YgTkrmDg8wyPoEbikwu6h5HoX+F64vhTr8FfZvAS0rvhRy+0arcCqqiTevb0FI5DDbnx8SxjoMBUSpBkWtRw6euVlELWxtRBrW24R8L9RjhNKbNomwIYvyf6uUF+Nnn+caY6lKSzdjrOjIUvnDC+aHogFrNjj74fLdgqJKhWDP4hAOy7LgsjjgK1RQp19LFWXtc40C4g2mBY8l0nlL2YvHVq0KIPsfHwcMDZV8Wzke/PHoEBfjwWwt2NHSM6HqVYvHCTuobEOXCfy09A/rMvfIumlAUj4JuFbKU8PjwtDtCQgh44m6tIMqEulaj07PDtciTV90bki4HPb9oi9IQyF25LEWKGnkMSkRtGkTME3rKXaGuv2h7w9J+XZwxSARPAaIXt1WJINUF3GVSHY72Vy30AorqZnLmV8Co8bWoB0i8zD6urw5q785ALd3nGj7WjBEBIjQ3bOym/ae0xEPsyTFgKhoLtz3gVLUnbJX6KnGirAHa4E+zg4BpSwcZU0I+RPVP3MOdRPWM42rOepM=----ATTACHMENT:----NjA4NTE2NTA5OTI5NDg2MyAzMjY4OTMxNjIzOTk4MDk5IDg3NDU1MTE1OTM1NDQ5NjQ=