diff --git a/composer.json b/composer.json index 3181ead..901ae3c 100644 --- a/composer.json +++ b/composer.json @@ -12,31 +12,31 @@ "ext-json": "*", "ext-pdo": "*", "ext-swoole": ">=4.4", - "hyperf/constants": "^1.1", + "hyperf/constants": "~2.0.0", "aliyuncs/oss-sdk-php": "^2.3", "box/spout": "^3.1", - "hyperf/amqp": "^1.1", - "hyperf/cache": "~1.1.0", - "hyperf/command": "~1.1.0", - "hyperf/config": "~1.1.0", - "hyperf/database": "^1.1", - "hyperf/db-connection": "~1.1.0", - "hyperf/filesystem": "^1.1", - "hyperf/framework": "~1.1.0", - "hyperf/guzzle": "~1.1.0", - "hyperf/http-server": "~1.1.0", - "hyperf/logger": "~1.1.0", - "hyperf/memory": "~1.1.0", - "hyperf/metric": "^1.1", - "hyperf/nsq": "^1.1", - "hyperf/process": "~1.1.0", - "hyperf/redis": "~1.1.0", - "hyperf/snowflake": "^1.1", + "hyperf/amqp": "~2.0.0", + "hyperf/cache": "~2.0.0", + "hyperf/command": "~2.0.0", + "hyperf/config": "~2.0.0", + "hyperf/database": "~2.0.0", + "hyperf/db-connection": "~2.0.0", + "hyperf/filesystem": "~2.0.0", + "hyperf/framework": "~2.0.0", + "hyperf/guzzle": "~2.0.0", + "hyperf/http-server": "~2.0.0", + "hyperf/logger": "~2.0.0", + "hyperf/memory": "~2.0.0", + "hyperf/metric": "~2.0.0", + "hyperf/nsq": "~2.0.0", + "hyperf/process": "~2.0.0", + "hyperf/redis": "~2.0.0", + "hyperf/snowflake": "~2.0.0", "yadakhov/insert-on-duplicate-key": "^1.2", - "hyperf/async-queue": "^1.1", - "hyperf/crontab": "^1.1", + "hyperf/async-queue": "~2.0.0", + "hyperf/crontab": "~2.0.0", "zoujingli/ip2region": "^1.0", - "hyperf/validation": "^1.1" + "hyperf/validation": "~2.0.0" }, "replace": { "hyperf-admin/base-utils": "self.version", diff --git a/src/admin/composer.json b/src/admin/composer.json index 19799d2..9d4f5e8 100644 --- a/src/admin/composer.json +++ b/src/admin/composer.json @@ -9,8 +9,8 @@ } ], "require": { - "rock-admin/base-utils": "~0.0.1", - "rock-admin/validation": "~0.0.1" + "rock-admin/base-utils": "dev-master", + "rock-admin/validation": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/alert-manager/composer.json b/src/alert-manager/composer.json index 1460b29..fc0cc53 100644 --- a/src/alert-manager/composer.json +++ b/src/alert-manager/composer.json @@ -9,9 +9,9 @@ } ], "require": { - "hyperf/async-queue": "^1.1", - "hyperf/process": "^1.1", - "rock-admin/rule-engine": "~0.0.1" + "hyperf/async-queue": "~2.0.0", + "hyperf/process": "~2.0.0", + "rock-admin/rule-engine": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/alert-manager/src/AlertQueueConsumer.php b/src/alert-manager/src/AlertQueueConsumer.php index fbcbb47..874bb75 100644 --- a/src/alert-manager/src/AlertQueueConsumer.php +++ b/src/alert-manager/src/AlertQueueConsumer.php @@ -8,7 +8,7 @@ class AlertQueueConsumer extends ConsumerProcess { public $queue = 'alert_manager'; - public function isEnable(): bool + public function isEnable($server): bool { return config('alert_manager.enable', false); } diff --git a/src/base-utils/composer.json b/src/base-utils/composer.json index ae2c616..2e939d8 100644 --- a/src/base-utils/composer.json +++ b/src/base-utils/composer.json @@ -16,31 +16,31 @@ "ext-yaml": "*", "aliyuncs/oss-sdk-php": "^2.3", "box/spout": "^3.1", - "hyperf/amqp": "^1.1", - "hyperf/cache": "~1.1.0", - "hyperf/command": "~1.1.0", - "hyperf/config": "~1.1.0", - "hyperf/constants": "^1.1", - "hyperf/database": "^1.1", - "hyperf/db-connection": "~1.1.0", - "hyperf/filesystem": "^1.1", - "hyperf/framework": "~1.1.0", - "hyperf/guzzle": "~1.1.0", - "hyperf/http-server": "~1.1.0", - "hyperf/logger": "~1.1.0", - "hyperf/memory": "~1.1.0", - "hyperf/metric": "^1.1", - "hyperf/nsq": "^1.1", - "hyperf/process": "~1.1.0", - "hyperf/redis": "~1.1.0", - "hyperf/snowflake": "^1.1", + "hyperf/amqp": "~2.0.0", + "hyperf/cache": "~2.0.0", + "hyperf/command": "~2.0.0", + "hyperf/config": "~2.0.0", + "hyperf/constants": "~2.0.0", + "hyperf/database": "~2.0.0", + "hyperf/db-connection": "~2.0.0", + "hyperf/filesystem": "~2.0.0", + "hyperf/framework": "~2.0.0", + "hyperf/guzzle": "~2.0.0", + "hyperf/http-server": "~2.0.0", + "hyperf/logger": "~2.0.0", + "hyperf/memory": "~2.0.0", + "hyperf/metric": "~2.0.0", + "hyperf/nsq": "~2.0.0", + "hyperf/process": "~2.0.0", + "hyperf/redis": "~2.0.0", + "hyperf/snowflake": "~2.0.0", "yadakhov/insert-on-duplicate-key": "^1.2" }, "require-dev": { "swoft/swoole-ide-helper": "^4.2", "phpstan/phpstan": "^0.11.2", - "hyperf/devtool": "~1.1.0", - "hyperf/testing": "~1.1.0", + "hyperf/devtool": "~2.0.0", + "hyperf/testing": "~2.0.0", "daodao97/hyperf-watch": "dev-master", "symfony/var-dumper": "^5.0" }, diff --git a/src/base-utils/src/ColorLineFormatter.php b/src/base-utils/src/ColorLineFormatter.php index 5fac6ac..b310316 100644 --- a/src/base-utils/src/ColorLineFormatter.php +++ b/src/base-utils/src/ColorLineFormatter.php @@ -11,7 +11,7 @@ class ColorLineFormatter extends LineFormatter 'WARNING' => "\e[0;33m{log_str}\e[0m", ]; - public function format(array $record) + public function format(array $record): string { $log = parent::format($record); diff --git a/src/base-utils/src/ConfigProvider.php b/src/base-utils/src/ConfigProvider.php index 8c6633f..83fdfb2 100644 --- a/src/base-utils/src/ConfigProvider.php +++ b/src/base-utils/src/ConfigProvider.php @@ -2,20 +2,18 @@ declare(strict_types=1); namespace HyperfAdmin\BaseUtils; -use Dotenv\Dotenv; -use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\StdoutLoggerInterface; -use Hyperf\Crontab\LoggerInterface; use Hyperf\HttpServer\Router\DispatcherFactory; -use Hyperf\Utils\Str; -use Monolog\Formatter\JsonFormatter; -use Monolog\Logger; use HyperfAdmin\BaseUtils\Exception\HttpExceptionHandler; use HyperfAdmin\BaseUtils\Listener\BootAppConfListener as HABootAppConfListener; use HyperfAdmin\BaseUtils\Listener\DbQueryExecutedListener; use HyperfAdmin\BaseUtils\Listener\FetchModeListener; use HyperfAdmin\BaseUtils\Middleware\CorsMiddleware; use HyperfAdmin\BaseUtils\Middleware\HttpLogMiddleware; +use Monolog\Formatter\JsonFormatter; +use Monolog\Handler\StreamHandler; +use Monolog\Logger; +use Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler as HyperfHttpExceptionHandler; class ConfigProvider { @@ -24,10 +22,10 @@ class ConfigProvider if (is_dev()) { $logger_default = [ 'handler' => [ - 'class' => HAStreamHandler::class, + 'class' => StreamHandler::class, 'constructor' => [ - 'level' => Logger::INFO, 'stream' => 'php://stdout', + 'level' => Logger::DEBUG, ], ], 'formatter' => [ @@ -35,17 +33,18 @@ class ConfigProvider 'constructor' => [ 'format' => "%datetime%||%channel%||%level_name%||%message%||%context%||%extra%\n", 'allowInlineLineBreaks' => true, - 'includeStacktraces' => true, + 'dateFormat' => 'Y-m-d H:i:s', ], ], + 'processors' => [], ]; } else { $logger_default = [ 'handler' => [ 'class' => RotatingFileHandler::class, 'constructor' => [ - 'filename' => BASE_PATH . '/runtime/logs/app.log', - 'maxFiles' => 1, + 'filename' => BASE_PATH . '/runtime/logs/' . env('APP_NAME', 'hyperf-admin') . '.log', + 'maxFiles' => 2, 'level' => Logger::INFO, ], ], @@ -53,6 +52,7 @@ class ConfigProvider 'class' => JsonFormatter::class, 'constructor' => [], ], + 'processors' => [], ]; } @@ -107,7 +107,8 @@ class ConfigProvider 'exceptions' => [ 'handler' => [ 'http' => [ - HttpExceptionHandler::class + HyperfHttpExceptionHandler::class, + HttpExceptionHandler::class, ], ], ], diff --git a/src/base-utils/src/HAStreamHandler.php b/src/base-utils/src/HAStreamHandler.php deleted file mode 100644 index 092fb1a..0000000 --- a/src/base-utils/src/HAStreamHandler.php +++ /dev/null @@ -1,18 +0,0 @@ -= $this->level; - } -} diff --git a/src/base-utils/src/Helper/common.php b/src/base-utils/src/Helper/common.php index 067cbc6..4f7ca61 100644 --- a/src/base-utils/src/Helper/common.php +++ b/src/base-utils/src/Helper/common.php @@ -514,7 +514,7 @@ if (!function_exists('is_test')) { if (!function_exists('is_dev')) { function is_dev() { - return env('ENV') == 'dev'; + return env('ENV', env('APP_ENV')) == 'dev'; } } diff --git a/src/base-utils/src/Helper/system.php b/src/base-utils/src/Helper/system.php index 3ff1590..ed010e0 100644 --- a/src/base-utils/src/Helper/system.php +++ b/src/base-utils/src/Helper/system.php @@ -10,10 +10,6 @@ use HyperfAdmin\BaseUtils\AliyunOSS; use HyperfAdmin\BaseUtils\Guzzle; use HyperfAdmin\BaseUtils\Log; -if (file_exists(BASE_PATH . '/.env')) { - Dotenv\Dotenv::create([BASE_PATH])->load(); -} - if(!function_exists('server')) { function server() { diff --git a/src/base-utils/src/Middleware/HttpLogMiddleware.php b/src/base-utils/src/Middleware/HttpLogMiddleware.php index fd697de..78da4fd 100644 --- a/src/base-utils/src/Middleware/HttpLogMiddleware.php +++ b/src/base-utils/src/Middleware/HttpLogMiddleware.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace HyperfAdmin\BaseUtils\Middleware; use FastRoute\Dispatcher; +use Hyperf\HttpMessage\Exception\NotFoundHttpException; use Hyperf\HttpServer\Router\Dispatched; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -37,8 +38,6 @@ class HttpLogMiddleware implements MiddlewareInterface $response = $handler->handle($request); /** @var Dispatched $dispatched */ $dispatched = $request->getAttribute(Dispatched::class); - //获取method - $method = $request->getMethod(); switch($dispatched->status) { case Dispatcher::NOT_FOUND: Log::get('http')->warning(sprintf('%s not found', $path)); @@ -57,10 +56,9 @@ class HttpLogMiddleware implements MiddlewareInterface 'use_time' => 1000 * (microtime(true) - $start_time), 'response' => $response_content, ]; - // 当路由存在时获取定义路由 - $route = $dispatched->handler->route; Log::get('http')->info('resume', $msg); } + throw new NotFoundHttpException(); break; } diff --git a/src/base-utils/src/RotatingFileHandler.php b/src/base-utils/src/RotatingFileHandler.php index e7b47b0..318b538 100644 --- a/src/base-utils/src/RotatingFileHandler.php +++ b/src/base-utils/src/RotatingFileHandler.php @@ -1,74 +1,10 @@ filename = $filename; - $this->maxFiles = (int)$maxFiles; - $this->nextRotation = new \DateTime(date('YmdH0000', strtotime('+1 hour'))); - $this->dateFormat = 'YmdH'; - $this->filenameFormat = '{filename}-{date}'; - parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking); - } - - /** - * 修复handler写日志判断级别问题bug - */ - public function isHandling(array $record): bool - { - $level_code = Logger::toMonologLevel($record['level']); - - return $level_code >= $this->level; - } - - protected function rotate() - { - // update filename - $this->url = $this->getTimedFilename(); - $this->nextRotation = new \DateTime(date('YmdH0000', strtotime('+1 hour'))); - // skip GC of old logs if files are unlimited - if (0 === $this->maxFiles) { - return; - } - $logFiles = glob($this->getGlobPattern()); - if ($this->maxFiles >= count($logFiles)) { - // no files to remove - return; - } - // Sorting the files by name to remove the older ones - usort($logFiles, function ($a, $b) { - return strcmp($b, $a); - }); - foreach (array_slice($logFiles, $this->maxFiles) as $file) { - if (is_writable($file)) { - // suppress errors here as unlink() might fail if two processes - // are cleaning up/rotating at the same time - set_error_handler(function ($errno, $errstr, $errfile, $errline) { - }); - unlink($file); - restore_error_handler(); - } - } - $this->mustRotate = false; - } - - protected function getTimedFilename() - { - $fileInfo = pathinfo($this->filename); - $timedFilename = str_replace(['{filename}', '{date}'], [ - $fileInfo['filename'], - date($this->dateFormat), - ], $fileInfo['dirname'] . '/' . $this->filenameFormat); - - if (!empty($fileInfo['extension'])) { - $timedFilename .= '.' . $fileInfo['extension']; - } - - return $timedFilename; - } + public const FILE_PER_DAY = 'Y-m-d-H'; } diff --git a/src/cron-center/composer.json b/src/cron-center/composer.json index db60f4d..9b92921 100644 --- a/src/cron-center/composer.json +++ b/src/cron-center/composer.json @@ -10,11 +10,11 @@ } ], "require": { - "hyperf/crontab": "^1.1", - "hyperf/process": "^1.1", - "hyperf/command": "^1.1", - "hyperf/event": "^1.1", - "rock-admin/base-utils": "~0.0.1" + "hyperf/crontab": "~2.0.0", + "hyperf/process": "~2.0.0", + "hyperf/command": "~2.0.0", + "hyperf/event": "~2.0.0", + "rock-admin/base-utils": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/event-bus/composer.json b/src/event-bus/composer.json index 37e24e2..e1390c6 100644 --- a/src/event-bus/composer.json +++ b/src/event-bus/composer.json @@ -9,8 +9,8 @@ } ], "require": { - "hyperf/process": "^1.1", - "hyperf/amqp": "^1.1" + "hyperf/process": "~2.0.0", + "hyperf/amqp": "~2.0.0" }, "autoload": { "psr-4": { diff --git a/src/event-bus/src/ProcessFactory.php b/src/event-bus/src/ProcessFactory.php index 4588a3b..66d081f 100644 --- a/src/event-bus/src/ProcessFactory.php +++ b/src/event-bus/src/ProcessFactory.php @@ -81,7 +81,7 @@ class ProcessFactory $this->consumer->consume($this->message); } - public function isEnable(): bool + public function isEnable($server): bool { return $this->message->isEnable(); } @@ -125,7 +125,7 @@ class ProcessFactory }, $this->instance); } - public function isEnable(): bool + public function isEnable($server): bool { return true; } diff --git a/src/process-manager/composer.json b/src/process-manager/composer.json index 75cf63b..6eec28d 100644 --- a/src/process-manager/composer.json +++ b/src/process-manager/composer.json @@ -10,10 +10,10 @@ ], "require": { "php": ">=7.2", - "hyperf/amqp": "^1.1", - "hyperf/crontab": "^1.1", - "hyperf/nsq": "^1.1", - "hyperf/process": "~1.1.0" + "hyperf/amqp": "~2.0.0", + "hyperf/crontab": "~2.0.0", + "hyperf/nsq": "~2.0.0", + "hyperf/process": "~2.0.0" }, "autoload": { "psr-4": { diff --git a/src/process-manager/src/AmqpConsumerManager.php b/src/process-manager/src/AmqpConsumerManager.php index 5c96c23..bca8cac 100644 --- a/src/process-manager/src/AmqpConsumerManager.php +++ b/src/process-manager/src/AmqpConsumerManager.php @@ -81,7 +81,7 @@ class AmqpConsumerManager return $this->consumerMessage; } - public function isEnable(): bool + public function isEnable($server): bool { return $this->consumerMessage->isEnable(); } diff --git a/src/process-manager/src/BootProcessListener.php b/src/process-manager/src/BootProcessListener.php index 1ebe237..0598e0f 100644 --- a/src/process-manager/src/BootProcessListener.php +++ b/src/process-manager/src/BootProcessListener.php @@ -70,7 +70,7 @@ class BootProcessListener implements ListenerInterface $instance = $process; } if ($instance instanceof ProcessInterface) { - $instance->isEnable() && $instance->bind($server); + $instance->isEnable($server) && $instance->bind($server); } } } diff --git a/src/process-manager/src/NsqConsumerManager.php b/src/process-manager/src/NsqConsumerManager.php index 017c4f8..bd041d6 100644 --- a/src/process-manager/src/NsqConsumerManager.php +++ b/src/process-manager/src/NsqConsumerManager.php @@ -100,7 +100,7 @@ class NsqConsumerManager return $this->consumer; } - public function isEnable(): bool + public function isEnable($server): bool { return $this->config->get(sprintf('nsq.%s.enable', $this->consumer->getPool()), true) && $this->consumer->isEnable(); } diff --git a/src/validation/composer.json b/src/validation/composer.json index e722a16..42b3f81 100644 --- a/src/validation/composer.json +++ b/src/validation/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "hyperf/validation": "^1.1", + "hyperf/validation": "~2.0.0", "rock-admin/base-utils": "dev-master" }, "autoload": {