Issues

ZF-6398: Improve Zend_Controller_Router_Route_Chain that Routes added to Chains still could be used in Router without chains

Description

Currently (version 1.8) method chain of Zend_Controller_Router_Route_Chain looks like:

public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = '/')
{
    $route->isPartial(true);

    $this->_routes[]     = $route;
    $this->_separators[] = $separator;

    return $this;

}

So when you add any Route object to chain it becomes Partial and stop function outside a chain.

Let say we need to reuse some route object in different chains to minimize memory usage. It's ok. But if we need to add this route to router without using chains (i.e. create partial route) it wouldn't function because of Partial flag set to true:

$route1 = new Zend_Controller_Router_Route (......); $route2 = new Zend_Controller_Router_Route (......); $route3 = new Zend_Controller_Router_Route (......);

$router->addRoute($route1); // will be broken because of Partial flag $router->addRoute($route1->chain($route2)); // ok $router->addRoute($route1->chain($route2)->chain(route3)); // ok

Why not set Partial directly in match/assemble methods of Zend_Controller_Router_Route_Chain before calling match method of chain member and set Partial back to false after that.

Comments

Assigning to Ben Scholzen

Your suggestion is possible, but would generate quuite some overhead. My prefered solution is to hand an additional $partial-parameter to the match() and assemble() method, tho this would be a change of the public API. I will make that change with the router refactoring.

Well to minimize overhead there could be also another possible solution:

Remove partial flag, instead of using partial flag check in match/assemble instanceof caller object (If caller is instanceof Router_Abstract -- path is NOT partial, if instanceof Router_Route_Abstract -- path is partial),

Also your solution with default value of partial === null (which will then use isPartial object flag) would be fine and retain backward compatibility

Regards Anjey