/** * @test * @author Robert Lemke <*****@*****.**> */ public function createRegistersShutdownObjectsAtTheComponentManager() { $className = 'SomeClass' . uniqid(); eval('class ' . $className . ' {}'); $object = new $className(); $objectName = 'F3\\Virtual\\BasicClass'; $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration($objectName); $objectConfiguration->setScope('prototype'); $this->mockObjectManager->expects($this->once())->method('isObjectRegistered')->with($objectName)->will($this->returnValue(TRUE)); $this->mockObjectManager->expects($this->once())->method('getObjectConfiguration')->with($objectName)->will($this->returnValue($objectConfiguration)); $this->mockObjectManager->expects($this->once())->method('registerShutdownObject')->with($object, 'shutdownObject'); $this->mockObjectBuilder->expects($this->once())->method('createObject')->will($this->returnValue($object)); $this->objectFactory->create($objectName); }
/** * 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; } }
/** * Returns a fresh or existing instance of the object specified by $objectName. * * Important: * * If possible, instances of Prototype objects should always be created with the * Object Factory's create() method and Singleton objects should rather be * injected by some type of Dependency Injection. * * @param string $objectName The name of the object to return an instance of * @return object The object instance * @author Robert Lemke <*****@*****.**> * @throws \F3\FLOW3\Object\Exception\UnknownObjectException if an object with the given name does not exist * @api */ public function getObject($objectName) { if (!$this->isObjectRegistered($objectName)) { throw new \F3\FLOW3\Object\Exception\UnknownObjectException('Object "' . $objectName . '" is not registered.', 1166550023); } switch ($this->objectConfigurations[$objectName]->getScope()) { case 'prototype': $object = call_user_func_array(array($this->objectFactory, 'create'), func_get_args()); break; case 'singleton': if ($this->singletonObjectsRegistry->objectExists($objectName)) { $object = $this->singletonObjectsRegistry->getObject($objectName); } else { $arguments = array_slice(func_get_args(), 1); $overridingArguments = $this->getOverridingArguments($arguments); $object = $this->objectBuilder->createObject($objectName, $this->objectConfigurations[$objectName], $overridingArguments); $this->singletonObjectsRegistry->putObject($objectName, $object); $this->registerShutdownObject($object, $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName()); } break; case 'session': if ($this->sessionObjectsRegistry === NULL) { throw new \F3\FLOW3\Object\Exception('The session objects registry has not been injected correctly into the object manager.', 1247211113); } if ($this->sessionObjectsRegistry->objectExists($objectName)) { $object = $this->sessionObjectsRegistry->getObject($objectName); } else { $arguments = array_slice(func_get_args(), 1); $overridingArguments = $this->getOverridingArguments($arguments); $object = $this->objectBuilder->createObject($objectName, $this->objectConfigurations[$objectName], $overridingArguments); $this->sessionObjectsRegistry->putObject($objectName, $object); $this->registerShutdownObject($object, $this->objectConfigurations[$objectName]->getLifecycleShutdownMethodName()); } break; } return $object; }
/** * @test * @author Robert Lemke <*****@*****.**> */ public function createEmptyObjectPreventsThatTheConstructorOfTheTargetObjectIsCalled() { $objectConfiguration = new \F3\FLOW3\Object\Configuration\Configuration('F3\\FLOW3\\Tests\\Object\\Fixture\\ReconstitutableClassWithSimpleProperties'); $object = $this->objectBuilder->createEmptyObject('F3\\FLOW3\\Tests\\Object\\Fixture\\ReconstitutableClassWithSimpleProperties', $objectConfiguration); $this->assertFalse($object->constructorHasBeenCalled); }