Bladeren bron

[Routing] allowed default route variables to be null

Fabien Potencier 14 jaren geleden
bovenliggende
commit
7e58c3f976
2 gewijzigde bestanden met toevoegingen van 13 en 1 verwijderingen
  1. 12 0
      src/Symfony/Component/Routing/Route.php
  2. 1 1
      src/Symfony/Component/Routing/RouteCompiler.php

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

@@ -159,6 +159,18 @@ class Route
         return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
     }
 
+    /**
+     * Checks if a default value is set for the given variable.
+     *
+     * @param string $name A variable name
+     *
+     * @return Boolean true if the default value is set, false otherwise
+     */
+    public function hasDefault($name)
+    {
+        return array_key_exists($name, $this->defaults);
+    }
+
     /**
      * Sets a default value.
      *

+ 1 - 1
src/Symfony/Component/Routing/RouteCompiler.php

@@ -212,7 +212,7 @@ class RouteCompiler implements RouteCompilerInterface
         $this->segments[] = preg_quote($separator, '#').'(?P<'.$variable.'>'.$requirement.')';
         $this->variables[$variable] = $name;
 
-        if (null === $this->route->getDefault($variable)) {
+        if (!$this->route->hasDefault($variable)) {
             $this->firstOptional = count($this->segments);
         }
     }