处理多应用组件兼容问题

This commit is contained in:
Anyon 2020-07-30 16:12:56 +08:00
parent 5bdb46f766
commit 98f42ed0cd
19 changed files with 141 additions and 625 deletions

View File

@ -27,7 +27,6 @@
"endroid/qr-code": "^1.9",
"topthink/framework": "^6.0",
"topthink/think-view": "^1.0",
"topthink/think-multi-app": "^1.0",
"zoujingli/ip2region": "^1.0",
"zoujingli/think-library": "6.0.*-dev",
"zoujingli/wechat-developer": "^1.2"

60
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "06e0d937a455706ec9c4ca9a8315962b",
"content-hash": "8037e81a3aec4e25e2cb08d241087287",
"packages": [
{
"name": "endroid/qr-code",
@ -689,56 +689,6 @@
"description": "The ThinkPHP6 Helper Package",
"time": "2019-11-08T08:01:10+00:00"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-multi-app.git",
"reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-multi-app/zipball/ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3",
"reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0"
},
"type": "library",
"extra": {
"think": {
"services": [
"think\\app\\Service"
]
}
},
"autoload": {
"psr-4": {
"think\\app\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "thinkphp6 multi app support",
"time": "2020-07-12T13:50:37+00:00"
},
{
"name": "topthink/think-orm",
"version": "v2.0.33",
@ -929,12 +879,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "aae4fe718837428b6eae19b97ab34ca5e0ce529d"
"reference": "845f0e19f58548a241fb42369344ca5b3f221337"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/aae4fe718837428b6eae19b97ab34ca5e0ce529d",
"reference": "aae4fe718837428b6eae19b97ab34ca5e0ce529d",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/845f0e19f58548a241fb42369344ca5b3f221337",
"reference": "845f0e19f58548a241fb42369344ca5b3f221337",
"shasum": "",
"mirrors": [
{
@ -978,7 +928,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2020-07-29T06:09:04+00:00"
"time": "2020-07-30T08:07:27+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -283,6 +283,10 @@ return array(
'think\\admin\\helper\\SaveHelper' => $vendorDir . '/zoujingli/think-library/src/helper/SaveHelper.php',
'think\\admin\\helper\\TokenHelper' => $vendorDir . '/zoujingli/think-library/src/helper/TokenHelper.php',
'think\\admin\\helper\\ValidateHelper' => $vendorDir . '/zoujingli/think-library/src/helper/ValidateHelper.php',
'think\\admin\\multiple\\App' => $vendorDir . '/zoujingli/think-library/src/multiple/App.php',
'think\\admin\\multiple\\Url' => $vendorDir . '/zoujingli/think-library/src/multiple/Url.php',
'think\\admin\\multiple\\command\\Build' => $vendorDir . '/zoujingli/think-library/src/multiple/command/Build.php',
'think\\admin\\multiple\\command\\Clear' => $vendorDir . '/zoujingli/think-library/src/multiple/command/Clear.php',
'think\\admin\\service\\AdminService' => $vendorDir . '/zoujingli/think-library/src/service/AdminService.php',
'think\\admin\\service\\CaptchaService' => $vendorDir . '/zoujingli/think-library/src/service/CaptchaService.php',
'think\\admin\\service\\ExpressService' => $vendorDir . '/zoujingli/think-library/src/service/ExpressService.php',
@ -298,11 +302,6 @@ return array(
'think\\admin\\storage\\AliossStorage' => $vendorDir . '/zoujingli/think-library/src/storage/AliossStorage.php',
'think\\admin\\storage\\LocalStorage' => $vendorDir . '/zoujingli/think-library/src/storage/LocalStorage.php',
'think\\admin\\storage\\QiniuStorage' => $vendorDir . '/zoujingli/think-library/src/storage/QiniuStorage.php',
'think\\app\\MultiApp' => $vendorDir . '/topthink/think-multi-app/src/MultiApp.php',
'think\\app\\Service' => $vendorDir . '/topthink/think-multi-app/src/Service.php',
'think\\app\\Url' => $vendorDir . '/topthink/think-multi-app/src/Url.php',
'think\\app\\command\\Build' => $vendorDir . '/topthink/think-multi-app/src/command/Build.php',
'think\\app\\command\\Clear' => $vendorDir . '/topthink/think-multi-app/src/command/Clear.php',
'think\\cache\\Driver' => $vendorDir . '/topthink/framework/src/think/cache/Driver.php',
'think\\cache\\TagSet' => $vendorDir . '/topthink/framework/src/think/cache/TagSet.php',
'think\\cache\\driver\\File' => $vendorDir . '/topthink/framework/src/think/cache/driver/File.php',

View File

@ -7,7 +7,6 @@ $baseDir = dirname($vendorDir);
return array(
'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),
'think\\admin\\' => array($vendorDir . '/zoujingli/think-library/src'),
'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-template/src'),
'app\\' => array($baseDir . '/app'),

View File

@ -16,7 +16,6 @@ class ComposerStaticInitb911c14a0826c73d9f097343fd33a252
't' =>
array (
'think\\view\\driver\\' => 18,
'think\\app\\' => 10,
'think\\admin\\' => 12,
'think\\' => 6,
),
@ -65,10 +64,6 @@ class ComposerStaticInitb911c14a0826c73d9f097343fd33a252
array (
0 => __DIR__ . '/..' . '/topthink/think-view/src',
),
'think\\app\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-multi-app/src',
),
'think\\admin\\' =>
array (
0 => __DIR__ . '/..' . '/zoujingli/think-library/src',
@ -416,6 +411,10 @@ class ComposerStaticInitb911c14a0826c73d9f097343fd33a252
'think\\admin\\helper\\SaveHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/SaveHelper.php',
'think\\admin\\helper\\TokenHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/TokenHelper.php',
'think\\admin\\helper\\ValidateHelper' => __DIR__ . '/..' . '/zoujingli/think-library/src/helper/ValidateHelper.php',
'think\\admin\\multiple\\App' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/App.php',
'think\\admin\\multiple\\Url' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/Url.php',
'think\\admin\\multiple\\command\\Build' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/command/Build.php',
'think\\admin\\multiple\\command\\Clear' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/command/Clear.php',
'think\\admin\\service\\AdminService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/AdminService.php',
'think\\admin\\service\\CaptchaService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/CaptchaService.php',
'think\\admin\\service\\ExpressService' => __DIR__ . '/..' . '/zoujingli/think-library/src/service/ExpressService.php',
@ -431,11 +430,6 @@ class ComposerStaticInitb911c14a0826c73d9f097343fd33a252
'think\\admin\\storage\\AliossStorage' => __DIR__ . '/..' . '/zoujingli/think-library/src/storage/AliossStorage.php',
'think\\admin\\storage\\LocalStorage' => __DIR__ . '/..' . '/zoujingli/think-library/src/storage/LocalStorage.php',
'think\\admin\\storage\\QiniuStorage' => __DIR__ . '/..' . '/zoujingli/think-library/src/storage/QiniuStorage.php',
'think\\app\\MultiApp' => __DIR__ . '/..' . '/topthink/think-multi-app/src/MultiApp.php',
'think\\app\\Service' => __DIR__ . '/..' . '/topthink/think-multi-app/src/Service.php',
'think\\app\\Url' => __DIR__ . '/..' . '/topthink/think-multi-app/src/Url.php',
'think\\app\\command\\Build' => __DIR__ . '/..' . '/topthink/think-multi-app/src/command/Build.php',
'think\\app\\command\\Clear' => __DIR__ . '/..' . '/topthink/think-multi-app/src/command/Clear.php',
'think\\cache\\Driver' => __DIR__ . '/..' . '/topthink/framework/src/think/cache/Driver.php',
'think\\cache\\TagSet' => __DIR__ . '/..' . '/topthink/framework/src/think/cache/TagSet.php',
'think\\cache\\driver\\File' => __DIR__ . '/..' . '/topthink/framework/src/think/cache/driver/File.php',

View File

@ -704,58 +704,6 @@
],
"description": "The ThinkPHP6 Helper Package"
},
{
"name": "topthink/think-multi-app",
"version": "v1.0.14",
"version_normalized": "1.0.14.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-multi-app.git",
"reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-multi-app/zipball/ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3",
"reference": "ccaad7c2d33f42cb1cc2a78d6610aaec02cea4c3",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0"
},
"time": "2020-07-12T13:50:37+00:00",
"type": "library",
"extra": {
"think": {
"services": [
"think\\app\\Service"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"think\\app\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "thinkphp6 multi app support"
},
{
"name": "topthink/think-orm",
"version": "v2.0.33",
@ -955,12 +903,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "aae4fe718837428b6eae19b97ab34ca5e0ce529d"
"reference": "845f0e19f58548a241fb42369344ca5b3f221337"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/aae4fe718837428b6eae19b97ab34ca5e0ce529d",
"reference": "aae4fe718837428b6eae19b97ab34ca5e0ce529d",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/845f0e19f58548a241fb42369344ca5b3f221337",
"reference": "845f0e19f58548a241fb42369344ca5b3f221337",
"shasum": "",
"mirrors": [
{
@ -976,7 +924,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2020-07-29T06:09:04+00:00",
"time": "2020-07-30T08:07:27+00:00",
"type": "library",
"extra": {
"think": {

5
vendor/services.php vendored
View File

@ -1,7 +1,6 @@
<?php
// This file is automatically generated at:2020-07-29 15:30:40
// This file is automatically generated at:2020-07-30 16:11:54
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',
1 => 'think\\admin\\Library',
0 => 'think\\admin\\Library',
);

View File

@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,14 +0,0 @@
# think-multi-app
用于ThinkPHP6+的多应用支持
## 安装
~~~
composer require topthink/think-multi-app
~~~
## 使用
用法参考ThinkPHP6完全开发手册[多应用模式](https://www.kancloud.cn/manual/thinkphp6_0/1297876)章节。

View File

@ -1,28 +0,0 @@
{
"name": "topthink/think-multi-app",
"description": "thinkphp6 multi app support",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0"
},
"autoload": {
"psr-4": {
"think\\app\\": "src"
}
},
"extra": {
"think":{
"services":[
"think\\app\\Service"
]
}
},
"minimum-stability": "dev"
}

View File

@ -1,32 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\app;
use think\Service as BaseService;
class Service extends BaseService
{
public function boot()
{
$this->app->event->listen('HttpRun', function () {
$this->app->middleware->add(MultiApp::class);
});
$this->commands([
'build' => command\Build::class,
'clear' => command\Clear::class,
]);
$this->app->bind([
'think\route\Url' => Url::class,
]);
}
}

View File

@ -2,7 +2,7 @@
"type": "library",
"name": "zoujingli/think-library",
"license": "MIT",
"homepage": "http://framework.thinkadmin.top",
"homepage": "http://thinkadmin.top",
"description": "ThinkPHP v6.0 Development Library",
"authors": [
{

View File

@ -15,8 +15,16 @@
namespace think\admin;
use think\admin\command\Database;
use think\admin\command\Install;
use think\admin\command\Version;
use think\admin\multiple\App;
use think\admin\multiple\command\Build;
use think\admin\multiple\command\Clear;
use think\admin\multiple\Url;
use think\admin\service\AdminService;
use think\admin\service\SystemService;
use think\middleware\LoadLangPack;
use think\middleware\SessionInit;
use think\Request;
use think\Service;
@ -34,15 +42,18 @@ class Library extends Service
*/
public function boot()
{
// 多应用中间键
$this->app->event->listen('HttpRun', function () {
$this->app->middleware->add(App::class);
});
// 替换 ThinkPHP 指令
$this->commands(['build' => Build::class, 'clear' => Clear::class]);
// 注册 ThinkAdmin 指令
$this->commands([Queue::class, Install::class, Version::class, Database::class]);
// 动态绑定运行配置
$this->app->bind('think\route\Url', Url::class);
// 动态应用配置参数
SystemService::instance()->bindRuntime();
// 注册系统任务指令
$this->commands([
'think\admin\command\Queue',
'think\admin\command\Install',
'think\admin\command\Version',
'think\admin\command\Database',
]);
}
/**
@ -61,6 +72,8 @@ class Library extends Service
$this->app->request->setPathinfo($_SERVER['argv'][1]);
}
} else {
// 注册语言包处理中间键
$this->app->middleware->add(LoadLangPack::class);
// 注册会话初始化中间键
if ($this->app->request->request('not_init_session', 0) == 0) {
$this->app->middleware->add(SessionInit::class);
@ -87,7 +100,7 @@ class Library extends Service
}, 'route');
}
// 动态加入应用函数
$sysRule = "{$this->app->getBasePath()}*/sys.php";
foreach (glob($sysRule) as $file) includeFile($file);
$SysRule = "{$this->app->getBasePath()}*/sys.php";
foreach (glob($SysRule) as $file) includeFile($file);
}
}

View File

@ -1,4 +1,6 @@
<?php
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
@ -8,23 +10,24 @@
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\app;
namespace think\admin\multiple;
use Closure;
use think\App;
use think\exception\HttpException;
use think\Request;
use think\Response;
/**
* 多应用模式支持
* 多应用支持
* Class MultiApp
* @package think\admin\multiple
*/
class MultiApp
class App
{
/** @var App */
/**
* @var \think\App
*/
protected $app;
/**
@ -33,19 +36,17 @@ class MultiApp
*/
protected $name;
/**
* 应用名称
* @var string
*/
protected $appName;
/**
* 应用路径
* @var string
*/
protected $path;
public function __construct(App $app)
/**
* App constructor.
* @param \think\App $app
*/
public function __construct(\think\App $app)
{
$this->app = $app;
$this->name = $this->app->http->getName();
@ -61,13 +62,8 @@ class MultiApp
*/
public function handle($request, Closure $next)
{
if (!$this->parseMultiApp()) {
return $next($request);
}
return $this->app->middleware->pipeline('app')
->send($request)
->then(function ($request) use ($next) {
if (!$this->parseMultiApp()) return $next($request);
return $this->app->middleware->pipeline('app')->send($request)->then(function ($request) use ($next) {
return $next($request);
});
}
@ -90,7 +86,6 @@ class MultiApp
{
$scriptName = $this->getScriptName();
$defaultApp = $this->app->config->get('app.default_app') ?: 'index';
if ($this->name || ($scriptName && !in_array($scriptName, ['index', 'router', 'think']))) {
$appName = $this->name ?: $scriptName;
$this->app->http->setBind();
@ -98,15 +93,10 @@ class MultiApp
// 自动多应用识别
$this->app->http->setBind(false);
$appName = null;
$this->appName = '';
$bind = $this->app->config->get('app.domain_bind', []);
if (!empty($bind)) {
// 获取当前子域名
$subDomain = $this->app->request->subDomain();
$domain = $this->app->request->host(true);
$subDomain = $this->app->request->subDomain();
if (isset($bind[$domain])) {
$appName = $bind[$domain];
$this->app->http->setBind();
@ -118,21 +108,17 @@ class MultiApp
$this->app->http->setBind();
}
}
if (!$this->app->http->isBind()) {
$path = $this->app->request->pathinfo();
$map = $this->app->config->get('app.app_map', []);
$deny = $this->app->config->get('app.deny_app_list', []);
$name = current(explode('/', $path));
if (strpos($name, '.')) {
$name = strstr($name, '.', true);
}
if (isset($map[$name])) {
if ($map[$name] instanceof Closure) {
$result = call_user_func_array($map[$name], [$this->app]);
$appName = $result ?: $name;
$appName = call_user_func_array($map[$name], [$this->app]) ?: $name;
} else {
$appName = $map[$name];
}
@ -143,7 +129,6 @@ class MultiApp
} else {
$appName = $name ?: $defaultApp;
$appPath = $this->path ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR;
if (!is_dir($appPath)) {
$express = $this->app->config->get('app.app_express', false);
if ($express) {
@ -154,14 +139,12 @@ class MultiApp
}
}
}
if ($name) {
$this->app->request->setRoot('/' . $name);
$this->app->request->setPathinfo(strpos($path, '/') ? ltrim(strstr($path, '/'), '/') : '');
}
}
}
$this->setApp($appName ?: $defaultApp);
return true;
}
@ -179,7 +162,6 @@ class MultiApp
} elseif (isset($_SERVER['argv'][0])) {
$file = realpath($_SERVER['argv'][0]);
}
return isset($file) ? pathinfo($file, PATHINFO_FILENAME) : '';
}
@ -189,57 +171,33 @@ class MultiApp
*/
protected function setApp(string $appName): void
{
$this->appName = $appName;
$this->app->http->name($appName);
$appPath = $this->path ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR;
$this->app->setAppPath($appPath);
// 设置应用命名空间
$this->app->setNamespace($this->app->config->get('app.app_namespace') ?: 'app\\' . $appName);
if (is_dir($appPath)) {
$this->app->setRuntimePath($this->app->getRuntimePath() . $appName . DIRECTORY_SEPARATOR);
$this->app->http->setRoutePath($this->getRoutePath());
//加载应用
$this->loadApp($appName, $appPath);
$this->loadApp($appPath);
}
}
/**
* 加载应用文件
* @param string $appName 应用名
* @param string $appPath
* @return void
*/
protected function loadApp(string $appName, string $appPath): void
protected function loadApp(string $appPath): void
{
if (is_file($appPath . 'common.php')) {
include_once $appPath . 'common.php';
}
$files = [];
$files = array_merge($files, glob($appPath . 'config' . DIRECTORY_SEPARATOR . '*' . $this->app->getConfigExt()));
foreach ($files as $file) {
if (is_file($appPath . 'common.php')) \Composer\Autoload\includeFile($appPath . 'common.php');
foreach (glob($appPath . 'config' . DIRECTORY_SEPARATOR . '*' . $this->app->getConfigExt()) as $file) {
$this->app->config->load($file, pathinfo($file, PATHINFO_FILENAME));
}
if (is_file($appPath . 'event.php')) {
$this->app->loadEvent(include $appPath . 'event.php');
}
if (is_file($appPath . 'middleware.php')) {
$this->app->middleware->import(include $appPath . 'middleware.php', 'app');
}
if (is_file($appPath . 'provider.php')) {
$this->app->bind(include $appPath . 'provider.php');
}
if (is_file($appPath . 'event.php')) $this->app->loadEvent(include $appPath . 'event.php');
if (is_file($appPath . 'provider.php')) $this->app->bind(include $appPath . 'provider.php');
if (is_file($appPath . 'middleware.php')) $this->app->middleware->import(include $appPath . 'middleware.php', 'app');
// 加载应用默认语言包
$this->app->loadLangPack($this->app->lang->defaultLangSet());
}
}

View File

@ -1,4 +1,6 @@
<?php
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
@ -8,18 +10,15 @@
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\app;
use think\App;
use think\Route;
use think\route\Url as UrlBuild;
namespace think\admin\multiple;
/**
* 路由地址生成
* 多应用URL生成与解析
* Class Url
* @package think\admin\multiple
*/
class Url extends UrlBuild
class Url extends \think\route\Url
{
/**
* 直接解析URL地址
@ -31,7 +30,6 @@ class Url extends UrlBuild
protected function parseUrl(string $url, &$domain): string
{
$request = $this->app->request;
if (0 === strpos($url, '/')) {
// 直接作为路由地址解析
$url = substr($url, 1);
@ -42,27 +40,29 @@ class Url extends UrlBuild
// 解析到控制器
$url = substr($url, 1);
} elseif ('' === $url) {
$url = $this->getAppName() . '/' . $request->controller() . '/' . $request->action();
$url = $this->app->http->getName() . '/' . $request->controller() . '/' . $request->action();
} else {
// 解析到 应用/控制器/操作
$controller = $request->controller();
$app = $this->getAppName();
$app = $this->app->http->getName();
$path = explode('/', $url);
$action = array_pop($path);
$controller = empty($path) ? $controller : array_pop($path);
$app = empty($path) ? $app : array_pop($path);
$url = $controller . '/' . $action;
$bind = $this->app->config->get('app.domain_bind', []);
if ($key = array_search($this->app->http->getName(), $bind)) {
if ($key = array_search($app, $bind)) {
isset($bind[$_SERVER['SERVER_NAME']]) && $domain = $_SERVER['SERVER_NAME'];
$domain = is_bool($domain) ? $key : $domain;
} else {
$map = $this->app->config->get('app.app_map', []);
if ($key = array_search($app, $map)) {
$url = $key . '/' . $url;
} else {
$url = $app . '/' . $url;
}
}
}
return $url;
}
@ -74,26 +74,21 @@ class Url extends UrlBuild
$domain = $this->domain;
$request = $this->app->request;
$vars = $this->vars;
if (0 === strpos($url, '[') && $pos = strpos($url, ']')) {
// [name] 表示使用路由命名标识生成URL
$name = substr($url, 1, $pos - 1);
$url = 'name' . substr($url, $pos + 1);
}
if (false === strpos($url, '://') && 0 !== strpos($url, '/')) {
$info = parse_url($url);
$url = !empty($info['path']) ? $info['path'] : '';
if (isset($info['fragment'])) {
// 解析锚点
$anchor = $info['fragment'];
if (false !== strpos($anchor, '?')) {
// 解析参数
list($anchor, $info['query']) = explode('?', $anchor, 2);
}
if (false !== strpos($anchor, '@')) {
// 解析域名
list($anchor, $domain) = explode('@', $anchor, 2);
@ -103,49 +98,39 @@ class Url extends UrlBuild
list($url, $domain) = explode('@', $url, 2);
}
}
if ($url) {
$checkName = isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : '');
$checkDomain = $domain && is_string($domain) ? $domain : null;
$rule = $this->route->getName($checkName, $checkDomain);
if (empty($rule) && isset($info['query'])) {
$rule = $this->route->getName($url, $checkDomain);
// 解析地址里面参数 合并到vars
// 解析地址里面参数 合并到 vars
parse_str($info['query'], $params);
$vars = array_merge($params, $vars);
unset($info['query']);
}
}
if (!empty($rule) && $match = $this->getRuleUrl($rule, $vars, $domain)) {
// 匹配路由命名标识
$url = $match[0];
if ($domain && !empty($match[1])) {
$domain = $match[1];
}
if (!is_null($match[2])) {
$suffix = $match[2];
}
if (!$this->app->http->isBind()) {
$app = $this->getAppName();
$url = $app . '/' . $url;
$url = $this->app->http->getName() . '/' . $url;
}
} elseif (!empty($rule) && isset($name)) {
throw new \InvalidArgumentException('route name not exists:' . $name);
} else {
// 检测URL绑定
$bind = $this->route->getDomainBind($domain && is_string($domain) ? $domain : null);
if ($bind && 0 === strpos($url, $bind)) {
$url = substr($url, strlen($bind) + 1);
} else {
$binds = $this->route->getBind();
foreach ($binds as $key => $val) {
if (is_string($val) && 0 === strpos($url, $val) && substr_count($val, '/') > 1) {
$url = substr($url, strlen($val) + 1);
@ -154,38 +139,30 @@ class Url extends UrlBuild
}
}
}
// 路由标识不存在 直接解析
$url = $this->parseUrl($url, $domain);
if (isset($info['query'])) {
// 解析地址里面参数 合并到vars
parse_str($info['query'], $params);
$vars = array_merge($params, $vars);
}
}
// 还原URL分隔符
// 还原 URL 分隔符
$depr = $this->route->config('pathinfo_depr');
$url = str_replace('/', $depr, $url);
$file = $request->baseFile();
if ($file && 0 !== strpos($request->url(), $file)) {
$file = str_replace('\\', '/', dirname($file));
}
$url = rtrim($file, '/') . '/' . ltrim($url, '/');
// URL后缀
if ('/' == substr($url, -1) || '' == $url) {
$suffix = '';
} else {
$suffix = $this->parseSuffix($suffix);
}
// 锚点
$anchor = !empty($anchor) ? '#' . $anchor : '';
// 参数组装
if (!empty($vars)) {
// 添加参数
@ -194,39 +171,19 @@ class Url extends UrlBuild
$url .= $suffix . '?' . $vars . $anchor;
} else {
foreach ($vars as $var => $val) {
$val = (string) $val;
$val = (string)$val;
if ('' !== $val) {
$url .= $depr . $var . $depr . urlencode($val);
}
}
$url .= $suffix . $anchor;
}
} else {
$url .= $suffix . $anchor;
}
// 检测域名
$domain = $this->parseDomain($url, $domain);
// URL组装
return $domain . rtrim($this->root, '/') . '/' . ltrim($url, '/');
}
/**
* 获取URL的应用名
* @access protected
* @return string
*/
protected function getAppName()
{
$app = $this->app->http->getName();
$map = $this->app->config->get('app.app_map', []);
if ($key = array_search($app, $map)) {
$app = $key;
}
return $app;
}
}

View File

@ -1,4 +1,5 @@
<?php
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
@ -9,7 +10,7 @@
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\app\command;
namespace think\admin\multiple\command;
use think\console\Command;
use think\console\Input;
@ -24,32 +25,22 @@ class Build extends Command
*/
protected $basePath;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('build')
->addArgument('app', Argument::OPTIONAL, 'app name .')
->setDescription('Build App Dirs');
$this->setName('build')->addArgument('app', Argument::OPTIONAL, 'app name .')->setDescription('Build App Dirs');
}
protected function execute(Input $input, Output $output)
{
$this->basePath = $this->app->getBasePath();
$app = $input->getArgument('app') ?: '';
if (is_file($this->basePath . 'build.php')) {
$list = include $this->basePath . 'build.php';
} else {
$list = [
'__dir__' => ['controller', 'model', 'view'],
];
$list = ['__dir__' => ['controller', 'model', 'view']];
}
$this->buildApp($app, $list);
$output->writeln("<info>Successed</info>");
}
/**
@ -65,15 +56,12 @@ class Build extends Command
// 创建应用目录
mkdir($this->basePath . $app);
}
$appPath = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : '');
$namespace = 'app' . ($app ? '\\' . $app : '');
// 创建配置文件和公共文件
$this->buildCommon($app);
// 创建模块的默认页面
$this->buildHello($app, $namespace);
foreach ($list as $path => $file) {
if ('__dir__' == $path) {
// 生成子目录
@ -114,7 +102,6 @@ class Build extends Command
// 其他文件
$content = "<?php" . PHP_EOL . "namespace {$space};" . PHP_EOL . PHP_EOL . "class {$class}" . PHP_EOL . "{" . PHP_EOL . PHP_EOL . "}";
}
if (!is_file($filename)) {
file_put_contents($filename, $content);
}
@ -134,12 +121,10 @@ class Build extends Command
{
$suffix = $this->app->config->get('route.controller_suffix') ? 'Controller' : '';
$filename = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : '') . 'controller' . DIRECTORY_SEPARATOR . 'Index' . $suffix . '.php';
if (!is_file($filename)) {
$content = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'controller.stub');
$content = str_replace(['{%name%}', '{%app%}', '{%layer%}', '{%suffix%}'], [$app, $namespace, 'controller', $suffix], $content);
$this->checkDirBuild(dirname($filename));
file_put_contents($filename, $content);
}
}
@ -153,17 +138,13 @@ class Build extends Command
protected function buildCommon(string $app): void
{
$appPath = $this->basePath . ($app ? $app . DIRECTORY_SEPARATOR : '');
if (!is_file($appPath . 'common.php')) {
file_put_contents($appPath . 'common.php', "<?php" . PHP_EOL . "// 这是系统自动生成的公共文件" . PHP_EOL);
}
foreach (['event', 'middleware', 'common'] as $name) {
if (!is_file($appPath . $name . '.php')) {
foreach (['event', 'middleware', 'common'] as $name) if (!is_file($appPath . $name . '.php')) {
file_put_contents($appPath . $name . '.php', "<?php" . PHP_EOL . "// 这是系统自动生成的{$name}定义文件" . PHP_EOL . "return [" . PHP_EOL . PHP_EOL . "];" . PHP_EOL);
}
}
}
/**
* 创建目录

View File

@ -1,4 +1,5 @@
<?php
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
@ -8,7 +9,8 @@
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\app\command;
namespace think\admin\multiple\command;
use think\console\Command;
use think\console\Input;
@ -20,20 +22,17 @@ class Clear extends Command
{
protected function configure()
{
// 指令配置
$this->setName('clear')
->addArgument('app', Argument::OPTIONAL, 'app name .')
->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file')
->addOption('log', 'l', Option::VALUE_NONE, 'clear log file')
->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir')
->setDescription('Clear runtime file');
$this->setName('clear')->addArgument('app', Argument::OPTIONAL, 'app name .');
$this->addOption('cache', 'c', Option::VALUE_NONE, 'clear cache file');
$this->addOption('log', 'l', Option::VALUE_NONE, 'clear log file');
$this->addOption('dir', 'r', Option::VALUE_NONE, 'clear empty dir');
$this->setDescription('Clear runtime file');
}
protected function execute(Input $input, Output $output)
{
$app = $input->getArgument('app') ?: '';
$runtimePath = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . ($app ? $app . DIRECTORY_SEPARATOR : '');
if ($input->getOption('cache')) {
$path = $runtimePath . 'cache';
} elseif ($input->getOption('log')) {
@ -41,23 +40,18 @@ class Clear extends Command
} else {
$path = $runtimePath;
}
$rmdir = $input->getOption('dir') ? true : false;
$this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir);
$output->writeln("<info>Clear Successed</info>");
}
protected function clear(string $path, bool $rmdir): void
{
$files = is_dir($path) ? scandir($path) : [];
foreach ($files as $file) {
if ('.' != $file && '..' != $file && is_dir($path . $file)) {
array_map('unlink', glob($path . $file . DIRECTORY_SEPARATOR . '*.*'));
if ($rmdir) {
rmdir($path . $file);
}
if ($rmdir) rmdir($path . $file);
} elseif ('.gitignore' != $file && is_file($path . $file)) {
unlink($path . $file);
}

View File

@ -170,7 +170,7 @@ class QueueService extends Service
return $this->progress($status, $message, $progress);
}
if (is_numeric($status)) $data['status'] = intval($status);
if (is_numeric($progress)) $progress = str_pad(sprintf("%.2f", $progress), 6, "0", STR_PAD_LEFT);
if (is_numeric($progress)) $progress = str_pad(sprintf("%.2f", $progress), 6, '0', STR_PAD_LEFT);
if (is_string($message) && is_null($progress)) {
$data['message'] = $message;
$data['history'][] = ['message' => $message, 'progress' => $data['progress'], 'datetime' => date('Y-m-d H:i:s')];