Skip to content
This repository was archived by the owner on May 16, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions library/Zend/Controller/Router/Route/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function match($request, $partial = null)
$path = trim($request->getPathInfo(), self::URI_DELIMITER);
$subPath = $path;
$values = array();
$numRoutes = count($this->_routes);
$matchedPath = null;

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

$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;
Expand All @@ -115,16 +113,17 @@ public function match($request, $partial = null)
$match = $request;
}

$res = $route->match($match, true, ($key == $numRoutes - 1));
$res = $route->match($match, true);

if ($res === false) {
$request->setPathInfo($path);
return false;
}

$matchedPath = $route->getMatchedPath();

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

$values = $res + $values;
Expand Down
54 changes: 54 additions & 0 deletions tests/Zend/Controller/Router/Route/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,30 @@ public function testChainingStaticDynamicMatchToParams()
$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
*/
Expand Down Expand Up @@ -934,6 +958,36 @@ protected function _getRouter()
}
}


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
*
Expand Down