function AutowirePass::autowireCalls
1 call to AutowirePass::autowireCalls()
- AutowirePass::doProcessValue in vendor/
symfony/ dependency-injection/ Compiler/ AutowirePass.php
File
-
vendor/
symfony/ dependency-injection/ Compiler/ AutowirePass.php, line 181
Class
- AutowirePass
- Inspects existing service definitions and wires the autowired ones using the type hints of their classes.
Namespace
Symfony\Component\DependencyInjection\CompilerCode
private function autowireCalls(array $methodCalls, \ReflectionClass $reflectionClass, bool $isRoot, bool $checkAttributes) : array {
if ($isRoot) {
$this->decoratedId = null;
$this->decoratedClass = null;
$this->restorePreviousValue = null;
if (($definition = $this->container
->getDefinition($this->currentId)) && null !== ($this->decoratedId = $definition->innerServiceId) && $this->container
->has($this->decoratedId)) {
$this->decoratedClass = $this->container
->findDefinition($this->decoratedId)
->getClass();
}
}
$patchedIndexes = [];
foreach ($methodCalls as $i => $call) {
[
$method,
$arguments,
] = $call;
if ($method instanceof \ReflectionFunctionAbstract) {
$reflectionMethod = $method;
}
else {
$definition = new Definition($reflectionClass->name);
try {
$reflectionMethod = $this->getReflectionMethod($definition, $method);
} catch (RuntimeException $e) {
if ($definition->getFactory()) {
continue;
}
throw $e;
}
}
$arguments = $this->autowireMethod($reflectionMethod, $arguments, $checkAttributes);
if ($arguments !== $call[1]) {
$methodCalls[$i][1] = $arguments;
$patchedIndexes[] = $i;
}
}
// use named arguments to skip complex default values
foreach ($patchedIndexes as $i) {
$namedArguments = null;
$arguments = $methodCalls[$i][1];
foreach ($arguments as $j => $value) {
if ($namedArguments && !$value instanceof $this->defaultArgument) {
unset($arguments[$j]);
$arguments[$namedArguments[$j]] = $value;
}
if (!$value instanceof $this->defaultArgument) {
continue;
}
if (\is_array($value->value) ? $value->value : \is_object($value->value)) {
unset($arguments[$j]);
$namedArguments = $value->names;
}
if ($namedArguments) {
unset($arguments[$j]);
}
else {
$arguments[$j] = $value->value;
}
}
$methodCalls[$i][1] = $arguments;
}
return $methodCalls;
}