From a6670c214a447d4a27f7ebf0acc726a64c63c8e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 30 Aug 2011 21:37:30 +0200 Subject: [PATCH] [Routing] fixed a caching issue when annotations are used on a base class 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. --- .../Component/Routing/Loader/AnnotationClassLoader.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 8a2c5fe0e993..aa0ec96fc7a8 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -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()); @@ -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); } /**