Sfoglia il codice sorgente

[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.
Fabien Potencier 13 anni fa
parent
commit
a6670c214a

+ 4 - 3
src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

@@ -144,8 +144,9 @@ abstract class AnnotationClassLoader implements LoaderInterface
 
     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 @@ abstract class AnnotationClassLoader implements LoaderInterface
 
         $this->configureRoute($route, $class, $method, $annot);
 
-        $collection->add($annot->getName(), $route);
+        $collection->add($name, $route);
     }
 
     /**