From 90d7ec19e47b9fa1b4095aacd1d10c6097db4c62 Mon Sep 17 00:00:00 2001 From: ThinkPHP Date: Tue, 30 Apr 2013 11:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BLoader=E7=B1=BB=E7=9A=84autol?= =?UTF-8?q?oad=E6=96=B9=E6=B3=95=20LIB=5FPATH=E7=9B=AE=E5=BD=95=E4=B8=8B?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E6=B3=A8=E5=86=8C=20=E8=87=AA=E5=8A=A8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Think/Loader.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Library/Think/Loader.php b/Library/Think/Loader.php index 93fb86e6..fd4e2012 100644 --- a/Library/Think/Loader.php +++ b/Library/Think/Loader.php @@ -16,11 +16,7 @@ class Loader { // 类名映射 static protected $map = []; // 命名空间 - static protected $namespace = [ - 'Think' => CORE_PATH, - 'Vendor' => VENDOR_PATH, - 'Org' => ORG_PATH, - ]; + static protected $namespace = []; // 自动加载 static public function autoload($class){ @@ -29,7 +25,14 @@ class Loader { include self::$map[$class]; }else{ // 命名空间自动加载 $name = strstr($class, '\\', true); - $path = isset(self::$namespace[$name]) ? dirname(self::$namespace[$name]) . '/' : APP_PATH; + if(isset(self::$namespace[$name])){ // 注册的命名空间 + $path = dirname(self::$namespace[$name]) . '/'; + }elseif(is_dir(LIB_PATH.$name)){ // Library目录下面的命名空间自动定位 + $path = LIB_PATH; + }else{ // 项目命名空间 + $path = APP_PATH; + } + //$path = isset(self::$namespace[$name]) ? dirname(self::$namespace[$name]) . '/' : APP_PATH; $filename = $path . str_replace('\\', '/', $class) . EXT; if(is_file($filename)) { // Win环境下面严格区分大小写