mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
APP_MULTI_MODULE常量改为app_multi_module配置参数
This commit is contained in:
1
base.php
1
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); // 是否自动运行
|
||||
|
||||
@@ -7,6 +7,8 @@ return [
|
||||
|
||||
// 应用模式状态
|
||||
'app_status' => '',
|
||||
// 是否支持多模块
|
||||
'app_multi_module' => true,
|
||||
// 注册的根命名空间
|
||||
'root_namespace' => [],
|
||||
// 扩展配置文件
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 = '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
|
||||
$this->expectOutputString($expectOutputString);
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user