/** * Returns a fresh or existing instance of the object specified by $objectName. * * This specialized get() method is able to do setter injection for properties * defined in the object configuration of the specified object. * * @param string $objectName The name of the object to return an instance of * @return object The object instance * @throws \Neos\Flow\ObjectManagement\Exception\CannotBuildObjectException * @throws \Neos\Flow\ObjectManagement\Exception\UnresolvedDependenciesException * @throws \Neos\Flow\ObjectManagement\Exception\UnknownObjectException */ public function get($objectName) { if (isset($this->objects[$objectName]['i'])) { return $this->objects[$objectName]['i']; } if (isset($this->objectConfigurations[$objectName]) && count($this->objectConfigurations[$objectName]->getArguments()) > 0) { throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because constructor injection is not available in the compile time Object Manager. Refactor your code to use setter injection instead. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '. Build stack: ' . implode(', ', $this->objectNameBuildStack), 1297090026); } if (!isset($this->objects[$objectName])) { throw new Exception\UnknownObjectException('Cannot build object "' . $objectName . '" because it is unknown to the compile time Object Manager.', 1301477694); } if ($this->objects[$objectName]['s'] !== Configuration::SCOPE_SINGLETON) { throw new Exception\CannotBuildObjectException('Cannot build object "' . $objectName . '" because the get() method in the compile time Object Manager only supports singletons.', 1297090027); } $this->objectNameBuildStack[] = $objectName; $object = parent::get($objectName); /** @var Configuration $objectConfiguration */ $objectConfiguration = $this->objectConfigurations[$objectName]; /** @var Property $property */ foreach ($objectConfiguration->getProperties() as $propertyName => $property) { if ($property->getAutowiring() !== Configuration::AUTOWIRING_MODE_ON) { continue; } switch ($property->getType()) { case Property::PROPERTY_TYPES_STRAIGHTVALUE: $value = $property->getValue(); break; case Property::PROPERTY_TYPES_CONFIGURATION: $propertyValue = $property->getValue(); $value = $this->configurationManager->getConfiguration($propertyValue['type'], $propertyValue['path']); break; case Property::PROPERTY_TYPES_OBJECT: $propertyObjectName = $property->getValue(); if (!is_string($propertyObjectName)) { throw new Exception\CannotBuildObjectException('The object definition of "' . $objectName . '::' . $propertyName . '" is too complex for the compile time Object Manager. You can only use plain object names, not factories and the like. Check configuration in ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . ' and objects which depend on ' . $objectName . '.', 1297099659); } $value = $this->get($propertyObjectName); break; default: throw new Exception\CannotBuildObjectException('Invalid property type.', 1297090029); } if (method_exists($object, $setterMethodName = 'inject' . ucfirst($propertyName))) { $object->{$setterMethodName}($value); } elseif (method_exists($object, $setterMethodName = 'set' . ucfirst($propertyName))) { $object->{$setterMethodName}($value); } else { throw new Exception\UnresolvedDependenciesException('Could not inject configured property "' . $propertyName . '" into "' . $objectName . '" because no injection method exists, but for compile time use this is required. Configuration source: ' . $this->objectConfigurations[$objectName]->getConfigurationSourceHint() . '.', 1297110953); } } $initializationLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleInitializationMethodName(); if (method_exists($object, $initializationLifecycleMethodName)) { $object->{$initializationLifecycleMethodName}(); } $shutdownLifecycleMethodName = $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName(); if (method_exists($object, $shutdownLifecycleMethodName)) { $this->shutdownObjects[$object] = $shutdownLifecycleMethodName; } array_pop($this->objectNameBuildStack); return $object; }