コード例 #1
0
ファイル: index.php プロジェクト: simudream/caffeine
 /**
  * Starting point for every page request. Loads required core modules, gets data from url and calls
  * necessary modules to make things happen.
  */
 public static function init()
 {
     if (!self::$_inited) {
         self::$_inited = true;
         foreach (self::$_requiredCore as $module) {
             require_once ROOT . 'core/' . $module . '/' . $module . EXT;
         }
         // Set the Load::auto method to handle all class loading from now on
         spl_autoload_register('Load::auto');
         Load::loadSetupFiles();
         // If CLI mode, everything thats needed has been loaded
         if (IS_CLI) {
             return;
         }
         date_default_timezone_set(Config::get('system.timezone'));
         Event::trigger('caffeine.started');
         // If maintenance mode has been set in the config, stop everything and load mainteance view
         if (Config::get('system.maintenance_mode')) {
             View::error(ERROR_MAINTENANCE);
         } else {
             list($route, $data) = Router::getRouteData();
             if ($data) {
                 if (self::_hasPermission($route, $data)) {
                     list($module, $controller, $method) = $data['callback'];
                     $params = Router::getParams();
                     // Make sure controller words are upper-case
                     $conBits = explode('_', $controller);
                     foreach ($conBits as &$bit) {
                         $bit = ucfirst($bit);
                     }
                     $controller = implode('_', $conBits);
                     $controller = sprintf('%s_%sController', ucfirst($module), ucwords($controller));
                     // Call the routes controller and method
                     if (method_exists($controller, $method)) {
                         $response = call_user_func_array(array($controller, $method), $params);
                         if (!self::_isErrorResponse($response)) {
                             Event::trigger('module.response', array($response));
                             View::load($module, $controller, $method);
                         } else {
                             View::error($response);
                         }
                     } else {
                         Log::error($module, sprintf('The method %s::%s() called by route %s doesn\'t exist.', $controller, $method, $route));
                         View::error(ERROR_500);
                     }
                 } else {
                     View::error(ERROR_ACCESSDENIED);
                 }
             } else {
                 if ($route !== '[index]' || !View::directLoad('index')) {
                     View::error(ERROR_404);
                 }
             }
         }
         View::output();
         Event::trigger('caffeine.finished');
     } else {
         die('Why are you trying to re-initialize Caffeine?');
     }
 }