Skip to content

Commit

Permalink
added loaded annotation map to FileCacheReader
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittjoh committed May 24, 2011
1 parent 92da058 commit a7102fb
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions lib/Doctrine/Common/Annotations/FileCacheReader.php
Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -67,22 +72,26 @@ 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)
{
$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
Expand All @@ -92,22 +101,26 @@ 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)
{
$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
Expand All @@ -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)
Expand Down Expand Up @@ -188,4 +201,9 @@ public function getPropertyAnnotation(\ReflectionProperty $property, $annotation

return null;
}

public function clearLoadedAnnotations()
{
$this->loadedAnnotations = array();
}
}

0 comments on commit a7102fb

Please sign in to comment.