diff --git a/base.php b/base.php index 64ed27a3..59b265e3 100644 --- a/base.php +++ b/base.php @@ -30,7 +30,6 @@ defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS); defined('APP_NAMESPACE') or define('APP_NAMESPACE', 'app'); defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录 defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀 -defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块 defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀 defined('IS_API') or define('IS_API', false); // 是否API接口 defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', true); // 是否自动运行 diff --git a/convention.php b/convention.php index cfed3f30..d1e1edd9 100644 --- a/convention.php +++ b/convention.php @@ -7,6 +7,8 @@ return [ // 应用模式状态 'app_status' => '', + // 是否支持多模块 + 'app_multi_module' => true, // 注册的根命名空间 'root_namespace' => [], // 扩展配置文件 diff --git a/library/think/App.php b/library/think/App.php index 5dc27bf3..22aa01dc 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -55,7 +55,7 @@ class App $request->langset(Lang::detect()); // 加载系统语言包 Lang::load(THINK_PATH . 'lang' . DS . $request->langset() . EXT); - if (!APP_MULTI_MODULE) { + if (!$config['app_multi_module']) { Lang::load(APP_PATH . 'lang' . DS . $request->langset() . EXT); } } @@ -205,7 +205,7 @@ class App if (is_string($result)) { $result = explode('/', $result); } - if (APP_MULTI_MODULE) { + if ($config['app_multi_module']) { // 多模块部署 $module = strip_tags(strtolower($result[0] ?: $config['default_module'])); $bind = Route::bind('module'); @@ -326,7 +326,7 @@ class App private static function init($module = '') { // 定位模块目录 - $module = ($module && APP_MULTI_MODULE) ? $module . DS : ''; + $module = ($module) ? $module . DS : ''; // 加载初始化文件 if (is_file(APP_PATH . $module . 'init' . EXT)) { diff --git a/library/think/Build.php b/library/think/Build.php index 0f23a113..ed510e39 100644 --- a/library/think/Build.php +++ b/library/think/Build.php @@ -88,7 +88,7 @@ class Build */ public static function module($module = '', $list = []) { - $module = APP_MULTI_MODULE ? $module : ''; + $module = $module ? $module : ''; if (!is_dir(APP_PATH . $module)) { // 创建模块目录 mkdir(APP_PATH . $module); diff --git a/library/think/Loader.php b/library/think/Loader.php index 27ad52f2..6c5cad6a 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -463,6 +463,6 @@ class Loader $array = explode('\\', $name); $class = self::parseName(array_pop($array), 1) . (CLASS_APPEND_SUFFIX || $appendSuffix ? ucfirst($layer) : ''); $path = $array ? implode('\\', $array) . '\\' : ''; - return APP_NAMESPACE . '\\' . (APP_MULTI_MODULE ? $module . '\\' : '') . $layer . '\\' . $path . $class; + return APP_NAMESPACE . '\\' . ($module ? $module . '\\' : '') . $layer . '\\' . $path . $class; } } diff --git a/library/think/Route.php b/library/think/Route.php index 3f8cb56a..96cb3640 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1004,7 +1004,7 @@ class Route if (isset($path)) { if ($reverse) { // 解析模块 - $module = APP_MULTI_MODULE ? array_shift($path) : null; + $module = Config::get('app_multi_module') ? array_shift($path) : null; if ($autoSearch) { // 自动搜索控制器 $dir = APP_PATH . ($module ? $module . DS : '') . 'controller'; @@ -1038,7 +1038,7 @@ class Route } else { $action = array_pop($path); $controller = !empty($path) ? array_pop($path) : null; - $module = APP_MULTI_MODULE && !empty($path) ? array_pop($path) : null; + $module = Config::get('app_multi_module') && !empty($path) ? array_pop($path) : null; $method = Request::instance()->method(); // REST 操作方法支持 if ('[rest]' == $action) { diff --git a/tests/thinkphp/library/think/appTest.php b/tests/thinkphp/library/think/appTest.php index 0f9173ac..b29bd459 100644 --- a/tests/thinkphp/library/think/appTest.php +++ b/tests/thinkphp/library/think/appTest.php @@ -49,8 +49,7 @@ class appTest extends \PHPUnit_Framework_TestCase public function testRun() { Config::set('root_namespace', ['/path/']); - - App::run(Request::instance())->send(); + App::run(Request::create("http://www.example.com"))->send(); $expectOutputString = '