/** * Builds code which injects an object which was specified by its object name * * @param Configuration $objectConfiguration Configuration of the object to inject into * @param ConfigurationProperty $propertyConfiguration * @param string $propertyName Name of the property to inject * @param string $propertyObjectName Object name of the object to inject * @return array PHP code * @throws \TYPO3\Flow\Object\Exception\UnknownObjectException */ 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 \TYPO3\Flow\Object\Exception\UnknownObjectException('Malformed DocComent block for a property in class "' . $className . '".', 1360171313); } if ($propertyObjectName[0] === '\\') { throw new \TYPO3\Flow\Object\Exception\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 \TYPO3\Flow\Object\Exception\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 = '\\TYPO3\\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 array('$this->' . $propertyName . ' = ' . $preparedSetterArgument . ';'); } }