Example #1
0
File: Core.php Project: iamfat/gini
 /**
  * Function to start the whole gini framework.
  **/
 public static function start()
 {
     error_reporting(E_ALL & ~E_NOTICE);
     spl_autoload_register('\\Gini\\Core::autoload');
     register_shutdown_function('\\Gini\\Core::shutdown');
     set_exception_handler('\\Gini\\Core::exception');
     set_error_handler('\\Gini\\Core::error', E_ALL & ~E_NOTICE);
     assert_options(ASSERT_ACTIVE, 1);
     assert_options(ASSERT_WARNING, 0);
     assert_options(ASSERT_QUIET_EVAL, 1);
     assert_options(ASSERT_CALLBACK, '\\Gini\\Core::assertion');
     mb_internal_encoding('utf-8');
     mb_language('uni');
     define('CLASS_DIR', 'class');
     define('VIEW_DIR', 'view');
     define('RAW_DIR', 'raw');
     define('DATA_DIR', 'data');
     define('CACHE_DIR', 'cache');
     $info = self::import(SYS_PATH);
     if (isset($_SERVER['GINI_APP_PATH'])) {
         $app_path = $_SERVER['GINI_APP_PATH'];
         define('APP_PATH', $app_path);
         $info = self::import(APP_PATH);
     } else {
         define('APP_PATH', SYS_PATH);
     }
     define('APP_ID', $info->id);
     // load composer if detected
     $composer_path = APP_PATH . '/vendor/autoload.php';
     if (file_exists($composer_path)) {
         require_once $composer_path;
     }
     Config::setup();
     Event::setup();
     !method_exists('\\Gini\\Application', 'setup') or \Gini\Application::setup();
     // 生成一个 APP_HASH 用于做版本唯一说明
     define('APP_HASH', sha1(array_reduce(self::$MODULE_INFO, function ($str, $info) {
         return $str . ':' . $info->id . '/' . $info->version;
     }, '')));
     // module setup won't be run before CLASS cache
     if (isset($GLOBALS['gini.class_map'])) {
         foreach (self::$MODULE_INFO as $name => $info) {
             $class = '\\Gini\\Module\\' . strtr($name, ['-' => '', '_' => '', '/' => '']);
             if (!$info->error && method_exists($class, 'setup')) {
                 call_user_func($class . '::setup');
             }
         }
     }
     global $argv;
     !method_exists('\\Gini\\Application', 'main') or \Gini\Application::main($argv);
 }