From b454adeef54ea1e0c0b24ca6d3488d217fc520f9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 22 Jun 2016 14:54:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BLoader=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=20=E6=94=AF=E6=8C=81=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=AF=B9=E5=BA=94=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E8=B7=AF=E5=BE=84=20=E5=85=BC=E5=AE=B9composer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Loader.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/library/think/Loader.php b/library/think/Loader.php index a94da475..6149751c 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -76,8 +76,17 @@ class Loader } else { return false; } - $filename = $path . str_replace('\\', DS, $class) . EXT; - if (is_file($filename)) { + // 定位文件 + $match = false; + foreach ((array) $path as $p) { + $filename = $p . str_replace('\\', DS, $class) . EXT; + if (is_file($filename)) { + $match = true; + break; + } + } + + if ($match) { // 开启调试模式Win环境严格区分大小写 if (IS_WIN && false === strpos(realpath($filename), $class . EXT)) { return false; @@ -87,7 +96,6 @@ class Loader return false; } } - return true; } // 注册classmap @@ -143,12 +151,13 @@ class Loader // 读取Composer自动加载文件 $autoload = include VENDOR_PATH . 'think_autoload.php'; if (is_array($autoload)) { - self::addClassMap($autoload); - } - } elseif (is_file(RUNTIME_PATH . 'autoload_composer.php')) { - $autoload = include RUNTIME_PATH . 'autoload_composer.php'; - if (is_array($autoload)) { - self::addNamespace($autoload); + // 命名空间和类库映射注册 + self::addNamespace($autoload['namespace']); + self::addClassMap($autoload['classmap']); + // 载入composer包的文件列表 + foreach ($autoload['files'] as $file) { + include $file; + } } } elseif (AUTO_SCAN_PACKAGE && is_dir(VENDOR_PATH)) { self::scanComposerPackage(VENDOR_PATH);