コード例 #1
0
 /**
  * Reconstitutes an object from a serialized object without calling the constructor.
  *
  * @param array $objectData The object data array
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 protected function reconstituteObject(array $objectData)
 {
     $object = $this->createEmptyObject($objectData['className']);
     foreach ($objectData['properties'] as $propertyName => $propertyData) {
         switch ($propertyData['type']) {
             case 'simple':
                 $propertyValue = $propertyData['value'];
                 break;
             case 'array':
                 $propertyValue = $this->reconstituteArray($propertyData['value']);
                 break;
             case 'ArrayObject':
                 $propertyValue = new \ArrayObject($this->reconstituteArray($propertyData['value']));
                 break;
             case 'object':
                 $propertyValue = $this->reconstituteObject($this->objectsAsArray[$propertyData['value']]);
                 break;
             case 'SplObjectStorage':
                 $propertyValue = $this->reconstituteSplObjectStorage($propertyData['value']);
                 break;
             case 'persistenceObject':
                 $propertyValue = $this->reconstitutePersistenceObject($propertyData['value']['className'], $propertyData['value']['UUID']);
                 break;
         }
         $reflectionProperty = new \ReflectionProperty(get_class($object), $propertyName);
         $reflectionProperty->setAccessible(TRUE);
         $reflectionProperty->setValue($object, $propertyValue);
     }
     $objectName = $this->objectManager->getObjectNameByClassName($objectData['className']);
     $objectConfigruation = $this->objectManager->getObjectConfiguration($objectName);
     $this->objectBuilder->reinjectDependencies($object, $objectConfigruation);
     $this->objectManager->registerShutdownObject($object, $objectConfigruation->getLifecycleShutdownMethodName());
     return $object;
 }
コード例 #2
0
 /**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function shutdownCallsTheShutdownMethodsOfAllObjectsInTheSingletonObjectsRegistry()
 {
     $className = 'SomeClass' . uniqid();
     $mockObject1 = $this->getMock($className, array('shutdownObject'));
     $mockObject1->expects($this->once())->method('shutdownObject');
     $mockObject2 = $this->getMock($className, array('prepareForSelfDestruction'));
     $mockObject2->expects($this->once())->method('prepareForSelfDestruction');
     $shutdownObjects = array(spl_object_hash($mockObject1) => array($mockObject1, 'shutdownObject'), spl_object_hash($mockObject2) => array($mockObject2, 'prepareForSelfDestruction'));
     $objectManager = new \F3\FLOW3\Object\ObjectManager();
     $objectManager->injectObjectBuilder($this->getMock('F3\\FLOW3\\Object\\ObjectBuilder'));
     $objectManager->injectObjectFactory($this->getMock('F3\\FLOW3\\Object\\ObjectFactoryInterface'));
     $objectManager->injectSingletonObjectsRegistry($this->getMock('F3\\FLOW3\\Object\\TransientRegistry'));
     $objectManager->injectReflectionService($this->getMock('F3\\FLOW3\\Reflection\\ReflectionService'));
     $shutdownObjectsReflection = new \ReflectionProperty($objectManager, 'shutdownObjects');
     $shutdownObjectsReflection->setAccessible(TRUE);
     $shutdownObjectsReflection->setValue($objectManager, $shutdownObjects);
     $objectManager->shutdown();
 }