From a7102fbff94b3525921d62055bc543d2ad728419 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Tue, 24 May 2011 12:12:58 +0200 Subject: [PATCH] added loaded annotation map to FileCacheReader --- .../Common/Annotations/FileCacheReader.php | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php index 4dbdbf746..0b8b79620 100644 --- a/lib/Doctrine/Common/Annotations/FileCacheReader.php +++ b/lib/Doctrine/Common/Annotations/FileCacheReader.php @@ -34,6 +34,7 @@ class FileCacheReader implements Reader private $reader; private $dir; private $debug; + private $loadedAnnotations = array(); public function __construct(Reader $reader, $cacheDir, $debug = false) { @@ -53,11 +54,15 @@ public function getClassAnnotations(\ReflectionClass $class) { $key = $class->getName(); + if (isset($this->loadedAnnotations[$key])) { + return $this->loadedAnnotations[$key]; + } + $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php'; if (!file_exists($path)) { $annot = $this->reader->getClassAnnotations($class); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } if ($this->debug @@ -67,10 +72,10 @@ public function getClassAnnotations(\ReflectionClass $class) $annot = $this->reader->getClassAnnotations($class); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } - return include $path; + return $this->loadedAnnotations[$key] = include $path; } public function getPropertyAnnotations(\ReflectionProperty $property) @@ -78,11 +83,15 @@ public function getPropertyAnnotations(\ReflectionProperty $property) $class = $property->getDeclaringClass(); $key = $class->getName().'$'.$property->getName(); + if (isset($this->loadedAnnotations[$key])) { + return $this->loadedAnnotations[$key]; + } + $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php'; if (!file_exists($path)) { $annot = $this->reader->getPropertyAnnotations($property); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } if ($this->debug @@ -92,10 +101,10 @@ public function getPropertyAnnotations(\ReflectionProperty $property) $annot = $this->reader->getPropertyAnnotations($property); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } - return include $path; + return $this->loadedAnnotations[$key] = include $path; } public function getMethodAnnotations(\ReflectionMethod $method) @@ -103,11 +112,15 @@ public function getMethodAnnotations(\ReflectionMethod $method) $class = $method->getDeclaringClass(); $key = $class->getName().'#'.$method->getName(); + if (isset($this->loadedAnnotations[$key])) { + return $this->loadedAnnotations[$key]; + } + $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php'; if (!file_exists($path)) { $annot = $this->reader->getMethodAnnotations($method); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } if ($this->debug @@ -117,10 +130,10 @@ public function getMethodAnnotations(\ReflectionMethod $method) $annot = $this->reader->getMethodAnnotations($method); $this->saveCacheFile($path, $annot); - return $annot; + return $this->loadedAnnotations[$key] = $annot; } - return include $path; + return $this->loadedAnnotations[$key] = include $path; } private function saveCacheFile($path, $data) @@ -188,4 +201,9 @@ public function getPropertyAnnotation(\ReflectionProperty $property, $annotation return null; } + + public function clearLoadedAnnotations() + { + $this->loadedAnnotations = array(); + } } \ No newline at end of file