浏览代码

Merge remote branch 'xdecock/Performance'

Fabien Potencier 14 年之前
父节点
当前提交
84172c4839

+ 7 - 2
src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

@@ -54,7 +54,10 @@ class PhpGeneratorDumper extends GeneratorDumper
             $compiledRoute = $route->compile();
 
             $variables = str_replace("\n", '', var_export($compiledRoute->getVariables(), true));
-            $defaults = str_replace("\n", '', var_export($route->getDefaults(), true));
+            $defaultsMerge='';
+            foreach ($compiledRoute->getDefaults() as $key => $value) {
+                $defaultsMerge.='        $defaults[\''.$key.'\']='.str_replace("\n", '', var_export($value, true)).';'."\n";
+            }
             $requirements = str_replace("\n", '', var_export($compiledRoute->getRequirements(), true));
             $tokens = str_replace("\n", '', var_export($compiledRoute->getTokens(), true));
 
@@ -63,7 +66,9 @@ class PhpGeneratorDumper extends GeneratorDumper
             $methods[] = <<<EOF
     protected function get{$escapedName}RouteInfo()
     {
-        return array($variables, array_merge(\$this->defaults, $defaults), $requirements, $tokens);
+        \$defaults=\$this->defaults;
+$defaultsMerge
+        return array($variables, \$defaults, $requirements, $tokens);
     }
 
 EOF

+ 13 - 5
src/Symfony/Component/Routing/Router.php

@@ -68,12 +68,20 @@ class Router implements RouterInterface
             'resource_type'          => null,
         );
 
-        // check option names
-        if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
-            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: \'%s\'.', implode('\', \'', $diff)));
+        // check option names and live merge, if errors are encountered Exception will be thrown
+        $invalid = array();
+        $isInvalid = false;
+        foreach ($options as $key => $value) {
+            if (array_key_exists($key, $this->options)) {
+                $this->options[$key] = $value;
+            } else {
+                $isInvalid = true;
+                $invalid[] = $key;
+            }
+        }
+        if ($isInvalid) {
+            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: \'%s\'.', implode('\', \'', $invalid)));
         }
-
-        $this->options = array_merge($this->options, $options);
     }
 
     /**