コード例 #1
0
ファイル: Application.php プロジェクト: atijust/fastra
 /**
  * @return \FastRoute\Dispatcher
  */
 private function createDispatcher()
 {
     $routeDefinition = function (RouteCollector $collector) {
         foreach ($this->routeCollection->getRoutes() as $route) {
             $collector->addRoute($route->methods, $route->path, $route);
         }
     };
     if (isset($this['route.cache_file'])) {
         return \FastRoute\cachedDispatcher($routeDefinition, ['cacheFile' => $this['route.cache_file'], 'cacheDisabled' => $this['debug']]);
     } else {
         return \FastRoute\simpleDispatcher($routeDefinition);
     }
 }
コード例 #2
0
 public function testMiddleware()
 {
     $router = new RouteCollection();
     $router->group(function (RouteCollection $router) {
         $router->group(function (RouteCollection $router) {
             $router->route('GET', '/path', 'handler')->middleware(['m1', 'm2']);
         })->middleware(['m3', 'm4']);
     })->middleware(['m5', 'm6']);
     $routes = $router->getRoutes();
     $this->assertRoute('GET', '/path', 'handler', ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'], reset($routes));
     $this->assertFalse(next($routes));
     $router = new RouteCollection();
     $router->group(function (RouteCollection $router) {
         $router->group(function (RouteCollection $router) {
             $router->route('GET', '/path', 'handler')->middleware('m1')->middleware('m2');
         })->middleware('m3')->middleware('m4');
     })->middleware('m5')->middleware('m6');
     $routes = $router->getRoutes();
     $this->assertRoute('GET', '/path', 'handler', ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'], reset($routes));
     $this->assertFalse(next($routes));
 }