diff --git a/VERSION b/VERSION index 8cfbc90..8428158 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.2 \ No newline at end of file diff --git a/flight/Engine.php b/flight/Engine.php index 7e388bc..d7f69db 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -274,10 +274,13 @@ class Engine { public function _start() { $dispatched = false; $self = $this; + $request = $this->request(); + $response = $this->response(); + $router = $this->router(); // Flush any existing output if (ob_get_length() > 0) { - $this->response()->write(ob_get_clean()); + $response->write(ob_get_clean()); } // Enable output buffering @@ -287,8 +290,8 @@ class Engine { $this->handleErrors($this->get('flight.handle_errors')); // Disable caching for AJAX requests - if ($this->request()->ajax) { - $this->response()->cache(false); + if ($request->ajax) { + $response->cache(false); } // Allow post-filters to run @@ -297,8 +300,9 @@ class Engine { }); // Route the request - while ($route = $this->router()->route($this->request())) { + while ($route = $router->route($request)) { $params = array_values($route->params); + array_push($params, $route); $continue = $this->dispatcher->execute( $route->callback, @@ -309,7 +313,7 @@ class Engine { if (!$continue) break; - $this->router()->next(); + $router->next(); } if (!$dispatched) { diff --git a/flight/net/Route.php b/flight/net/Route.php index 4007e35..f8f99ff 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -39,6 +39,11 @@ class Route { */ public $regex; + /** + * @var string URL splat content + */ + public $splat; + /** * Constructor. * @@ -65,6 +70,8 @@ class Route { $ids = array(); $char = substr($this->pattern, -1); + + $this->splat = substr($url, strpos($this->pattern, '*')); $this->pattern = str_replace(array(')','*'), array(')?','.*?'), $this->pattern); // Build the regex for matching diff --git a/tests/RouterTest.php b/tests/RouterTest.php index c488310..6ddd4c9 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -34,11 +34,13 @@ class RouterTest extends PHPUnit_Framework_TestCase // Checks if a route was matched function check($str = 'OK'){ $route = $this->router->route($this->request); + $params = array_values($route->params); + array_push($params, $route); $this->assertTrue(is_callable($route->callback)); - call_user_func_array($route->callback, $route->params); + call_user_func_array($route->callback, $params); $this->expectOutputString($str); } @@ -146,4 +148,14 @@ class RouterTest extends PHPUnit_Framework_TestCase $this->check(); } + + // Test splat + function testSplatWildcard(){ + $this->router->map('/account/*', function($route){ + echo $route->splat; + }); + $this->request->url = '/account/123/abc/xyz'; + + $this->check('123/abc/xyz'); + } }