Просмотр исходного кода

Merge branch 'Bittarman-fix/ChainRouting-Subpath-Resetting'

Rob Allen 10 лет назад
Родитель
Сommit
4911fb4094

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

@@ -89,7 +89,6 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
         $path        = trim($request->getPathInfo(), self::URI_DELIMITER);
         $subPath     = $path;
         $values      = array();
-        $numRoutes   = count($this->_routes);
         $matchedPath = null;
 
         foreach ($this->_routes as $key => $route) {
@@ -106,7 +105,6 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
 
                 $subPath = substr($subPath, strlen($separator));
             }
-
             // TODO: Should be an interface method. Hack for 1.0 BC
             if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
                 $match = $subPath;
@@ -115,8 +113,10 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
                 $match = $request;
             }
 
-            $res = $route->match($match, true, ($key == $numRoutes - 1));
+            $res = $route->match($match, true);
+
             if ($res === false) {
+                $request->setPathInfo($path);
                 return false;
             }
 
@@ -124,7 +124,6 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
 
             if ($matchedPath !== null) {
                 $subPath   = substr($subPath, strlen($matchedPath));
-                $separator = substr($subPath, 0, strlen($this->_separators[$key]));
             }
 
             $values = $res + $values;

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

@@ -815,6 +815,30 @@ class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(2, $res['bar']);
     }
 
+    public function testMultipleChainsWithVersion2Routes()
+    {
+
+        $foo = new Zend_Controller_Router_Route_SubclassTest('foo');
+        $bar = new Zend_Controller_Router_Route_SubclassTest('bar', array('baz' => 'no'));
+
+
+        $chain = $foo->chain($bar);
+
+        $foo2 = new Zend_Controller_Router_Route_SubclassTest('foo');
+        $baz = new Zend_Controller_Router_Route_SubclassTest('baz', array('baz' => 'baz'));
+
+        $chain2 = $foo2->chain($baz);
+
+        $rewrite = new Zend_Controller_Router_Rewrite();
+        $rewrite->addRoute('chain2', $chain2); // First In Last Out, we want this to be matched against second
+        $rewrite->addRoute('chain1', $chain);
+        $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo/baz');
+
+        $res = $rewrite->route($request);
+        $this->assertEquals('baz', $res->getParam('baz'), 'Route did not match');
+        $this->assertEquals('chain2', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
+    }
+
     /**
      * @group ZF-11443
      */
@@ -934,6 +958,36 @@ class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
     }
 }
 
+
+class Zend_Controller_Router_Route_SubclassTest extends Zend_Controller_Router_Route_Static
+{
+    public function match($path, $partial = false)
+    {
+        $path = $path->getPathInfo();
+        $match = parent::match($path, $partial); // TODO: Change the autogenerated stub
+        if (is_array($match)) {
+            $this->setMatchedPath($this->_route);
+        }
+        return $match;
+    }
+
+    public function getVersion()
+    {
+        return 2;
+    }
+
+    public function assemble($data = array(), $reset = false, $encode = false)
+    {
+        // TODO: Implement assemble() method.
+    }
+
+    public static function getInstance(Zend_Config $config)
+    {
+        // TODO: Implement getInstance() method.
+    }
+
+}
+
 /**
  * Zend_Controller_Router_ChainTest_Request - request object for router testing
  *