Neos\Flow\ObjectManagement\Configuration\ConfigurationBuilder::autowireArguments PHP Method

autowireArguments() protected method

If mandatory constructor arguments have not been defined yet, this function tries to autowire them if possible.
protected autowireArguments ( array &$objectConfigurations ) : void
$objectConfigurations array
return void
    protected function autowireArguments(array &$objectConfigurations)
    {
        foreach ($objectConfigurations as $objectConfiguration) {
            /** @var Configuration $objectConfiguration */
            if ($objectConfiguration->getClassName() === '') {
                continue;
            }
            $className = $objectConfiguration->getClassName();
            if (!$this->reflectionService->hasMethod($className, '__construct')) {
                continue;
            }
            $arguments = $objectConfiguration->getArguments();
            $autowiringAnnotation = $this->reflectionService->getMethodAnnotation($className, '__construct', Flow\Autowiring::class);
            foreach ($this->reflectionService->getMethodParameters($className, '__construct') as $parameterName => $parameterInformation) {
                $debuggingHint = '';
                $index = $parameterInformation['position'] + 1;
                if (!isset($arguments[$index])) {
                    if ($parameterInformation['optional'] === true) {
                        $defaultValue = isset($parameterInformation['defaultValue']) ? $parameterInformation['defaultValue'] : null;
                        $arguments[$index] = new ConfigurationArgument($index, $defaultValue, ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE);
                        $arguments[$index]->setAutowiring(Configuration::AUTOWIRING_MODE_OFF);
                    } elseif ($parameterInformation['class'] !== null && isset($objectConfigurations[$parameterInformation['class']])) {
                        $arguments[$index] = new ConfigurationArgument($index, $parameterInformation['class'], ConfigurationArgument::ARGUMENT_TYPES_OBJECT);
                    } elseif ($parameterInformation['allowsNull'] === true) {
                        $arguments[$index] = new ConfigurationArgument($index, null, ConfigurationArgument::ARGUMENT_TYPES_STRAIGHTVALUE);
                        $arguments[$index]->setAutowiring(Configuration::AUTOWIRING_MODE_OFF);
                    } elseif (interface_exists($parameterInformation['class'])) {
                        $debuggingHint = sprintf('No default implementation for the required interface %s was configured, therefore no specific class name could be used for this dependency. ', $parameterInformation['class']);
                    }
                    if (isset($arguments[$index]) && ($objectConfiguration->getAutowiring() === Configuration::AUTOWIRING_MODE_OFF || $autowiringAnnotation !== null && $autowiringAnnotation->enabled === false)) {
                        $arguments[$index]->setAutowiring(Configuration::AUTOWIRING_MODE_OFF);
                        $arguments[$index]->set($index, null);
                    }
                }
                if (!isset($arguments[$index]) && $objectConfiguration->getScope() === Configuration::SCOPE_SINGLETON) {
                    throw new UnresolvedDependenciesException(sprintf('Could not autowire required constructor argument $%s for singleton class %s. %sCheck the type hint of that argument and your Objects.yaml configuration.', $parameterName, $className, $debuggingHint), 1298629392);
                }
            }
            $objectConfiguration->setArguments($arguments);
        }
    }