Remove $route from parameter list, only pass when dispatching callback.

pull/301/head v1.3.1
Mike Cao 8 years ago
parent 9c8d492799
commit 6aea7394c4

@ -1 +1 @@
1.3.0 1.3.1

@ -312,6 +312,12 @@ class Engine {
while ($route = $router->route($request)) { while ($route = $router->route($request)) {
$params = array_values($route->params); $params = array_values($route->params);
// Add route info to the parameter list
if ($route->pass) {
$params[] = $route;
}
// Call route handler
$continue = $this->dispatcher->execute( $continue = $this->dispatcher->execute(
$route->callback, $route->callback,
$params $params

@ -127,10 +127,6 @@ class Route {
$this->params[$k] = (array_key_exists($k, $matches)) ? urldecode($matches[$k]) : null; $this->params[$k] = (array_key_exists($k, $matches)) ? urldecode($matches[$k]) : null;
} }
if ($this->pass) {
$this->params[] = $this;
}
$this->regex = $regex; $this->regex = $regex;
return true; return true;

@ -75,7 +75,7 @@ class Router {
* Routes the current request. * Routes the current request.
* *
* @param Request $request Request object * @param Request $request Request object
* @return Route Matching route * @return Route|bool Matching route or false if no match
*/ */
public function route(Request $request) { public function route(Request $request) {
while ($route = $this->current()) { while ($route = $this->current()) {

@ -54,6 +54,10 @@ class RouterTest extends PHPUnit_Framework_TestCase
while ($route = $this->router->route($this->request)) { while ($route = $this->router->route($this->request)) {
$params = array_values($route->params); $params = array_values($route->params);
if ($route->pass) {
$params[] = $route;
}
$continue = $this->dispatcher->execute( $continue = $this->dispatcher->execute(
$route->callback, $route->callback,
$params $params
@ -130,7 +134,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
$this->router->map('/test/@name:[a-z]+', function($name){ $this->router->map('/test/@name:[a-z]+', function($name){
echo $name; echo $name;
}); });
$this->request->url = '/test/abc'; $this->request->url = '/test/abc';
$this->check('abc'); $this->check('abc');
@ -141,7 +144,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
$this->router->map('/blog(/@year(/@month(/@day)))', function($year, $month, $day){ $this->router->map('/blog(/@year(/@month(/@day)))', function($year, $month, $day){
echo "$year,$month,$day"; echo "$year,$month,$day";
}); });
$this->request->url = '/blog/2000'; $this->request->url = '/blog/2000';
$this->check('2000,,'); $this->check('2000,,');
@ -152,7 +154,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
$this->router->map('/@controller/@method(/@id:[0-9]+)', function($controller, $method, $id){ $this->router->map('/@controller/@method(/@id:[0-9]+)', function($controller, $method, $id){
echo "$controller,$method,$id"; echo "$controller,$method,$id";
}); });
$this->request->url = '/user/delete/123'; $this->request->url = '/user/delete/123';
$this->check('user,delete,123'); $this->check('user,delete,123');
@ -163,7 +164,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
$this->router->map('/@controller/@method(/@id:[0-9]+)', function($controller, $method, $id){ $this->router->map('/@controller/@method(/@id:[0-9]+)', function($controller, $method, $id){
echo "$controller,$method,$id"; echo "$controller,$method,$id";
}); });
$this->request->url = '/user/delete/'; $this->request->url = '/user/delete/';
$this->check('user,delete,'); $this->check('user,delete,');
@ -181,16 +181,16 @@ class RouterTest extends PHPUnit_Framework_TestCase
function testRouteObjectPassing(){ function testRouteObjectPassing(){
$this->router->map('/yes_route', function($route){ $this->router->map('/yes_route', function($route){
$this->assertTrue(is_object($route)); $this->assertTrue(is_object($route));
}, }, true);
true);
$this->request->url = '/yes_route'; $this->request->url = '/yes_route';
$this->check(); $this->check();
$this->router->map('/no_route', function($route = null){ $this->router->map('/no_route', function($route = null){
$this->assertTrue(is_null($route)); $this->assertTrue(is_null($route));
}, }, false);
false);
$this->request->url = '/no_route'; $this->request->url = '/no_route';
$this->check(); $this->check();
} }
@ -198,9 +198,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
function testSplatWildcard(){ function testSplatWildcard(){
$this->router->map('/account/*', function($route){ $this->router->map('/account/*', function($route){
echo $route->splat; echo $route->splat;
}, }, true);
true);
$this->request->url = '/account/456/def/xyz'; $this->request->url = '/account/456/def/xyz';
$this->check('456/def/xyz'); $this->check('456/def/xyz');
@ -209,10 +207,8 @@ class RouterTest extends PHPUnit_Framework_TestCase
// Test splat without trailing slash // Test splat without trailing slash
function testSplatWildcardTrailingSlash(){ function testSplatWildcardTrailingSlash(){
$this->router->map('/account/*', function($route){ $this->router->map('/account/*', function($route){
echo $route->splat; echo $route->splat;
}, }, true);
true);
$this->request->url = '/account'; $this->request->url = '/account';
$this->check(); $this->check();
@ -223,9 +219,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
$this->router->map('/account/@name/*', function($name, $route){ $this->router->map('/account/@name/*', function($name, $route){
echo $route->splat; echo $route->splat;
$this->assertEquals('abc', $name); $this->assertEquals('abc', $name);
}, }, true);
true);
$this->request->url = '/account/abc/456/def/xyz'; $this->request->url = '/account/abc/456/def/xyz';
$this->check('456/def/xyz'); $this->check('456/def/xyz');

Loading…
Cancel
Save