/** * @covers Router::match * @covers Route::getParameters */ public function testParamsWithDynamicFilterMatch() { $collection = new RouteCollection(); $route = new Route('/js/:filename.js', array('_controller' => 'PHPRouter\\Test\\SomeController::dynamicFilterUrlMatch', 'methods' => 'GET')); $route->setFilters(array(':filename' => '([[:alnum:]\\.]+)'), true); $collection->attachRoute($route); $router = new Router($collection); $this->assertEquals(array(array('filename' => 'someJsFile')), $router->match('/js/someJsFile.js')->getParameters()); $this->assertEquals(array(array('filename' => 'someJsFile.min')), $router->match('/js/someJsFile.min.js')->getParameters()); $this->assertEquals(array(array('filename' => 'someJsFile.min.js')), $router->match('/js/someJsFile.min.js.js')->getParameters()); }
/** * Match if current Route match to the request url, method and type * * @param Route $route * @return bool */ private function match(Route $route) { if (!in_array($this->routeRequest->getRequestMethod(), $route->getMethods())) { return false; } if (!$this->routeRequest->isAjax() && 'ajax' == $route->getType()) { return false; } if (!preg_match($route->getPattern(), $this->routeRequest->getRequestUrl())) { return false; } return true; }
function __construct($resource, array $config) { $controller = explode('::', $config['_controller']); $this->controller = $controller[0]; if (!isset($controller[1])) { throw new Exception('Не определён экшн'); } $this->bundle = $config['bundle']; $this->action = $controller[1]; $this->controllerClass = $config['namespace'] . $this->controller; $config['_controller'] = $config['namespace'] . $config['_controller']; parent::__construct($resource, $config); }
/** * @test */ public function shouldCallSpecifiedCallback() { $route = new Route('GET /test/page/@number.html', '\\PhpRouter\\Test\\Test->page'); $route->parseParams('/test/page/42.html'); $this->assertEquals(42, $route->dispatch()); }