/** * 将路径信息注册到命名空间,该方法不会覆盖已经定义过的命名空间 * * @param string $path * 需要注册的路径 * @param string $name * 路径别名 * @param boolean $includePath * | 是否同时定义includePath * @param boolean $reset * | 是否覆盖已经存在的定义,默认false * @return void * @throws Exception */ public static function register($path, $alias = '', $includePath = false, $reset = false) { if (!$path) { return; } if (!empty($alias)) { $alias = strtolower($alias); if (!isset(self::$_namespace[$alias]) || $reset) { self::$_namespace[$alias] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR; } } if ($includePath) { if (empty(self::$_includePaths)) { self::$_includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path())); if (($pos = array_search('.', self::$_includePaths, true)) !== false) { unset(self::$_includePaths[$pos]); } } array_unshift(self::$_includePaths, $path); if (set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$_includePaths)) === false) { throw new Exception('[Wind.register] set include path error.'); } } }