Example #1
0
 public function handle()
 {
     $this->router = Router::getInstance(App::path('routes'), App::path('filter'));
     $defaultRouterToken = App::environment(Globals::ROUTER_DEFAULT_TOKENS);
     if (isset($defaultRouterToken) && !empty($defaultRouterToken)) {
         $this->router->baseMappings['default']['default'] = $defaultRouterToken;
     } else {
         $defaultRouterToken = $this->router->baseMappings['default']['default'];
     }
     $this->router->registerMatchedHandler(function ($params) {
         DI::bindSingleton(Request::class, new Request($params));
         DI::bindSingleton(Response::class, new Response());
     });
     $this->router->registerDefaultMatchedHandler(function ($params) use($defaultRouterToken) {
         $namespace = null;
         if (array_key_exists('namespace', $params)) {
             $namespace = $params['namespace'];
         }
         if (array_key_exists('controller', $params)) {
             $controller = $params['controller'];
         }
         if (array_key_exists('action', $params)) {
             $action = $params['action'];
         }
         if (!isset($controller)) {
             $controller = $defaultRouterToken['controller'];
         }
         if (!isset($action)) {
             $action = $defaultRouterToken['action'];
         }
         Controller::invoke($controller, $action, $namespace);
     });
     $this->router->missing(function () {
         throw new URLRouterException("URL Routing missing.");
     });
     $this->router->routing();
 }