Esempio n. 1
0
 function run()
 {
     if ($this->running) {
         throw new \Exception(get_called_class() . '::run() was previously called!');
     }
     $this->running = true;
     $request = Request::getInstance();
     if ($request->exists(self::PATH_INFO_OVERRIDE_PARAM)) {
         $this->pathInfo = $request->get(self::PATH_INFO_OVERRIDE_PARAM, '/');
         $request->delete(self::PATH_INFO_OVERRIDE_PARAM);
     } else {
         $this->pathInfo = \ManiaLib\Utils\Arrays::getNotNull($_SERVER, 'PATH_INFO', '/');
     }
     list($this->controller, $this->action) = Route::getActionAndControllerFromRoute($this->pathInfo);
     $this->calledURL = $request->createLink();
     $viewsNS =& Config::getInstance()->viewsNS;
     $currentViewsNS = Config::getInstance()->namespace . '\\Views\\';
     if (!in_array($currentViewsNS, $viewsNS)) {
         array_unshift($viewsNS, $currentViewsNS);
     }
     try {
         Controller::factory($this->controller)->launch($this->action);
         Response::getInstance()->render();
     } catch (\Exception $e) {
         call_user_func(Bootstrapper::$errorHandlingCallback, $e);
         Response::getInstance()->render();
     }
 }
Esempio n. 2
0
 /**
  * @param string A route like "/home/index/" or "/home/"
  * @return array[string] An array of (controller, action)
  */
 static function getActionAndControllerFromRoute($route)
 {
     $defaultController = Config::getInstance()->defaultController;
     if (substr($route, 0, 1) == '/') {
         $route = substr($route, 1);
     }
     if (substr($route, -1, 1) == '/') {
         $route = substr($route, 0, -1);
     }
     $route = explode('/', $route, 2);
     $controller = \ManiaLib\Utils\Arrays::getNotNull($route, 0, $defaultController);
     $controller = Route::separatorToUpperCamelCase($controller);
     $action = \ManiaLib\Utils\Arrays::get($route, 1);
     $action = $action ? Route::separatorToCamelCase($action) : null;
     return array($controller, $action);
 }