コード例 #1
0
 /**
  * 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;
 }