コード例 #1
0
ファイル: Application.php プロジェクト: popphp/popphp
 /**
  * Run the application.
  *
  * @param  boolean $exit
  * @return void
  */
 public function run($exit = true)
 {
     try {
         $this->init();
         // Trigger any app.route.pre events
         $this->trigger('app.route.pre');
         if (null !== $this->router) {
             $this->router->route();
             // Trigger any app.dispatch.post events
             $this->trigger('app.dispatch.pre');
             if ($this->router->hasController()) {
                 $controller = $this->router->getController();
                 if ($this->router->getControllerClass() == 'Closure') {
                     if ($this->router->hasRouteParams()) {
                         call_user_func_array($controller, $this->router->getRouteParams());
                     } else {
                         $controller();
                     }
                 } else {
                     $params = $this->router->hasRouteParams() ? $this->router->getRouteParams() : null;
                     $controller->dispatch($this->router->getAction(), $params);
                 }
             } else {
                 $this->router->noRouteFound($exit);
             }
             // Trigger any app.dispatch.post events
             $this->trigger('app.dispatch.post');
         }
     } catch (Exception $exception) {
         // Trigger any app.error events
         $this->trigger('app.error', ['exception' => $exception]);
     }
 }