Neos\Flow\ObjectManagement\DependencyInjection\ProxyClassBuilder::buildPropertyInjectionCodeByString PHP Method

buildPropertyInjectionCodeByString() public method

Builds code which injects an object which was specified by its object name
public buildPropertyInjectionCodeByString ( Configuration $objectConfiguration, Neos\Flow\ObjectManagement\Configuration\ConfigurationProperty $propertyConfiguration, string $propertyName, string $propertyObjectName ) : array
$objectConfiguration Neos\Flow\ObjectManagement\Configuration\Configuration Configuration of the object to inject into
$propertyConfiguration Neos\Flow\ObjectManagement\Configuration\ConfigurationProperty
$propertyName string Name of the property to inject
$propertyObjectName string Object name of the object to inject
return array PHP code
    public function buildPropertyInjectionCodeByString(Configuration $objectConfiguration, ConfigurationProperty $propertyConfiguration, $propertyName, $propertyObjectName)
    {
        $className = $objectConfiguration->getClassName();
        if (strpos($propertyObjectName, '.') !== false) {
            $settingPath = explode('.', $propertyObjectName);
            $settings = Arrays::getValueByPath($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS), array_shift($settingPath));
            $propertyObjectName = Arrays::getValueByPath($settings, $settingPath);
        }
        if (!isset($this->objectConfigurations[$propertyObjectName])) {
            $configurationSource = $objectConfiguration->getConfigurationSourceHint();
            if (!isset($propertyObjectName[0])) {
                throw new ObjectException\UnknownObjectException('Malformed DocComent block for a property in class "' . $className . '".', 1360171313);
            }
            if ($propertyObjectName[0] === '\\') {
                throw new ObjectException\UnknownObjectException('The object name "' . $propertyObjectName . '" which was specified as a property in the object configuration of object "' . $objectConfiguration->getObjectName() . '" (' . $configurationSource . ') starts with a leading backslash.', 1277827579);
            } else {
                throw new ObjectException\UnknownObjectException('The object "' . $propertyObjectName . '" which was specified as a property in the object configuration of object "' . $objectConfiguration->getObjectName() . '" (' . $configurationSource . ') does not exist. Check for spelling mistakes and if that dependency is correctly configured.', 1265213849);
            }
        }
        $propertyClassName = $this->objectConfigurations[$propertyObjectName]->getClassName();
        if ($this->objectConfigurations[$propertyObjectName]->getScope() === Configuration::SCOPE_PROTOTYPE && !$this->objectConfigurations[$propertyObjectName]->isCreatedByFactory()) {
            $preparedSetterArgument = 'new \\' . $propertyClassName . '(' . $this->buildMethodParametersCode($this->objectConfigurations[$propertyObjectName]->getArguments()) . ')';
        } else {
            $preparedSetterArgument = '\\Neos\\Flow\\Core\\Bootstrap::$staticObjectManager->get(\'' . $propertyObjectName . '\')';
        }
        $result = $this->buildSetterInjectionCode($className, $propertyName, $preparedSetterArgument);
        if ($result !== null) {
            return $result;
        }
        if ($propertyConfiguration->isLazyLoading() && $this->objectConfigurations[$propertyObjectName]->getScope() !== Configuration::SCOPE_PROTOTYPE) {
            return $this->buildLazyPropertyInjectionCode($propertyObjectName, $propertyClassName, $propertyName, $preparedSetterArgument);
        } else {
            return ['    $this->' . $propertyName . ' = ' . $preparedSetterArgument . ';'];
        }
    }