コード例 #1
0
ファイル: Context.php プロジェクト: JonathanRH/thebuggenie
 /**
  * Launches the MVC framework
  */
 public static function go()
 {
     Logging::log('Dispatching');
     try {
         if (($route = self::getRouting()->getRouteFromUrl(self::getRequest()->getParameter('url', null, false))) || self::isInstallmode()) {
             if (self::isUpgrademode()) {
                 $route = array('module' => 'installation', 'action' => 'upgrade');
             } elseif (self::isInstallmode()) {
                 $route = array('module' => 'installation', 'action' => 'installIntro');
             }
             if (!self::isInternalModule($route['module'])) {
                 if (is_dir(THEBUGGENIE_MODULES_PATH . $route['module'])) {
                     if (!file_exists(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'controllers' . DS . 'Main.php')) {
                         throw new \thebuggenie\core\framework\exceptions\ActionNotFoundException('The `' . $route['module'] . '` module is missing a `/controllers/Main.php` controller, containing the module its initial actions.');
                     }
                 } else {
                     throw new \Exception('Cannot load the ' . $route['module'] . ' module');
                 }
                 $actionClassBase = "\\thebuggenie\\modules\\" . $route['module'] . '\\controllers\\';
             } else {
                 $actionClassBase = "\\thebuggenie\\core\\modules\\" . $route['module'] . '\\controllers\\';
             }
             /**
              * Set up the action object by identifying the Controller from the action. The following actions can
              * be resolved by the Framework:
              *
              *  actionName          => /controllers/Main.php::runActionName()
              *  ::actionName        => /controllers/Main.php::runActionName()
              *  Other::actionName   => /controllers/Other.php::runActionName()
              *
              **/
             // If a separate controller is defined within the action name
             if (strpos($route['action'], '::')) {
                 $routing = explode('::', $route['action']);
                 $moduleController = $actionClassBase . $routing[0];
                 $moduleMethod = $routing[1];
                 if (class_exists($moduleController) && is_callable($moduleController, 'run' . ucfirst($moduleMethod))) {
                     $actionObject = new $moduleController();
                 } else {
                     throw new \Exception('The `' . $route['action'] . '` controller action is not callable');
                 }
             } else {
                 $actionClassName = $actionClassBase . 'Main';
                 $actionObject = new $actionClassName();
                 $moduleMethod = $route['action'];
             }
             $moduleName = $route['module'];
         } else {
             // Default
             $actionObject = new \thebuggenie\core\modules\main\controllers\Common();
             $moduleName = 'main';
             $moduleMethod = 'notFound';
         }
         self::$_action = $actionObject;
         if (!self::isInstallmode()) {
             self::initializeUser();
         }
         self::setupI18n();
         if (self::$_redirect_login == 'login') {
             Logging::log('An error occurred setting up the user object, redirecting to login', 'main', Logging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'login') {
                 self::setMessage('login_message_err', self::geti18n()->__('Please log in'));
             }
             self::getResponse()->headerRedirect(self::getRouting()->generate('login_page'), 403);
         }
         if (self::$_redirect_login == 'elevated_login') {
             Logging::log('Elevated permissions required', 'main', Logging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'elevated_login') {
                 self::setMessage('elevated_login_message_err', self::geti18n()->__('Please re-enter your password to continue'));
             }
             $actionObject = new \thebuggenie\core\modules\main\controllers\Main();
             $moduleName = 'main';
             $moduleMethod = 'elevatedLogin';
         }
         if (self::performAction($actionObject, $moduleName, $moduleMethod)) {
             if (self::isDebugMode()) {
                 self::generateDebugInfo();
             }
             if (\b2db\Core::isInitialized()) {
                 \b2db\Core::closeDBLink();
             }
             return true;
         }
     } catch (\thebuggenie\core\framework\exceptions\TemplateNotFoundException $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (\thebuggenie\core\framework\exceptions\ActionNotFoundException $e) {
         \b2db\Core::closeDBLink();
         header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (\thebuggenie\core\framework\exceptions\CSRFFailureException $e) {
         \b2db\Core::closeDBLink();
         if (self::isDebugMode()) {
             self::generateDebugInfo();
         }
         self::getResponse()->setHttpStatus(301);
         $message = $e->getMessage();
         if (self::getRequest()->getRequestedFormat() == 'json') {
             self::getResponse()->setContentType('application/json');
             $message = json_encode(array('message' => $message));
         }
         self::getResponse()->renderHeaders();
         echo $message;
     } catch (\Exception $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     }
 }
コード例 #2
0
ファイル: Context.php プロジェクト: RTechSoft/thebuggenie
 /**
  * Launches the MVC framework
  */
 public static function go()
 {
     Logging::log('Dispatching');
     try {
         if (($route = self::getRouting()->getRouteFromUrl(self::getRequest()->getParameter('url', null, false))) || self::isInstallmode()) {
             if (self::isUpgrademode()) {
                 $route = array('module' => 'installation', 'action' => 'upgrade');
             } elseif (self::isInstallmode()) {
                 $route = array('module' => 'installation', 'action' => 'installIntro');
             }
             if (!self::isInternalModule($route['module'])) {
                 if (is_dir(THEBUGGENIE_MODULES_PATH . $route['module'])) {
                     if (!file_exists(THEBUGGENIE_MODULES_PATH . $route['module'] . DS . 'Actions.php')) {
                         throw new \thebuggenie\core\framework\exceptions\ActionNotFoundException('The ' . $route['module'] . ' module is missing the Actions.php file, containing all the module actions');
                     }
                 } else {
                     throw new \Exception('Cannot load the ' . $route['module'] . ' module');
                 }
                 $actionClassName = "\\thebuggenie\\modules\\" . $route['module'] . "\\Actions";
             } else {
                 $actionClassName = "\\thebuggenie\\core\\modules\\" . $route['module'] . "\\Actions";
             }
             // Set up the action object
             // Construct the action class and method name, including any pre- action(s)
             $actionObject = new $actionClassName();
             $moduleName = $route['module'];
             $moduleMethod = $route['action'];
         } else {
             $actionObject = new \thebuggenie\core\modules\main\Actions();
             $moduleName = 'main';
             $moduleMethod = 'notFound';
         }
         self::$_action = $actionObject;
         if (!self::isInstallmode()) {
             self::initializeUser();
         }
         self::setupI18n();
         if (self::$_redirect_login == 'login') {
             Logging::log('An error occurred setting up the user object, redirecting to login', 'main', Logging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'login') {
                 self::setMessage('login_message_err', self::geti18n()->__('Please log in'));
             }
             self::getResponse()->headerRedirect(self::getRouting()->generate('login_page'), 403);
         }
         if (self::$_redirect_login == 'elevated_login') {
             Logging::log('Elevated permissions required', 'main', Logging::LEVEL_NOTICE);
             if (self::getRouting()->getCurrentRouteName() != 'elevated_login') {
                 self::setMessage('elevated_login_message_err', self::geti18n()->__('Please re-enter your password to continue'));
             }
             $actionObject = new \thebuggenie\core\modules\main\Actions();
             $moduleName = 'main';
             $moduleMethod = 'elevatedLogin';
         }
         if (self::performAction($actionObject, $moduleName, $moduleMethod)) {
             if (self::isDebugMode()) {
                 self::generateDebugInfo();
             }
             if (\b2db\Core::isInitialized()) {
                 \b2db\Core::closeDBLink();
             }
             return true;
         }
     } catch (\thebuggenie\core\framework\exceptions\TemplateNotFoundException $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (\thebuggenie\core\framework\exceptions\ActionNotFoundException $e) {
         \b2db\Core::closeDBLink();
         header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     } catch (\thebuggenie\core\framework\exceptions\CSRFFailureException $e) {
         \b2db\Core::closeDBLink();
         if (self::isDebugMode()) {
             self::generateDebugInfo();
         }
         self::getResponse()->setHttpStatus(301);
         $message = $e->getMessage();
         if (self::getRequest()->getRequestedFormat() == 'json') {
             self::getResponse()->setContentType('application/json');
             $message = json_encode(array('message' => $message));
         }
         self::getResponse()->renderHeaders();
         echo $message;
     } catch (\Exception $e) {
         \b2db\Core::closeDBLink();
         //header("HTTP/1.0 404 Not Found", true, 404);
         throw $e;
     }
 }