/** * Maps a single record into the object it represents and registers it as * reconstituted with the session. * * @param array $objectData * @return object * @author Karsten Dambekalns <*****@*****.**> */ public function mapToObject(array $objectData) { if ($this->persistenceSession->hasIdentifier($objectData['identifier'])) { return $this->persistenceSession->getObjectByIdentifier($objectData['identifier']); } else { $className = $objectData['classname']; $classSchema = $this->reflectionService->getClassSchema($className); $objectConfiguration = $this->objectManager->getObjectConfiguration($className); $object = $this->objectBuilder->createEmptyObject($className, $objectConfiguration); $this->persistenceSession->registerObject($object, $objectData['identifier']); $this->objectBuilder->reinjectDependencies($object, $objectConfiguration); $this->thawProperties($object, $objectData['identifier'], $objectData, $classSchema); $object->FLOW3_Persistence_memorizeCleanState(); $this->persistenceSession->registerReconstitutedObject($object); return $object; } }
/** * Creates a fresh instance of the object specified by $objectName. * * This factory method can only create objects of the scope prototype. * Singleton objects must be either injected by some type of Dependency Injection or * if that is not possible, be retrieved by the getObject() method of the * Object Manager * * You must use either Dependency Injection or this factory method for instantiation * of your objects if you need FLOW3's object management capabilities (including * AOP, Security and Persistence). It is absolutely okay and often advisable to * use the "new" operator for instantiation in your automated tests. * * @param string $objectName The name of the object to create * @return object The new object instance * @throws \InvalidArgumentException if the object name starts with a backslash * @throws \F3\FLOW3\Object\Exception\UnknownObjectException if an object with the given name does not exist * @throws \F3\FLOW3\Object\Exception\WrongScopeException if the specified object is not configured as Prototype * @author Robert Lemke <*****@*****.**> * @api */ public function create($objectName) { if ($objectName[0] === '\\') { throw new \InvalidArgumentException('The object name must not start with a backslash, "' . $objectName . '" given.', 1243272770); } if (!$this->objectManager->isObjectRegistered($objectName)) { throw new \F3\FLOW3\Object\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1166550023); } $objectConfiguration = $this->objectManager->getObjectConfiguration($objectName); if ($objectConfiguration->getScope() != 'prototype') { throw new \F3\FLOW3\Object\Exception\WrongScopeException('Object "' . $objectName . '" is of scope ' . $objectConfiguration->getScope() . ' but only prototype is supported by create()', 1225385285); } $overridingArguments = self::convertArgumentValuesToArgumentObjects(array_slice(func_get_args(), 1)); $object = $this->objectBuilder->createObject($objectName, $objectConfiguration, $overridingArguments); $this->objectManager->registerShutdownObject($object, $objectConfiguration->getLifecycleShutdownMethodName()); return $object; }