Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 4911fb4

Browse files
committed
Merge branch 'Bittarman-fix/ChainRouting-Subpath-Resetting'
2 parents b70f259 + a5917ce commit 4911fb4

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

library/Zend/Controller/Router/Route/Chain.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function match($request, $partial = null)
8989
$path = trim($request->getPathInfo(), self::URI_DELIMITER);
9090
$subPath = $path;
9191
$values = array();
92-
$numRoutes = count($this->_routes);
9392
$matchedPath = null;
9493

9594
foreach ($this->_routes as $key => $route) {
@@ -106,7 +105,6 @@ public function match($request, $partial = null)
106105

107106
$subPath = substr($subPath, strlen($separator));
108107
}
109-
110108
// TODO: Should be an interface method. Hack for 1.0 BC
111109
if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
112110
$match = $subPath;
@@ -115,16 +113,17 @@ public function match($request, $partial = null)
115113
$match = $request;
116114
}
117115

118-
$res = $route->match($match, true, ($key == $numRoutes - 1));
116+
$res = $route->match($match, true);
117+
119118
if ($res === false) {
119+
$request->setPathInfo($path);
120120
return false;
121121
}
122122

123123
$matchedPath = $route->getMatchedPath();
124124

125125
if ($matchedPath !== null) {
126126
$subPath = substr($subPath, strlen($matchedPath));
127-
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
128127
}
129128

130129
$values = $res + $values;

tests/Zend/Controller/Router/Route/ChainTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,30 @@ public function testChainingStaticDynamicMatchToParams()
815815
$this->assertEquals(2, $res['bar']);
816816
}
817817

818+
public function testMultipleChainsWithVersion2Routes()
819+
{
820+
821+
$foo = new Zend_Controller_Router_Route_SubclassTest('foo');
822+
$bar = new Zend_Controller_Router_Route_SubclassTest('bar', array('baz' => 'no'));
823+
824+
825+
$chain = $foo->chain($bar);
826+
827+
$foo2 = new Zend_Controller_Router_Route_SubclassTest('foo');
828+
$baz = new Zend_Controller_Router_Route_SubclassTest('baz', array('baz' => 'baz'));
829+
830+
$chain2 = $foo2->chain($baz);
831+
832+
$rewrite = new Zend_Controller_Router_Rewrite();
833+
$rewrite->addRoute('chain2', $chain2); // First In Last Out, we want this to be matched against second
834+
$rewrite->addRoute('chain1', $chain);
835+
$request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo/baz');
836+
837+
$res = $rewrite->route($request);
838+
$this->assertEquals('baz', $res->getParam('baz'), 'Route did not match');
839+
$this->assertEquals('chain2', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
840+
}
841+
818842
/**
819843
* @group ZF-11443
820844
*/
@@ -934,6 +958,36 @@ protected function _getRouter()
934958
}
935959
}
936960

961+
962+
class Zend_Controller_Router_Route_SubclassTest extends Zend_Controller_Router_Route_Static
963+
{
964+
public function match($path, $partial = false)
965+
{
966+
$path = $path->getPathInfo();
967+
$match = parent::match($path, $partial); // TODO: Change the autogenerated stub
968+
if (is_array($match)) {
969+
$this->setMatchedPath($this->_route);
970+
}
971+
return $match;
972+
}
973+
974+
public function getVersion()
975+
{
976+
return 2;
977+
}
978+
979+
public function assemble($data = array(), $reset = false, $encode = false)
980+
{
981+
// TODO: Implement assemble() method.
982+
}
983+
984+
public static function getInstance(Zend_Config $config)
985+
{
986+
// TODO: Implement getInstance() method.
987+
}
988+
989+
}
990+
937991
/**
938992
* Zend_Controller_Router_ChainTest_Request - request object for router testing
939993
*

0 commit comments

Comments
 (0)