/** * 初始化 * @return void */ public static function boot() { // 目录定义 self::structure(); // 初始化环境 self::environment(); // 加载配置 Config::configure(CONFIG); // 数据检查 Validate::validity(); // session初始化 Session::start(); // 调度程序 Dispatcher::dispatch(); }
public static function start() { try { $url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $uri_parts = explode('/', trim($url_path, ' /')); $module = array_shift($uri_parts); empty($uri_parts[0]) ? $controllerName = 'Main' : ($controllerName = $uri_parts[0]); empty($uri_parts[1]) ? $action = 'index' : ($action = $uri_parts[1]); if (count($uri_parts) % 2) { throw new Exception('Неверное количество параметров запроса'); } $params = null; for ($i = 2; $i < count($uri_parts); $i++) { $params[$uri_parts[$i]] = $uri_parts[++$i]; } if ($params !== null) { $_REQUEST = array_merge($_REQUEST, $params); } Session::start(); if (!array_key_exists('isAuthorize', $_SESSION)) { Session::set('isAuthorize', false); } if (!Session::get('isAuthorize')) { $controllerName = 'Login'; $action = 'login'; $_SERVER['REQUEST_URI'] = '/kassa/login'; } $controllerName = 'controllers\\' . $controllerName . 'Controller'; $action = $action . '_action'; if (!class_exists($controllerName)) { throw new Exception('Запрашеваемой страницы не существует: ' . $controllerName); } $controller = new $controllerName(); if (!method_exists($controller, $action)) { throw new Exception('Указаного действия не существует:' . $action); } $controller->{$action}(); } catch (Exception $e) { echo $e->getMessage(); } }
/** * 架构方法 设置参数 * @access public * @param array $config 配置参数 */ public function __construct($config = array()) { $this->config = array_merge($this->config, $config); Session::start(); }
/** * Called after the controller is loaded, before the method * * @param string $method name */ public function initialize($method) { \Core\Session::start(); }
/** * 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; }