public function testPriority() { $endPoint = new Point\ControllerPoint(['controller' => 'DemoController', 'action' => 'action']); $this->routes->add('default', new Route('/blog/', $endPoint), 70); $this->routes->add('cats', new Route('/cats/', $endPoint), 50); $this->routes->add('profile', new Route('/cats/', $endPoint), 60); $routes = $this->routes->getRoutes(); self::assertEquals(['default', 'profile', 'cats'], array_keys($routes)); }
/** * @param CollectionRoute $routes * @param string $path * @param null|string $method * @param null|bool $isXHR * @return \Generator * @throws NotFoundException */ public function match(CollectionRoute $routes, $path, $method = null, $isXHR = null) { $find = 0; foreach ($routes->getRoutes() as $route) { $point = $this->matchRoute($route, $path, $method, $isXHR); if ($point) { $find++; (yield $point); } } if (!$find) { throw new NotFoundException('Not found'); } }
protected function setUp() { $this->matcher = new Matcher(); $this->routes = new CollectionRoute(); $endPoint = new Point\ControllerDynamicAction(['controller' => DemoController::class]); $route = new Route('/{lang}/users/{id}/{action}/', $endPoint, ['lang' => 'ru|en', 'action' => '[a-z0-9_]+', 'id' => '\\d+'], Route::ONLY_XHR); $this->routes->add('users', $route, 70); $endPoint = new Point\ControllerDynamicAction(['controller' => DemoController::class]); $route = new Route('/blog/{id}/', $endPoint, ['id' => '\\d+'], Route::ONLY_NO_XHR, ['get']); $this->routes->add('blog', $route, 20); $endPoint = new Point\ControllerPoint(['controller' => DemoController::class, 'action' => 'user']); $route = new Route('/profile/{id}(/)?', $endPoint, ['id' => '\\d+'], null, ['get']); $this->routes->add('profile', $route, 50); $endPoint = new Point\CallablePoint(['callable' => function () { return '404'; }]); $route = new Route('.*', $endPoint, ['id' => '\\d+'], null, ['get']); $this->routes->add('otherwise', $route, 10); }