private function __construct() { if (!defined('DEBUG')) { define('DEBUG', 'on'); } if (DEBUG == 'off') { \error_reporting(0); } $this->env['sapi_name'] = php_sapi_name(); if ($this->env['sapi_name'] != 'cli') { Swoole\Error::$echo_html = true; } if (empty(self::$app_path)) { if (defined('WEBPATH')) { self::$app_path = WEBPATH . '/apps'; } else { Swoole\Error::info("core error", __CLASS__ . ": Swoole::\$app_path and WEBPATH empty."); } } define('APPSPATH', self::$app_path); //将此目录作为App命名空间的根目录 Swoole\Loader::setRootNS('App', self::$app_path . '/classes'); $this->load = new Swoole\Loader($this); $this->model = new Swoole\ModelLoader($this); //路由钩子,URLRewrite $this->addHook(Swoole::HOOK_ROUTE, 'swoole_urlrouter_rewrite'); //mvc $this->addHook(Swoole::HOOK_ROUTE, 'swoole_urlrouter_mvc'); //设置路由函数 $this->router(array($this, 'urlRoute')); }
<?php define("SWOOLEPATH", str_replace("\\", "/", __DIR__)); define("LIBPATH", SWOOLEPATH . '/../'); if (PHP_OS == 'WINNT') { define("NL", "\r\n"); } else { define("NL", "\n"); } define("BL", "<br />" . NL); require_once SWOOLEPATH . '/Loader.php'; /** * 注册顶层命名空间到自动载入器 */ Swoole\Loader::setRootNS('Swoole', SWOOLEPATH); spl_autoload_register('\\Swoole\\Loader::autoload');
* @package SwooleSystem * @author 韩天峰 */ define("LIBPATH", __DIR__); if (PHP_OS == 'WINNT') { define("NL", "\r\n"); } else { define("NL", "\n"); } define("BL", "<br />" . NL); require_once __DIR__ . '/Swoole/Swoole.php'; require_once __DIR__ . '/Swoole/Loader.php'; /** * 注册顶层命名空间到自动载入器 */ Swoole\Loader::setRootNS('Swoole', __DIR__ . '/Swoole'); spl_autoload_register('\\Swoole\\Loader::autoload'); /** * 产生类库的全局变量 */ global $php; $php = Swoole::getInstance(); /** *函数的命名空间 */ function import_func($space_name) { if ($space_name[0] == '@') { $func_file = WEBPATH . '/class/' . substr($space_name, 1) . '.func.php'; } else { $func_file = LIBPATH . '/function/' . $space_name . '.php';