From ea2d4e4282438e60a7807087e314e940be080255 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 2 Jan 2012 15:46:20 +0100 Subject: [PATCH] DCOM-93 - Add ClassMetadataFactory#wakeupReflection implementation --- .../ORM/Mapping/ClassMetadataFactory.php | 17 +++++++++++++++++ .../Tools/DisconnectedClassMetadataFactory.php | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index fdf57dbac..07d6344ca 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -172,6 +172,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if ($this->cacheDriver) { if (($cached = $this->cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) { + $this->wakeupReflection($cached, $this->getReflectionService()); $this->loadedMetadata[$realClassName] = $cached; } else { foreach ($this->loadMetadata($realClassName) as $loadedClassName) { @@ -575,6 +576,22 @@ 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; + } } /** diff --git a/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php index f98c8bfae..c9534a76e 100644 --- a/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php @@ -70,4 +70,9 @@ class DisconnectedClassMetadataFactory extends ClassMetadataFactory { return array(); } -} \ No newline at end of file + + public function getReflectionService() + { + return new \Doctrine\Common\Persistence\Mapping\StaticReflectionService; + } +}