Esempio n. 1
0
 /**
  * 获取核心实例
  * @return Core
  */
 public static function &getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new Core();
     }
     return self::$_instance;
 }
 /**
  * Starts the framework
  *
  * @param string|null $settings Path to settings file
  * @return int If all is well then it returns zero
  * @throws \Exception
  */
 public static function run(string $settings = null) : int
 {
     $settingsFile = $settings ? $settings : realpath(dirname(__FILE__) . '/../../../' . 'settings.yml');
     # load settings
     if (!Settings::load($settingsFile)) {
         return false;
     }
     if (Settings::getProduction()) {
         ini_set('display_errors', 'Off');
         ini_set('error_log', '/tmp/php-error.log');
         ini_set('log_errors', 1);
     }
     # set timezone
     Timezone::setTimezone(Settings::getTimezone());
     # set locale language
     I18n::setLocale(I18n::getLanguage());
     # generate routes
     if (Settings::getAutoroute()) {
         Routing::generateRoutes();
     }
     # load routes
     $routesFile = Settings::getRoutesFile();
     if (file_exists($routesFile)) {
         self::$routes = YAML::load($routesFile);
     } else {
         printf('[Error] Routes file %s does not exists', $routesFile);
         return false;
     }
     $dbSettings = Settings::getDBSettings();
     $db = new DB($dbSettings['dbm'], $dbSettings['host'], $dbSettings['name'], $dbSettings['user'], $dbSettings['password']);
     DB::setGlobal($db);
     # load actions
     Actions::autoloader(Settings::getActionsPath());
     Session::start();
     $request = isset($_GET[Settings::SETTINGS_ROUTE_PARAM_VALUE]) ? $_GET[Settings::SETTINGS_ROUTE_PARAM_VALUE] : '';
     if (Routing::parseRoute($request, self::$routes) == -1) {
         Response::response(Response::HTTP_FORBIDDEN);
     }
     return 0;
 }
Esempio n. 3
0
 /**
  * Instance generator of the Object
  * @param  array  $config the config file found at app.php
  * @return Core         The generated config instance
  */
 public static function make($config = array())
 {
     self::$instance = new Core();
     self::$instance->config = $config;
     return self::$instance;
 }