Browse Source

[Routing] added 'defaults' support in Annotation class loader

Fabien Potencier 14 years ago
parent
commit
b753ea45b2

+ 12 - 0
src/Symfony/Component/Routing/Annotation/Route.php

@@ -22,6 +22,7 @@ class Route
     protected $name;
     protected $requirements;
     protected $options;
+    protected $defaults;
 
     /**
      * Constructor.
@@ -32,6 +33,7 @@ class Route
     {
         $this->requirements = array();
         $this->options = array();
+        $this->defaults = array();
 
         if (isset($data['value'])) {
             $data['pattern'] = $data['value'];
@@ -86,4 +88,14 @@ class Route
     {
         return $this->options;
     }
+
+    public function setDefaults($defaults)
+    {
+        $this->defaults = $defaults;
+    }
+
+    public function getDefaults()
+    {
+        return $this->defaults;
+    }
 }

+ 6 - 1
src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

@@ -87,6 +87,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
             'pattern'      => '',
             'requirements' => array(),
             'options'      => array(),
+            'defaults'     => array(),
         );
 
         if ($annot = $this->reader->getClassAnnotation($class, $annotClass)) {
@@ -101,6 +102,10 @@ abstract class AnnotationClassLoader implements LoaderInterface
             if (null !== $annot->getOptions()) {
                 $globals['options'] = $annot->getOptions();
             }
+
+            if (null !== $annot->getDefaults()) {
+                $globals['defaults'] = $annot->getDefaults();
+            }
         }
 
         $this->reader->setDefaultAnnotationNamespace('Symfony\\Component\\Routing\\Annotation\\');
@@ -111,7 +116,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
                     $annot->setName($this->getDefaultRouteName($class, $method));
                 }
 
-                $defaults = $this->getRouteDefaults($class, $method, $annot);
+                $defaults = array_merge($globals['defaults'], $annot->getDefaults(), $this->getRouteDefaults($class, $method, $annot));
                 $requirements = array_merge($globals['requirements'], $annot->getRequirements());
                 $options = array_merge($globals['options'], $annot->getOptions());