Example #1
0
 /**
  * Traverses through the given class and interface names and builds a base object configuration
  * for all of them. Then parses the provided extra configuration and merges the result
  * into the overall configuration. Finally autowires dependencies of arguments and properties
  * which can be resolved automatically.
  *
  * @param array $availableClassNamesByPackage An array of available class names, grouped by package key
  * @param array $rawObjectConfigurationsByPackages An array of package keys and their raw (ie. unparsed) object configurations
  * @return array<TYPO3\FLOW3\Object\Configuration\Configuration> Object configurations
  * @throws \TYPO3\FLOW3\Object\Exception\InvalidObjectConfigurationException
  */
 public function buildObjectConfigurations(array $availableClassNamesByPackage, array $rawObjectConfigurationsByPackages)
 {
     $objectConfigurations = array();
     foreach ($availableClassNamesByPackage as $packageKey => $classNames) {
         foreach ($classNames as $className) {
             $objectName = $className;
             if ($this->reflectionService->isClassFinal($className)) {
                 continue;
             }
             if (interface_exists($className)) {
                 $interfaceName = $className;
                 $className = $this->reflectionService->getDefaultImplementationClassNameForInterface($interfaceName);
                 if ($className === FALSE) {
                     continue;
                 }
                 if ($this->reflectionService->isClassAnnotatedWith($interfaceName, 'TYPO3\\FLOW3\\Annotations\\Scope')) {
                     throw new \TYPO3\FLOW3\Object\Exception\InvalidObjectConfigurationException(sprintf('Scope annotations in interfaces don\'t have any effect, therefore you better remove it from %s in order to avoid confusion.', $interfaceName), 1299095595);
                 }
             }
             $rawObjectConfiguration = array('className' => $className);
             $rawObjectConfiguration = $this->enhanceRawConfigurationWithAnnotationOptions($className, $rawObjectConfiguration);
             $objectConfigurations[$objectName] = $this->parseConfigurationArray($objectName, $rawObjectConfiguration, 'automatically registered class');
             $objectConfigurations[$objectName]->setPackageKey($packageKey);
         }
     }
     foreach ($rawObjectConfigurationsByPackages as $packageKey => $rawObjectConfigurations) {
         foreach ($rawObjectConfigurations as $objectName => $rawObjectConfiguration) {
             $objectName = str_replace('_', '\\', $objectName);
             if (!is_array($rawObjectConfiguration)) {
                 throw new \TYPO3\FLOW3\Object\Exception\InvalidObjectConfigurationException('Configuration of object "' . $objectName . '" in package "' . $packageKey . '" is not an array, please check your Objects.yaml for syntax errors.', 1295954338);
             }
             $existingObjectConfiguration = isset($objectConfigurations[$objectName]) ? $objectConfigurations[$objectName] : NULL;
             if (isset($rawObjectConfiguration['className'])) {
                 $rawObjectConfiguration = $this->enhanceRawConfigurationWithAnnotationOptions($rawObjectConfiguration['className'], $rawObjectConfiguration);
             }
             $newObjectConfiguration = $this->parseConfigurationArray($objectName, $rawObjectConfiguration, 'configuration of package ' . $packageKey . ', definition for object "' . $objectName . '"', $existingObjectConfiguration);
             if (!isset($objectConfigurations[$objectName]) && !interface_exists($objectName, TRUE) && !class_exists($objectName, FALSE)) {
                 throw new \TYPO3\FLOW3\Object\Exception\InvalidObjectConfigurationException('Tried to configure unknown object "' . $objectName . '" in package "' . $packageKey . '". Please check your Objects.yaml.', 1184926175);
             }
             if ($objectName !== $newObjectConfiguration->getClassName() && !interface_exists($objectName, TRUE)) {
                 throw new \TYPO3\FLOW3\Object\Exception\InvalidObjectConfigurationException('Tried to set a differing class name for class "' . $objectName . '" in the object configuration of package "' . $packageKey . '". Setting "className" is only allowed for interfaces, please check your Objects.yaml."', 1295954589);
             }
             $objectConfigurations[$objectName] = $newObjectConfiguration;
             if ($objectConfigurations[$objectName]->getPackageKey() === NULL) {
                 $objectConfigurations[$objectName]->setPackageKey($packageKey);
             }
         }
     }
     $this->autowireArguments($objectConfigurations);
     $this->autowireProperties($objectConfigurations);
     return $objectConfigurations;
 }