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 = '

:)

ThinkPHP V5
十年磨一剑 - 为API开发设计的高性能框架

[ V5.0 版本由 七牛云 独家赞助发布 ]
'; $this->expectOutputString($expectOutputString); diff --git a/tests/thinkphp/library/think/routeTest.php b/tests/thinkphp/library/think/routeTest.php index 5c9e5dd4..0b0314c2 100644 --- a/tests/thinkphp/library/think/routeTest.php +++ b/tests/thinkphp/library/think/routeTest.php @@ -168,29 +168,28 @@ class routeTest extends \PHPUnit_Framework_TestCase public function testDomain() { - $_SERVER['HTTP_HOST'] = 'subdomain.thinkphp.cn'; - $_SERVER['REQUEST_URI'] = ''; + $request = Request::create('http://subdomain.thinkphp.cn'); Route::domain('subdomain.thinkphp.cn', 'sub?abc=test&status=1'); - Route::checkDomain(); + Route::checkDomain($request); $this->assertEquals('sub?abc=test&status=1', Route::domain('subdomain.thinkphp.cn')); $this->assertEquals('sub', Route::bind('module')); $this->assertEquals('test', $_GET['abc']); $this->assertEquals(1, $_GET['status']); Route::domain('subdomain.thinkphp.cn', function () {return ['type' => 'module', 'module' => 'sub2'];}); - Route::checkDomain(); + Route::checkDomain($request); $this->assertEquals('sub2', Route::bind('module')); Route::domain('subdomain.thinkphp.cn', '\app\index\controller'); - Route::checkDomain(); + Route::checkDomain($request); $this->assertEquals('\app\index\controller', Route::bind('namespace')); Route::domain('subdomain.thinkphp.cn', '@\app\index\controller\blog'); - Route::checkDomain(); + Route::checkDomain($request); $this->assertEquals('\app\index\controller\blog', Route::bind('class')); Route::domain('subdomain.thinkphp.cn', '[sub3]'); - Route::checkDomain(); + Route::checkDomain($request); $this->assertEquals('sub3', Route::bind('group')); } } diff --git a/tests/thinkphp/library/think/urlTest.php b/tests/thinkphp/library/think/urlTest.php index a82c0936..96fa0788 100644 --- a/tests/thinkphp/library/think/urlTest.php +++ b/tests/thinkphp/library/think/urlTest.php @@ -29,6 +29,7 @@ class urlTest extends \PHPUnit_Framework_TestCase Route::get('blog/:name', 'index/blog'); Route::get('blog/:id', 'index/blog'); Config::set('pathinfo_depr', '/'); + Config::set('url_html_suffix', ''); $this->assertEquals('/blog/thinkphp', Url::build('index/blog?name=thinkphp')); $this->assertEquals('/blog/thinkphp.html', Url::build('index/blog', 'name=thinkphp', 'html')); $this->assertEquals('/blog/10', Url::build('index/blog?id=10')); @@ -41,6 +42,7 @@ class urlTest extends \PHPUnit_Framework_TestCase public function testBuildController() { + Config::set('url_html_suffix', ''); Route::get('blog/:id', '@index/blog/read'); $this->assertEquals('/blog/10.html', Url::build('@index/blog/read', 'id=10', 'html'));