ソースを参照

[Routing] added setContext() method to both matchers and generators

Fabien Potencier 14 年 前
コミット
ca8c7907e2

+ 10 - 0
src/Symfony/Component/Routing/Generator/UrlGenerator.php

@@ -41,6 +41,16 @@ class UrlGenerator implements UrlGeneratorInterface
         $this->cache = array();
     }
 
+    /**
+     * Sets the request context.
+     *
+     * @param array $context  The context
+     */
+    public function setContext(array $context = array())
+    {
+        $this->context = $context;
+    }
+
     /**
      * Generates a URL from the given parameters.
      *

+ 10 - 0
src/Symfony/Component/Routing/Matcher/ApacheUrlMatcher.php

@@ -36,6 +36,16 @@ class ApacheUrlMatcher extends UrlMatcher
         $this->defaults = $defaults;
     }
 
+    /**
+     * Sets the request context.
+     *
+     * @param array $context  The context
+     */
+    public function setContext(array $context = array())
+    {
+        $this->context = $context;
+    }
+
     /**
      * Tries to match a URL based on Apache mod_rewrite matching.
      *

+ 10 - 0
src/Symfony/Component/Routing/Matcher/UrlMatcher.php

@@ -39,6 +39,16 @@ class UrlMatcher implements UrlMatcherInterface
         $this->defaults = $defaults;
     }
 
+    /**
+     * Sets the request context.
+     *
+     * @param array $context  The context
+     */
+    public function setContext(array $context = array())
+    {
+        $this->context = $context;
+    }
+
     /**
      * Tries to match a URL with a set of routes.
      *

+ 2 - 11
src/Symfony/Component/Routing/Router.php

@@ -94,17 +94,8 @@ class Router implements RouterInterface
      */
     public function setContext(array $context = array())
     {
-        $this->context = $context;
-    }
-
-    /**
-     * Sets the defaults.
-     *
-     * @param array $defaults The defaults
-     */
-    public function setDefaults(array $defaults = array())
-    {
-        $this->defaults = $defaults;
+        $this->getMatcher()->setContext($context);
+        $this->getGenerator()->setContext($context);
     }
 
     /**