__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace DI\Definition\Source;
use DI\Definition\Definition;
use DI\Definition\ExtendsPreviousDefinition;
/**
* Manages a chain of other definition sources.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class SourceChain implements DefinitionSource, MutableDefinitionSource
{
private ?MutableDefinitionSource $mutableSource;
/**
* @param list<DefinitionSource> $sources
*/
public function __construct(
private array $sources,
) {
}
/**
* @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) : Definition|null
{
$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
{
$allDefinitions = array_merge(...array_map(fn ($source) => $source->getDefinitions(), $this->sources));
/** @var string[] $allNames */
$allNames = array_keys($allDefinitions);
$allValues = array_filter(array_map(fn ($name) => $this->getDefinition($name), $allNames));
return array_combine($allNames, $allValues);
}
public function addDefinition(Definition $definition) : void
{
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) : void
{
$this->mutableSource = $mutableSource;
array_unshift($this->sources, $mutableSource);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| AttributeBasedAutowiring.php | File | 8.6 KB | 0777 |
|
| Autowiring.php | File | 522 B | 0777 |
|
| DefinitionArray.php | File | 3.39 KB | 0777 |
|
| DefinitionFile.php | File | 1.32 KB | 0777 |
|
| DefinitionNormalizer.php | File | 3.66 KB | 0777 |
|
| DefinitionSource.php | File | 637 B | 0777 |
|
| MutableDefinitionSource.php | File | 356 B | 0777 |
|
| NoAutowiring.php | File | 582 B | 0777 |
|
| ReflectionBasedAutowiring.php | File | 2.37 KB | 0777 |
|
| SourceCache.php | File | 2.38 KB | 0777 |
|
| SourceChain.php | File | 2.64 KB | 0777 |
|