/** * Creates and returns a ready-to-use object of the specified type. * During the building process all depencencies are resolved and injected. * * @param string $objectName Name of the object to create an object for * @param \F3\FLOW3\Object\Configuration\Configuration $objectConfiguration The object configuration * @param array $overridingArguments An array of \F3\FLOW3\Object\Argument which override possible autowired arguments. Numbering starts with 1! Index == 1 is the first argument, index == 2 to the second etc. * @return object * @throws \F3\FLOW3\Object\Exception\CannotBuildObjectException * @author Robert Lemke <*****@*****.**> */ public function createObject($objectName, \F3\FLOW3\Object\Configuration\Configuration $objectConfiguration, array $overridingArguments = array()) { if (isset($this->objectsBeingBuilt[$objectName])) { throw new \F3\FLOW3\Object\Exception\CannotBuildObjectException('Circular object dependency for object "' . $objectName . '".', 1168505928); } try { $this->objectsBeingBuilt[$objectName] = TRUE; $className = $objectConfiguration->getClassName(); $customFactoryClassName = $objectConfiguration->getFactoryClassName(); if (interface_exists($className) === TRUE) { throw new \F3\FLOW3\Object\Exception\InvalidClassException('No default implementation for the object type "' . $objectName . '" found in the object configuration. Cannot instantiate interface ' . $className . '.', 1238761260); } if (class_exists($className) === FALSE && $customFactoryClassName === NULL) { throw new \F3\FLOW3\Object\Exception\UnknownClassException('Class "' . $className . '" which was specified in the object configuration of object "' . $objectName . '" does not exist.', 1229967561); } $arguments = $objectConfiguration->getArguments(); foreach ($overridingArguments as $index => $value) { $arguments[$index] = $value; } $setterProperties = $objectConfiguration->getProperties(); if ($objectConfiguration->getAutowiring() === \F3\FLOW3\Object\Configuration\Configuration::AUTOWIRING_MODE_ON && $className !== NULL) { $arguments = $this->autowireArguments($arguments, $className); $setterProperties = $this->autowireProperties($setterProperties, $className); } $preparedArguments = array(); $this->injectArguments($arguments, $preparedArguments); if ($customFactoryClassName !== NULL) { $customFactory = $this->objectManager->getObject($customFactoryClassName); $object = call_user_func_array(array($customFactory, $objectConfiguration->getFactoryMethodName()), $preparedArguments); if (!is_object($object)) { throw new \F3\FLOW3\Object\Exception\CannotBuildObjectException('Custom factory "' . $customFactoryClassName . '->' . $objectConfiguration->getFactoryMethodName() . '()" did not return an object while building object "' . $objectName . '" (Configuration source: ' . $objectConfiguration->getConfigurationSourceHint() . ')', 1257766990); } } else { $object = $this->instantiateClass($className, $preparedArguments); if (!is_object($object)) { throw new \F3\FLOW3\Object\Exception\CannotBuildObjectException('Could not instantiate class ' . $className . ' while building object "' . $objectName . '"', 1187164523); } } if ($object instanceof \F3\FLOW3\AOP\ProxyInterface) { $object->FLOW3_AOP_Proxy_setProperty('objectManager', $this->objectManager); $object->FLOW3_AOP_Proxy_setProperty('objectFactory', $this->objectFactory); $object->FLOW3_AOP_Proxy_construct(); } $this->injectProperties($setterProperties, $object); $this->callLifecycleInitializationMethod($object, $objectConfiguration); } catch (\Exception $exception) { unset($this->objectsBeingBuilt[$objectName]); throw $exception; } unset($this->objectsBeingBuilt[$objectName]); return $object; }