DCOM-93 - Factor out __wakeup into a delegate-method from ClassMetadataFactory#wakeupReflection to ClassMetadataInfo#wakeupReflection
This commit is contained in:
parent
ea2d4e4282
commit
1cecc9c429
@ -327,32 +327,34 @@ class ClassMetadata extends ClassMetadataInfo implements IClassMetadata
|
||||
/**
|
||||
* Restores some state that can not be serialized/unserialized.
|
||||
*
|
||||
* @param ReflectionService $reflService
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
public function wakeupReflection($reflService)
|
||||
{
|
||||
// Restore ReflectionClass and properties
|
||||
$this->reflClass = new ReflectionClass($this->name);
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
|
||||
foreach ($this->fieldMappings as $field => $mapping) {
|
||||
$reflField = isset($mapping['declared'])
|
||||
? new ReflectionProperty($mapping['declared'], $field)
|
||||
: $this->reflClass->getProperty($field);
|
||||
|
||||
$reflField->setAccessible(true);
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($this->name, $field);
|
||||
$this->reflFields[$field] = $reflField;
|
||||
}
|
||||
|
||||
foreach ($this->associationMappings as $field => $mapping) {
|
||||
$reflField = isset($mapping['declared'])
|
||||
? new ReflectionProperty($mapping['declared'], $field)
|
||||
: $this->reflClass->getProperty($field);
|
||||
|
||||
$reflField->setAccessible(true);
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($this->name, $field);
|
||||
$this->reflFields[$field] = $reflField;
|
||||
}
|
||||
}
|
||||
|
||||
public function initializeReflection($reflService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the mapped class, without invoking the constructor.
|
||||
*
|
||||
|
@ -576,22 +576,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
||||
*/
|
||||
protected function wakeupReflection(ClassMetadataInfo $class, ReflectionService $reflService)
|
||||
{
|
||||
// Restore ReflectionClass and properties
|
||||
$class->reflClass = $reflService->getClass($class->name);
|
||||
|
||||
foreach ($class->fieldMappings as $field => $mapping) {
|
||||
$reflField = isset($mapping['declared'])
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($class->name, $field);
|
||||
$class->reflFields[$field] = $reflField;
|
||||
}
|
||||
|
||||
foreach ($class->associationMappings as $field => $mapping) {
|
||||
$reflField = isset($mapping['declared'])
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($class->name, $field);
|
||||
$class->reflFields[$field] = $reflField;
|
||||
}
|
||||
$class->wakeupReflection($reflService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -506,6 +506,36 @@ class ClassMetadataInfo
|
||||
$this->rootEntityName = $entityName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores some state that can not be serialized/unserialized.
|
||||
*
|
||||
* @param ReflectionService $reflService
|
||||
* @return void
|
||||
*/
|
||||
public function wakeupReflection($reflService)
|
||||
{
|
||||
// Restore ReflectionClass and properties
|
||||
$this->reflClass = $reflService->getClass($this->name);
|
||||
|
||||
foreach ($this->fieldMappings as $field => $mapping) {
|
||||
$this->reflFields[$field] = isset($mapping['declared'])
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($this->name, $field);
|
||||
}
|
||||
|
||||
foreach ($this->associationMappings as $field => $mapping) {
|
||||
$this->reflFields[$field] = isset($mapping['declared'])
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($this->name, $field);
|
||||
}
|
||||
}
|
||||
|
||||
public function initializeReflection($reflService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the ReflectionClass instance of the mapped class.
|
||||
*
|
||||
|
@ -91,6 +91,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
||||
$class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2');
|
||||
|
||||
$class2 = unserialize(serialize($class));
|
||||
$class2->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
|
||||
$this->assertTrue(isset($class2->reflFields['mapped1']));
|
||||
$this->assertTrue(isset($class2->reflFields['mapped2']));
|
||||
@ -315,4 +316,4 @@ class MediumSuperclassEntity extends MediumSuperclassBase
|
||||
class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$serialized = serialize($cm);
|
||||
$cm = unserialize($serialized);
|
||||
$cm->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||||
|
||||
// Check state
|
||||
$this->assertTrue(count($cm->getReflectionProperties()) > 0);
|
||||
|
Loading…
Reference in New Issue
Block a user