Skip to content

Commit

Permalink
[Routing] fixed a caching issue when annotations are used on a base c…
Browse files Browse the repository at this point in the history
…lass used by more than one concrete class

Doctrine caches annotations. For methods, it uses PHP reflection and the getDeclaringClass() to create
a unique cache key. Unfortunately, if you have 2 classes that extend another one, the cache will be shared.
It's not a problem except that before this patch, the default route name was also cached (as the cache is serialized
after we changed the object). So, all other classes inherited this default route name. The fix is quite easy:
just don't change the read annotation object.
  • Loading branch information
fabpot committed Aug 30, 2011
1 parent 946ccb6 commit a6670c2
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -144,8 +144,9 @@ public function load($class, $type = null)

protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
{
if (null === $annot->getName()) {
$annot->setName($this->getDefaultRouteName($class, $method));
$name = $annot->getName();
if (null === $name) {
$name = $this->getDefaultRouteName($class, $method);
}

$defaults = array_merge($globals['defaults'], $annot->getDefaults());
Expand All @@ -156,7 +157,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl

$this->configureRoute($route, $class, $method, $annot);

$collection->add($annot->getName(), $route);
$collection->add($name, $route);
}

/**
Expand Down

0 comments on commit a6670c2

Please sign in to comment.