初始化仓库
This commit is contained in:
201
vendor/topthink/think-multi-app/LICENSE
vendored
Normal file
201
vendor/topthink/think-multi-app/LICENSE
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
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.
|
||||
14
vendor/topthink/think-multi-app/README.md
vendored
Normal file
14
vendor/topthink/think-multi-app/README.md
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# think-multi-app
|
||||
|
||||
用于ThinkPHP6+的多应用支持
|
||||
|
||||
## 安装
|
||||
|
||||
~~~
|
||||
composer require topthink/think-multi-app
|
||||
~~~
|
||||
|
||||
## 使用
|
||||
|
||||
用法参考ThinkPHP6完全开发手册[多应用模式](https://www.kancloud.cn/manual/thinkphp6_0/1297876)章节。
|
||||
|
||||
28
vendor/topthink/think-multi-app/composer.json
vendored
Normal file
28
vendor/topthink/think-multi-app/composer.json
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "topthink/think-multi-app",
|
||||
"description": "thinkphp multi app support",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "liu21st",
|
||||
"email": "liu21st@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"topthink/framework": "^6.0|^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"think\\app\\": "src"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"think":{
|
||||
"services":[
|
||||
"think\\app\\Service"
|
||||
]
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
224
vendor/topthink/think-multi-app/src/MultiApp.php
vendored
Normal file
224
vendor/topthink/think-multi-app/src/MultiApp.php
vendored
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace think\app;
|
||||
|
||||
use Closure;
|
||||
use think\App;
|
||||
use think\exception\HttpException;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
|
||||
/**
|
||||
* 多应用模式支持
|
||||
*/
|
||||
class MultiApp
|
||||
{
|
||||
|
||||
/** @var App */
|
||||
protected $app;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多应用解析
|
||||
* @access public
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return Response
|
||||
*/
|
||||
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) {
|
||||
return $next($request);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由目录
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function getRoutePath(): string
|
||||
{
|
||||
return $this->app->getAppPath() . 'route' . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析多应用
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseMultiApp(): bool
|
||||
{
|
||||
$scriptName = $this->getScriptName();
|
||||
$defaultApp = $this->app->config->get('app.default_app') ?: 'index';
|
||||
$appName = $this->app->http->getName();
|
||||
|
||||
if ($appName || ($scriptName && !in_array($scriptName, ['index', 'router', 'think']))) {
|
||||
$appName = $appName ?: $scriptName;
|
||||
$this->app->http->setBind();
|
||||
} else {
|
||||
// 自动多应用识别
|
||||
$this->app->http->setBind(false);
|
||||
$appName = null;
|
||||
|
||||
$bind = $this->app->config->get('app.domain_bind', []);
|
||||
|
||||
if (!empty($bind)) {
|
||||
// 获取当前子域名
|
||||
$subDomain = $this->app->request->subDomain();
|
||||
$domain = $this->app->request->host(true);
|
||||
|
||||
if (isset($bind[$domain])) {
|
||||
$appName = $bind[$domain];
|
||||
$this->app->http->setBind();
|
||||
} elseif (isset($bind[$subDomain])) {
|
||||
$appName = $bind[$subDomain];
|
||||
$this->app->http->setBind();
|
||||
} elseif (isset($bind['*'])) {
|
||||
$appName = $bind['*'];
|
||||
$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;
|
||||
} else {
|
||||
$appName = $map[$name];
|
||||
}
|
||||
} elseif ($name && (false !== array_search($name, $map) || in_array($name, $deny))) {
|
||||
throw new HttpException(404, 'app not exists:' . $name);
|
||||
} elseif ($name && isset($map['*'])) {
|
||||
$appName = $map['*'];
|
||||
} else {
|
||||
$appName = $name ?: $defaultApp;
|
||||
$appPath = $this->app->http->getPath() ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (!is_dir($appPath)) {
|
||||
$express = $this->app->config->get('app.app_express', false);
|
||||
if ($express) {
|
||||
$this->setApp($defaultApp);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($name) {
|
||||
$this->app->request->setRoot('/' . $name);
|
||||
$this->app->request->setPathinfo(strpos($path, '/') ? ltrim(strstr($path, '/'), '/') : '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->setApp($appName ?: $defaultApp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前运行入口名称
|
||||
* @access protected
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
protected function getScriptName(): string
|
||||
{
|
||||
if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
||||
$file = $_SERVER['SCRIPT_FILENAME'];
|
||||
} elseif (isset($_SERVER['argv'][0])) {
|
||||
$file = realpath($_SERVER['argv'][0]);
|
||||
}
|
||||
|
||||
return isset($file) ? pathinfo($file, PATHINFO_FILENAME) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置应用
|
||||
* @param string $appName
|
||||
*/
|
||||
protected function setApp(string $appName): void
|
||||
{
|
||||
$this->app->http->name($appName);
|
||||
|
||||
$appPath = $this->app->http->getPath() ?: $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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载应用文件
|
||||
* @param string $appName 应用名
|
||||
* @return void
|
||||
*/
|
||||
protected function loadApp(string $appName, 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) {
|
||||
$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');
|
||||
}
|
||||
|
||||
// 加载应用默认语言包
|
||||
$this->app->loadLangPack($this->app->lang->defaultLangSet());
|
||||
}
|
||||
|
||||
}
|
||||
32
vendor/topthink/think-multi-app/src/Service.php
vendored
Normal file
32
vendor/topthink/think-multi-app/src/Service.php
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
234
vendor/topthink/think-multi-app/src/Url.php
vendored
Normal file
234
vendor/topthink/think-multi-app/src/Url.php
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace think\app;
|
||||
|
||||
use think\App;
|
||||
use think\Route;
|
||||
use think\route\Url as UrlBuild;
|
||||
|
||||
/**
|
||||
* 路由地址生成
|
||||
*/
|
||||
class Url extends UrlBuild
|
||||
{
|
||||
/**
|
||||
* 直接解析URL地址
|
||||
* @access protected
|
||||
* @param string $url URL
|
||||
* @param string|bool $domain Domain
|
||||
* @return string
|
||||
*/
|
||||
protected function parseUrl(string $url, &$domain): string
|
||||
{
|
||||
$request = $this->app->request;
|
||||
|
||||
if (0 === strpos($url, '/')) {
|
||||
// 直接作为路由地址解析
|
||||
$url = substr($url, 1);
|
||||
} elseif (false !== strpos($url, '\\')) {
|
||||
// 解析到类
|
||||
$url = ltrim(str_replace('\\', '/', $url), '/');
|
||||
} elseif (0 === strpos($url, '@')) {
|
||||
// 解析到控制器
|
||||
$url = substr($url, 1);
|
||||
} elseif ('' === $url) {
|
||||
$url = $request->controller() . '/' . $request->action();
|
||||
if (!$this->app->http->isBind()) {
|
||||
$url = $this->getAppName() . '/' . $url;
|
||||
}
|
||||
} else {
|
||||
// 解析到 应用/控制器/操作
|
||||
$controller = $request->controller();
|
||||
$path = explode('/', $url);
|
||||
$action = array_pop($path);
|
||||
$controller = empty($path) ? $controller : array_pop($path);
|
||||
$app = empty($path) ? $this->getAppName() : array_pop($path);
|
||||
$url = $controller . '/' . $action;
|
||||
$bind = $this->app->config->get('app.domain_bind', []);
|
||||
|
||||
if ($key = array_search($this->app->http->getName(), $bind)) {
|
||||
isset($bind[$_SERVER['SERVER_NAME']]) && $domain = $_SERVER['SERVER_NAME'];
|
||||
|
||||
$domain = is_bool($domain) ? $key : $domain;
|
||||
} elseif (!$this->app->http->isBind()) {
|
||||
$url = $app . '/' . $url;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function build(): string
|
||||
{
|
||||
// 解析URL
|
||||
$url = $this->url;
|
||||
$suffix = $this->suffix;
|
||||
$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);
|
||||
}
|
||||
} elseif (strpos($url, '@') && false === strpos($url, '\\')) {
|
||||
// 解析域名
|
||||
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
|
||||
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;
|
||||
}
|
||||
} 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);
|
||||
$domain = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 路由标识不存在 直接解析
|
||||
$url = $this->parseUrl($url, $domain);
|
||||
|
||||
if (isset($info['query'])) {
|
||||
// 解析地址里面参数 合并到vars
|
||||
parse_str($info['query'], $params);
|
||||
$vars = array_merge($params, $vars);
|
||||
}
|
||||
}
|
||||
|
||||
// 还原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)) {
|
||||
// 添加参数
|
||||
if ($this->route->config('url_common_param')) {
|
||||
$vars = http_build_query($vars);
|
||||
$url .= $suffix . '?' . $vars . $anchor;
|
||||
} else {
|
||||
foreach ($vars as $var => $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;
|
||||
}
|
||||
}
|
||||
180
vendor/topthink/think-multi-app/src/command/Build.php
vendored
Normal file
180
vendor/topthink/think-multi-app/src/command/Build.php
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
|
||||
class Build extends Command
|
||||
{
|
||||
/**
|
||||
* 应用基础目录
|
||||
* @var string
|
||||
*/
|
||||
protected $basePath;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$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'],
|
||||
];
|
||||
}
|
||||
|
||||
$this->buildApp($app, $list);
|
||||
$output->writeln("<info>Successed</info>");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建应用
|
||||
* @access protected
|
||||
* @param string $app 应用名
|
||||
* @param array $list 目录结构
|
||||
* @return void
|
||||
*/
|
||||
protected function buildApp(string $app, array $list = []): void
|
||||
{
|
||||
if (!is_dir($this->basePath . $app)) {
|
||||
// 创建应用目录
|
||||
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) {
|
||||
// 生成子目录
|
||||
foreach ($file as $dir) {
|
||||
$this->checkDirBuild($appPath . $dir);
|
||||
}
|
||||
} elseif ('__file__' == $path) {
|
||||
// 生成(空白)文件
|
||||
foreach ($file as $name) {
|
||||
if (!is_file($appPath . $name)) {
|
||||
file_put_contents($appPath . $name, 'php' == pathinfo($name, PATHINFO_EXTENSION) ? '<?php' . PHP_EOL : '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 生成相关MVC文件
|
||||
foreach ($file as $val) {
|
||||
$val = trim($val);
|
||||
$filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . '.php';
|
||||
$space = $namespace . '\\' . $path;
|
||||
$class = $val;
|
||||
switch ($path) {
|
||||
case 'controller': // 控制器
|
||||
if ($this->app->config->get('route.controller_suffix')) {
|
||||
$filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . 'Controller.php';
|
||||
$class = $val . 'Controller';
|
||||
}
|
||||
$content = "<?php" . PHP_EOL . "namespace {$space};" . PHP_EOL . PHP_EOL . "class {$class}" . PHP_EOL . "{" . PHP_EOL . PHP_EOL . "}";
|
||||
break;
|
||||
case 'model': // 模型
|
||||
$content = "<?php" . PHP_EOL . "namespace {$space};" . PHP_EOL . PHP_EOL . "use think\Model;" . PHP_EOL . PHP_EOL . "class {$class} extends Model" . PHP_EOL . "{" . PHP_EOL . PHP_EOL . "}";
|
||||
break;
|
||||
case 'view': // 视图
|
||||
$filename = $appPath . $path . DIRECTORY_SEPARATOR . $val . '.html';
|
||||
$this->checkDirBuild(dirname($filename));
|
||||
$content = '';
|
||||
break;
|
||||
default:
|
||||
// 其他文件
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建应用的欢迎页面
|
||||
* @access protected
|
||||
* @param string $app 目录
|
||||
* @param string $namespace 类库命名空间
|
||||
* @return void
|
||||
*/
|
||||
protected function buildHello(string $app, string $namespace): void
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建应用的公共文件
|
||||
* @access protected
|
||||
* @param string $app 目录
|
||||
* @return void
|
||||
*/
|
||||
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')) {
|
||||
file_put_contents($appPath . $name . '.php', "<?php" . PHP_EOL . "// 这是系统自动生成的{$name}定义文件" . PHP_EOL . "return [" . PHP_EOL . PHP_EOL . "];" . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
* @access protected
|
||||
* @param string $dirname 目录名称
|
||||
* @return void
|
||||
*/
|
||||
protected function checkDirBuild(string $dirname): void
|
||||
{
|
||||
if (!is_dir($dirname)) {
|
||||
mkdir($dirname, 0755, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
vendor/topthink/think-multi-app/src/command/Clear.php
vendored
Normal file
66
vendor/topthink/think-multi-app/src/command/Clear.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
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')) {
|
||||
$path = $runtimePath . 'log';
|
||||
} 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);
|
||||
}
|
||||
} elseif ('.gitignore' != $file && is_file($path . $file)) {
|
||||
unlink($path . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
vendor/topthink/think-multi-app/src/command/stubs/controller.stub
vendored
Normal file
12
vendor/topthink/think-multi-app/src/command/stubs/controller.stub
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {%app%}\{%layer%};
|
||||
|
||||
class Index{%suffix%}
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return '您好!这是一个[{%name%}]示例应用';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user