/** * @param $rootPath * @param bool $run * @param null $configPath * @return \ZPHP\Server\IServer * @throws \Exception */ public static function run($rootPath, $run = true, $configPath = null) { if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } self::$zPath = \dirname(__DIR__); self::setRootPath($rootPath); if (empty($configPath)) { if (!empty($_SERVER['HTTP_HOST'])) { $configPath = \str_replace(':', '_', $_SERVER['HTTP_HOST']); } elseif (!empty($_SERVER['argv'][1])) { $configPath = $_SERVER['argv'][1]; } } if (!empty($configPath)) { self::setConfigPath($configPath); } \spl_autoload_register(__CLASS__ . '::autoLoader'); Config::load(self::getConfigPath()); self::$libPath = Config::get('lib_path', self::$zPath . DS . 'lib'); if ($run && Config::getField('project', 'debug_mode', 0)) { Debug::start(); } $appPath = Config::get('app_path', self::$appPath); self::setAppPath($appPath); $eh = Config::getField('project', 'exception_handler', __CLASS__ . '::exceptionHandler'); \set_exception_handler($eh); \register_shutdown_function(Config::getField('project', 'fatal_handler', __CLASS__ . '::fatalHandler')); $timeZone = Config::get('time_zone', 'Asia/Shanghai'); \date_default_timezone_set($timeZone); $serverMode = Config::get('server_mode', 'Http'); $service = Server\Factory::getInstance($serverMode); if ($run) { $service->run(); } else { return $service; } if ($run && Config::getField('project', 'debug_mode', 0)) { Debug::end(); } }