Zend Framework

Rest route doesn't work in chains in some cases

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.2
  • Fix Version/s: 1.9.6
  • Component/s: Zend_Rest_Route
  • Labels:
    None

Description

Zend_Rest_Route doesn't work in chains with Zend_Controller_Router_Route.

Here is a simple test case:

 
$route = new Zend_Controller_Router_Route('api');
$router->addRoute("api", $route->chain(new Zend_Rest_Route($front)));

The problem is that Zend_Rest_Route doesn't set matched path in it's "match" method (which is required for chaining to work). As I think it should behave similar to Zend_Controller_Router_Route_Module, which uses following code:

 
public function match($path, $partial = false) 
{
    // skipping method body

    if ($partial) {
        $this->setMatchedPath($matchedPath);
    }

    // skipping
}

Activity

Hide
Luke Crouch added a comment -

Can you help me by expanding the test case code? How is $router defined?

thanks,
-L

Show
Luke Crouch added a comment - Can you help me by expanding the test case code? How is $router defined? thanks, -L
Hide
Vladimir Razuvaev added a comment -

Here is a full test case code:

[code]
$front = Zend_Controller_Front::getInstance();
// default ZF router:
$router = $front->getRouter();
$router->removeDefaultRoutes();

$route = new Zend_Controller_Router_Route('api');
$router->addRoute("api", $route->chain(new Zend_Rest_Route($front)));
[/code]

When trying to navigate to /api/controller/id exception is thrown:
Zend\Controller\Router\Rewrite.php, line 341: Current route is not defined

Currently, I have subclassed Zend_Rest_Route with following code to make it work in chains:

[code]
class RestRoute extends Zend_Rest_Route
{
public function match($request, $partial = false)
{
$result = parent::match($request);
if($partial && $result) { $this->setMatchedPath($request->getPathInfo()); }
return $result;
}
}

[/code]

This is trivially copy-paste from Zend_Controller_Router_Route_Module

Show
Vladimir Razuvaev added a comment - Here is a full test case code: [code] $front = Zend_Controller_Front::getInstance(); // default ZF router: $router = $front->getRouter(); $router->removeDefaultRoutes(); $route = new Zend_Controller_Router_Route('api'); $router->addRoute("api", $route->chain(new Zend_Rest_Route($front))); [/code] When trying to navigate to /api/controller/id exception is thrown: Zend\Controller\Router\Rewrite.php, line 341: Current route is not defined Currently, I have subclassed Zend_Rest_Route with following code to make it work in chains: [code] class RestRoute extends Zend_Rest_Route { public function match($request, $partial = false) { $result = parent::match($request); if($partial && $result) { $this->setMatchedPath($request->getPathInfo()); } return $result; } } [/code] This is trivially copy-paste from Zend_Controller_Router_Route_Module
Hide
Luke Crouch added a comment -

Added partial logic to Zend_Rest_Route::match to support using Zend_Rest_Route in route chains.

Show
Luke Crouch added a comment - Added partial logic to Zend_Rest_Route::match to support using Zend_Rest_Route in route chains.
Hide
Bradley Holt added a comment -

This issue is not fixed in 1.9.4. The code attached to this issue is not present in 1.9.4 or 1.9.5. It appears to be present in trunk but not in the release-1.9 branch. This code should either be merged into the release-1.9 branch or this issue should have its Fix Version set to 1.10.

Show
Bradley Holt added a comment - This issue is not fixed in 1.9.4. The code attached to this issue is not present in 1.9.4 or 1.9.5. It appears to be present in trunk but not in the release-1.9 branch. This code should either be merged into the release-1.9 branch or this issue should have its Fix Version set to 1.10.
Hide
Matthew Weier O'Phinney added a comment -

Patch merged to 1.9 release branch; will release with 1.9.6.

Show
Matthew Weier O'Phinney added a comment - Patch merged to 1.9 release branch; will release with 1.9.6.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: