Browse Source

[ZF-5366] Fixed omitting of parameters when route is partial

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15460 44c647ce-9c0f-0410-b52a-842ac1e357ba
dasprid 16 years ago
parent
commit
0830f11791

+ 2 - 2
library/Zend/Controller/Router/Route.php

@@ -302,7 +302,7 @@ class Zend_Controller_Router_Route extends Zend_Controller_Router_Route_Abstract
      * @param  boolean $reset Whether or not to set route defaults with those provided in $data
      * @return string Route path with user submitted parameters
      */
-    public function assemble($data = array(), $reset = false, $encode = false)
+    public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
     {
         if ($this->_isTranslated) {
             $translator = $this->getTranslator();
@@ -377,7 +377,7 @@ class Zend_Controller_Router_Route extends Zend_Controller_Router_Route_Abstract
                 }
             }
                 
-            if ($flag || $value !== $defaultValue) {
+            if ($flag || $value !== $defaultValue || $partial) {
                 if ($encode) $value = urlencode($value);
                 $return = $this->_urlDelimiter . $value . $return;
                 $flag = true;

+ 4 - 3
library/Zend/Controller/Router/Route/Chain.php

@@ -126,14 +126,15 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
      */
     public function assemble($data = array(), $reset = false, $encode = false)
     {
-        $value = '';
-
+        $value     = '';
+        $numRoutes = count($this->_routes);
+        
         foreach ($this->_routes as $key => $route) {
             if ($key > 0) {
                 $value .= $this->_separators[$key];
             }
             
-            $value .= $route->assemble($data, $reset, $encode, true);
+            $value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key));
             
             if (method_exists($route, 'getVariables')) {
                 $variables = $route->getVariables();

+ 2 - 2
library/Zend/Controller/Router/Route/Hostname.php

@@ -248,7 +248,7 @@ class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route
      * @param  boolean $reset Whether or not to set route defaults with those provided in $data
      * @return string Route path with user submitted parameters
      */
-    public function assemble($data = array(), $reset = false, $encode = false)
+    public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
     {
         $host = array();
         $flag = false;
@@ -281,7 +281,7 @@ class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route
         $return = '';
 
         foreach (array_reverse($host, true) as $key => $value) {
-            if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key])) {
+            if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key]) || $partial) {
                 if ($encode) $value = urlencode($value);
                 $return = '.' . $value . $return;
                 $flag = true;

+ 1 - 1
library/Zend/Controller/Router/Route/Module.php

@@ -198,7 +198,7 @@ class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_A
      * @param bool $reset Weither to reset the current params
      * @return string Route path with user submitted parameters
      */
-    public function assemble($data = array(), $reset = false, $encode = true)
+    public function assemble($data = array(), $reset = false, $encode = true, $partial = false)
     {
         if (!$this->_keysSet) {
             $this->_setRequestKeys();

+ 1 - 1
library/Zend/Controller/Router/Route/Regex.php

@@ -154,7 +154,7 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
      * @param  array $data An array of name (or index) and value pairs used as parameters
      * @return string Route path with user submitted parameters
      */
-    public function assemble($data = array(), $reset = false, $encode = false)
+    public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
     {
         if ($this->_reverse === null) {
             require_once 'Zend/Controller/Router/Exception.php';

+ 1 - 1
library/Zend/Controller/Router/Route/Static.php

@@ -94,7 +94,7 @@ class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_A
      * @param array $data An array of variable and value pairs used as parameters
      * @return string Route path with user submitted parameters
      */
-    public function assemble($data = array(), $reset = false, $encode = false)
+    public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
     {
         return $this->_route;
     }

+ 12 - 0
tests/Zend/Controller/Router/Route/ChainTest.php

@@ -182,6 +182,18 @@ class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('val', $res['var']);
     }
     
+    public function testVariableOmittingWhenPartial()
+    {
+        $foo = new Zend_Controller_Router_Route(':foo', array('foo' => 'foo'));
+        $bar = new Zend_Controller_Router_Route(':bar', array('bar' => 'bar'));
+
+        $chain = $foo->chain($bar);
+
+        $path = $chain->assemble(array());
+
+        $this->assertEquals('foo/', $path);
+    }
+    
     public function testVariableUnsettingRoute()
     {
         $foo = new Zend_Controller_Router_Route(':foo');