ComposerUpdate

This commit is contained in:
邹景立 2021-05-18 14:32:53 +08:00
parent 2cd5337551
commit d07cc95740
20 changed files with 89 additions and 191 deletions

View File

@ -337,7 +337,6 @@ return array(
'think\\admin\\multiple\\BuildUrl' => $vendorDir . '/zoujingli/think-library/src/multiple/BuildUrl.php',
'think\\admin\\multiple\\Multiple' => $vendorDir . '/zoujingli/think-library/src/multiple/Multiple.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',

View File

@ -466,7 +466,6 @@ class ComposerStaticInit0ec6378467f464339c264d61cf644c03
'think\\admin\\multiple\\BuildUrl' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/BuildUrl.php',
'think\\admin\\multiple\\Multiple' => __DIR__ . '/..' . '/zoujingli/think-library/src/multiple/Multiple.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',

View File

@ -834,12 +834,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "72156b3cbcccb0be17fc6706de094e9f12a20f74"
"reference": "e2c63ede57564e638e54bbca483d307b639b114a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/72156b3cbcccb0be17fc6706de094e9f12a20f74",
"reference": "72156b3cbcccb0be17fc6706de094e9f12a20f74",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/e2c63ede57564e638e54bbca483d307b639b114a",
"reference": "e2c63ede57564e638e54bbca483d307b639b114a",
"shasum": "",
"mirrors": [
{
@ -856,7 +856,7 @@
"ext-mbstring": "*",
"topthink/framework": "^6.0"
},
"time": "2021-05-17T11:05:01+00:00",
"time": "2021-05-18T06:14:56+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2021-05-18 14:20:28
// This file is automatically generated at:2021-05-18 14:32:42
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

View File

@ -81,6 +81,7 @@ abstract class Command extends \think\console\Command
$this->queue->error($message);
} elseif (is_string($message)) {
$this->output->writeln($message);
exit("\r\n");
}
return $this;
}
@ -97,6 +98,7 @@ abstract class Command extends \think\console\Command
$this->queue->success($message);
} elseif (is_string($message)) {
$this->output->writeln($message);
exit("\r\n");
}
return $this;
}

View File

@ -78,7 +78,6 @@ abstract class Controller extends stdClass
if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.');
}
$this->csrf_message = lang('think_library_csrf_error');
$this->initialize();
}

View File

@ -60,7 +60,7 @@ abstract class Helper
/**
* 获取数据库对象
* @param string|Query $dbQuery
* @param string|Db|Query $dbQuery
* @return Db|Query
*/
protected function buildQuery($dbQuery)

View File

@ -70,7 +70,7 @@ class Library extends Service
// 替换 ThinkPHP 地址
$this->app->bind('think\route\Url', BuildUrl::class);
// 替换 ThinkPHP 指令
$this->commands(['build' => Build::class, 'clear' => Clear::class]);
$this->commands(['build' => Build::class]);
// 注册 ThinkAdmin 指令
$this->commands([Queue::class, Install::class, Version::class, Database::class, Replace::class]);
// 动态应用运行参数
@ -120,10 +120,5 @@ class Library extends Service
// 动态加载应用初始化系统函数
[$ds, $base] = [DIRECTORY_SEPARATOR, $this->app->getBasePath()];
foreach (glob("{$base}*{$ds}sys.php") as $file) includeFile($file);
// 动态加载插件初始化系统函数
$base = "{$this->app->getBasePath()}addons{$ds}";
if (file_exists($base) && is_dir($base)) {
foreach (glob("{$base}*{$ds}sys.php") as $file) includeFile($file);
}
}
}

View File

@ -62,16 +62,13 @@ abstract class Queue
abstract public function execute(array $data = []);
/**
* 设置任务的进度
* @param null|string $message 进度消息
* @param null|string $progress 进度数值
* @param integer $backline 回退行数
* @return Queue
* 设置失败的消息
* @param string $message 消息内容
* @throws Exception
*/
protected function setQueueProgress(?string $message = null, ?string $progress = null, int $backline = 0): Queue
protected function setQueueError(string $message): void
{
$this->queue->progress(2, $message, $progress, $backline);
return $this;
$this->queue->error($message);
}
/**
@ -85,12 +82,29 @@ abstract class Queue
}
/**
* 设置失败的消息
* @param string $message 消息内容
* @throws Exception
* 更新任务进度
* @param integer $total 记录总和
* @param integer $count 当前记录
* @param string $message 文字描述
* @param integer $backline 回退行数
* @return static
*/
protected function setQueueError(string $message): void
protected function setQueueMessage(int $total, int $count, string $message = '', int $backline = 0): Queue
{
$this->queue->error($message);
$this->queue->message($total, $count, $message, $backline);
return $this;
}
/**
* 设置任务的进度
* @param null|string $message 进度消息
* @param null|string $progress 进度数值
* @param integer $backline 回退行数
* @return Queue
*/
protected function setQueueProgress(?string $message = null, ?string $progress = null, int $backline = 0): Queue
{
$this->queue->progress(2, $message, $progress, $backline);
return $this;
}
}

View File

@ -198,7 +198,8 @@ abstract class Storage
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
[$content] = [curl_exec($ch), curl_close($ch)];
$content = curl_exec($ch);
curl_close($ch);
return $content ?: '';
}

View File

@ -63,11 +63,11 @@ class Database extends Command
[$tables, $total, $count] = SystemService::instance()->getTables();
$this->setQueueProgress("总共需要修复 {$total} 张数据表", '0');
foreach ($tables as $table) {
$this->queue->message($total, ++$count, "正在修复数据表 {$table}");
$this->setQueueMessage($total, ++$count, "正在修复数据表 {$table}");
$this->app->db->query("REPAIR TABLE `{$table}`");
$this->queue->message($total, $count, "完成修复数据表 {$table}", 1);
$this->setQueueMessage($total, $count, "完成修复数据表 {$table}", 1);
}
$this->queue->success("已完成对 {$total} 张数据表修复操作");
$this->setQueueSuccess("已完成对 {$total} 张数据表修复操作");
}
/**
@ -80,11 +80,11 @@ class Database extends Command
[$tables, $total, $count] = SystemService::instance()->getTables();
$this->setQueueProgress("总共需要优化 {$total} 张数据表", '0');
foreach ($tables as $table) {
$this->queue->message($total, ++$count, "正在优化数据表 {$table}");
$this->setQueueMessage($total, ++$count, "正在优化数据表 {$table}");
$this->app->db->query("OPTIMIZE TABLE `{$table}`");
$this->queue->message($total, $count, "完成优化数据表 {$table}", 1);
$this->setQueueMessage($total, $count, "完成优化数据表 {$table}", 1);
}
$this->queue->success("已完成对 {$total} 张数据表优化操作");
$this->setQueueSuccess("已完成对 {$total} 张数据表优化操作");
}
}

View File

@ -153,5 +153,4 @@ class Install extends Command
{
return true;
}
}

View File

@ -51,12 +51,12 @@ class Replace extends Command
{
$search = $input->getArgument('search');
$repalce = $input->getArgument('replace');
if ($search === '') $this->queue->error('查找替换字符内容不能为空!');
if ($repalce === '') $this->queue->error('目标替换字符内容不能为空!');
if ($search === '') $this->setQueueError('查找替换字符内容不能为空!');
if ($repalce === '') $this->setQueueError('目标替换字符内容不能为空!');
[$tables, $total, $count] = SystemService::instance()->getTables();
foreach ($tables as $table) {
$data = [];
$this->queue->message($total, ++$count, sprintf("准备替换数据表 %s", Str::studly($table)));
$this->setQueueMessage($total, ++$count, sprintf("准备替换数据表 %s", Str::studly($table)));
foreach ($this->app->db->table($table)->getFields() as $field => $attrs) {
if (preg_match('/char|text/', $attrs['type'])) {
$data[$field] = $this->app->db->raw(sprintf('REPLACE(`%s`,"%s","%s")', $field, $search, $repalce));
@ -64,14 +64,14 @@ class Replace extends Command
}
if (count($data) > 0) {
if ($this->app->db->table($table)->where('1=1')->update($data) !== false) {
$this->queue->message($total, $count, sprintf("成功替换数据表 %s", Str::studly($table)), 1);
$this->setQueueMessage($total, $count, sprintf("成功替换数据表 %s", Str::studly($table)), 1);
} else {
$this->queue->message($total, $count, sprintf("失败替换数据表 %s", Str::studly($table)), 1);
$this->setQueueMessage($total, $count, sprintf("失败替换数据表 %s", Str::studly($table)), 1);
}
} else {
$this->queue->message($total, $count, sprintf("无需替换数据表 %s", Str::studly($table)), 1);
$this->setQueueMessage($total, $count, sprintf("无需替换数据表 %s", Str::studly($table)), 1);
}
}
$this->queue->success('批量替换成功');
$this->setQueueSuccess("批量替换 {$total} 张数据表成功");
}
}

View File

@ -39,7 +39,7 @@ class TokenHelper extends Helper
$this->class->csrf_state = true;
if ($this->app->request->isPost() && !TokenService::instance()->checkFormToken()) {
if ($return) return false;
$this->class->error($this->class->csrf_message);
$this->class->error($this->class->csrf_message ?: lang('think_library_csrf_error'));
} else {
return true;
}

View File

@ -159,12 +159,6 @@ class BuildUrl extends Url
$file = 'index.php';
}
}
/*=====- 插件 Addons URL 处理 - 开始 -=====*/
if (preg_match("#^{$depr}addons-{$app}({$depr}|\.|$)#i", $uri)) {
[$pre, $suf] = explode($depr, $url . $depr, 2);
if ($pre === $app) $url = rtrim("addons-{$app}{$depr}{$suf}", $depr);
}
/*=====- 插件 Addons URL 处理 - 结束 -=====*/
$url = rtrim($file, '/') . '/' . ltrim($url, '/');
// URL后缀
if ('/' == substr($url, -1) || '' == $url) {

View File

@ -1,15 +1,16 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// | ThinkAdmin
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkLibrary
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
declare (strict_types=1);
@ -64,7 +65,7 @@ class Multiple
* @param Closure $next
* @return Response
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): Response
{
if (!$this->parseMultiApp()) return $next($request);
return $this->app->middleware->pipeline('app')->send($request)->then(function ($request) use ($next) {
@ -121,14 +122,12 @@ class Multiple
$appName = $map['*'];
} else {
$appName = $name ?: $defaultApp;
if (stripos($appName, 'addons-') !== 0) {
if (!is_dir($this->path ?: $this->app->getBasePath() . $appName)) {
if ($this->app->config->get('app.app_express', false)) {
$this->setApp($defaultApp);
return true;
} else {
return false;
}
if (!is_dir($this->path ?: $this->app->getBasePath() . $appName)) {
if ($this->app->config->get('app.app_express', false)) {
$this->setApp($defaultApp);
return true;
} else {
return false;
}
}
}
@ -149,19 +148,13 @@ class Multiple
private function setApp(string $appName): void
{
$space = $this->app->config->get('app.app_namespace') ?: 'app';
if (stripos($appName, 'addons-') === 0) {
$appName = substr($appName, strlen('addons-'));
$this->app->setNamespace("{$space}\\addons\\{$appName}");
$appPath = $this->path ?: $this->app->getBasePath() . 'addons' . DIRECTORY_SEPARATOR . $appName . DIRECTORY_SEPARATOR;
} else {
$this->app->setNamespace("{$space}\\{$appName}");
$appPath = $this->path ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR;
}
$appPath = $this->path ?: $this->app->getBasePath() . $appName . DIRECTORY_SEPARATOR;
// 动态设置多应用变量
$this->app->setAppPath($appPath);
$this->app->setNamespace("{$space}\\{$appName}");
$this->app->http->name($appName);
if (is_dir($appPath)) {
$this->app->setRuntimePath($this->app->getRuntimePath() . $appName . DIRECTORY_SEPARATOR);
$this->app->http->setRoutePath($this->app->getAppPath() . 'route' . DIRECTORY_SEPARATOR);
$this->app->http->setRoutePath($appPath . 'route' . DIRECTORY_SEPARATOR);
$this->loadApp($appPath);
}
}
@ -199,11 +192,7 @@ class Multiple
*/
private function scriptName(): 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) : '';
$file = $_SERVER['SCRIPT_FILENAME'] ?? ($_SERVER['argv'][0] ?? '');
return empty($file) ? '' : pathinfo($file, PATHINFO_FILENAME);
}
}

View File

@ -1,99 +0,0 @@
<?php
// 以下代码来自 topthink/think-multi-app有部分修改以兼容 ThinkAdmin 的需求
// +----------------------------------------------------------------------
// | 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>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace think\admin\multiple\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
* @package think\admin\multiple\command
*/
class Clear extends Command
{
protected function configure()
{
$this->setName('clear')->addArgument('app', Argument::OPTIONAL, 'app name');
$this->addOption('path', 'd', Option::VALUE_OPTIONAL, 'path to clear');
$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->addOption('expire', 'e', Option::VALUE_NONE, 'clear cache file if cache has expired');
$this->setDescription('Clear runtime file');
}
/**
* @param Input $input
* @param Output $output
* @return void
*/
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 = $input->getOption('path') ?: $runtimePath;
}
$rmdir = (bool)$input->getOption('dir');
// --expire 仅当 --cache 时生效
$expire = $input->getOption('expire') && $input->getOption('cache');
$this->clear(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, $rmdir, $expire);
$output->writeln("<info>Clear Successed</info>");
}
/**
* 清处理指定目录
* @param string $path 待清理目录
* @param boolean $rmdir 是否目录
* @param boolean $expire 有效时间
*/
private function clear(string $path, bool $rmdir, bool $expire): void
{
foreach (is_dir($path) ? scandir($path) : [] as $file) {
if ('.' !== $file && '..' !== $file && is_dir($path . $file)) {
$this->clear($path . $file . DIRECTORY_SEPARATOR, $rmdir, $expire);
if ($rmdir) @rmdir($path . $file);
} elseif ('.gitignore' != $file && is_file($path . $file)) {
if ($expire) {
if ($this->cacheHasExpired($path . $file)) {
@unlink($path . $file);
}
} else {
@unlink($path . $file);
}
}
}
}
/**
* 缓存文件是否已过期
* @param $filename string 文件路径
* @return boolean
*/
private function cacheHasExpired(string $filename): bool
{
$expire = (int)substr(file_get_contents($filename), 8, 12);
return 0 != $expire && time() - $expire > filemtime($filename);
}
}

View File

@ -50,11 +50,7 @@ class NodeService extends Service
*/
public function getCurrent(string $type = ''): string
{
$space = $this->app->getNamespace();
$prefix = strtolower($this->app->http->getName());
if (preg_match("|\\\\addons\\\\{$prefix}$|", $space)) {
$prefix = "addons-{$prefix}";
}
// 获取应用前缀节点
if ($type === 'module') return $prefix;
// 获取控制器前缀节点
@ -123,9 +119,8 @@ class NodeService extends Service
$name = substr($file, strlen(strtr($this->app->getRootPath(), '\\', '/')) - 1);
if (preg_match("|^([\w/]+)/(\w+)/controller/(.+)\.php$|i", $name, $matches)) {
[, $namespace, $appname, $classname] = $matches;
$addons = preg_match('|/addons$|', $namespace) ? 'addons-' : '';
$class = new ReflectionClass(strtr("{$namespace}/{$appname}/controller/{$classname}", '/', '\\'));
$prefix = strtolower(strtr("{$addons}{$appname}/{$this->nameTolower($classname)}", '\\', '/'));
$prefix = strtolower(strtr("{$appname}/{$this->nameTolower($classname)}", '\\', '/'));
$data[$prefix] = $this->_parseComment($class->getDocComment() ?: '', $classname);
foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (in_array($metname = $method->getName(), $ignores)) continue;

View File

@ -17,6 +17,7 @@ declare (strict_types=1);
namespace think\admin\service;
use think\admin\Library;
use think\admin\Service;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -98,7 +99,7 @@ class ProcessService extends Service
/**
* 查询相关进程列表
* @param string $cmd 任务指令
* @param string $name 名称
* @param string $name 程名称
* @return array
*/
public function query(string $cmd, string $name = 'php.exe'): array
@ -157,6 +158,15 @@ class ProcessService extends Service
return PATH_SEPARATOR === ';';
}
/**
* 读取组件版本号
* @return string
*/
public function version(): string
{
return Library::VERSION;
}
/**
* 清除空白字符过滤
* @param string $content

View File

@ -273,7 +273,7 @@ class SystemService extends Service
$this->app->console->call("optimize:schema", ["--connection={$connection}"]);
foreach (NodeService::instance()->getModules() as $module) {
$path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . $module;
file_exists($path) && is_dir($path) or mkdir($path, 0755, true);
file_exists($path) && is_dir($path) || mkdir($path, 0755, true);
$this->app->console->call("optimize:route", [$module]);
}
}
@ -314,8 +314,9 @@ class SystemService extends Service
$rows[] = "mode = {$data['mode']}";
foreach ($data['appmap'] as $key => $item) $rows[] = "appmap[{$key}] = {$item}";
foreach ($data['domain'] as $key => $item) $rows[] = "domain[{$key}] = {$item}";
$filename = $this->app->getRootPath() . 'runtime/.env';
file_put_contents($filename, "[RUNTIME]\n" . join("\n", $rows));
// 数据配置保存文件
$env = $this->app->getRootPath() . 'runtime/.env';
file_put_contents($env, "[RUNTIME]\n" . join("\n", $rows));
return $this->bindRuntime($data);
}
@ -327,8 +328,8 @@ class SystemService extends Service
*/
public function getRuntime(?string $name = null, array $default = [])
{
$filename = $this->app->getRootPath() . 'runtime/.env';
if (file_exists($filename)) $this->app->env->load($filename);
$env = $this->app->getRootPath() . 'runtime/.env';
if (file_exists($env)) $this->app->env->load($env);
$data = [
'mode' => $this->app->env->get('RUNTIME_MODE') ?: 'debug',
'appmap' => $this->app->env->get('RUNTIME_APPMAP') ?: [],