From 74a9843b2d00f3e68785d2f9195ab466299a2454 Mon Sep 17 00:00:00 2001 From: Eugeniy Date: Tue, 16 Jun 2026 17:10:54 +0300 Subject: [PATCH 1/2] fix(php85): Fixed nullable parameter deprecations --- composer.json | 30 ++++++++++--------------- src/AuthCommand.php | 2 +- src/Exception/UnauthorizedException.php | 2 +- src/Guard/JwtGuard.php | 12 +++++----- src/Guard/SessionGuard.php | 2 +- src/Guard/SsoGuard.php | 8 +++---- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 009c5e7..c718f3b 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,10 @@ } }, "require": { - "php": ">=8.1", + "php": ">=8.3", "96qbhy/simple-jwt": "^v1.5", - "hyperf/cache": "^3.1", - "hyperf/di": "^3.1", + "hyperf/cache": "^3.1|^3.2", + "hyperf/di": "^3.1|^3.2", "ext-json": "*", "ext-redis": "*" }, @@ -36,15 +36,15 @@ "require-dev": { "brainmaestro/composer-git-hooks": "^2.8", "friendsofphp/php-cs-fixer": "^2.14", - "hyperf/command": "^3.1", - "hyperf/config": "^3.1", - "hyperf/database": "^3.1", - "hyperf/event": "^3.1", - "hyperf/framework": "^3.1", - "hyperf/redis": "^3.1", - "hyperf/session": "^3.1", - "hyperf/testing": "^3.1", - "hyperf/utils": "^3.1", + "hyperf/command": "^3.2", + "hyperf/config": "^3.2", + "hyperf/database": "^3.2", + "hyperf/event": "^3.2", + "hyperf/framework": "^3.2", + "hyperf/redis": "^3.2", + "hyperf/session": "^3.2", + "hyperf/testing": "^3.2", + "hyperf/utils": "^3.2", "itsgoingd/clockwork": "^5.0", "phpstan/phpstan": "^0.12", "swoft/swoole-ide-helper": "dev-master", @@ -74,11 +74,5 @@ "composer test" ] } - }, - "repositories": { - "packagist": { - "type": "composer", - "url": "https://mirrors.aliyun.com/composer/" - } } } diff --git a/src/AuthCommand.php b/src/AuthCommand.php index ba74845..1ee6f6f 100644 --- a/src/AuthCommand.php +++ b/src/AuthCommand.php @@ -30,7 +30,7 @@ public function handle() $this->gen('SIMPLE_JWT_SECRET'); } - public function gen($key, string $value = null) + public function gen($key, ?string $value = null) { if (empty(env($key))) { file_put_contents(BASE_PATH . '/.env', sprintf(PHP_EOL . '%s=%s', $key, $value ?? str_random(16)), FILE_APPEND); diff --git a/src/Exception/UnauthorizedException.php b/src/Exception/UnauthorizedException.php index f097677..8bcb168 100644 --- a/src/Exception/UnauthorizedException.php +++ b/src/Exception/UnauthorizedException.php @@ -20,7 +20,7 @@ class UnauthorizedException extends AuthException protected int $statusCode = 401; - public function __construct(string $message, AuthGuard $guard = null, Throwable $previous = null) + public function __construct(string $message, ?AuthGuard $guard = null, ?Throwable $previous = null) { parent::__construct($message, 401, $previous); $this->guard = $guard; diff --git a/src/Guard/JwtGuard.php b/src/Guard/JwtGuard.php index 7bcbaa3..df6f2a8 100644 --- a/src/Guard/JwtGuard.php +++ b/src/Guard/JwtGuard.php @@ -90,7 +90,7 @@ public function user(?string $token = null): ?Authenticatable if ($result instanceof UnauthorizedException) { throw $result; } - return $result ?: null; + return $result ?? null; } try { @@ -98,7 +98,7 @@ public function user(?string $token = null): ?Authenticatable $jwt = $this->getJwtManager()->parse($token); $uid = $jwt->getPayload()['uid'] ?? null; $user = $uid ? $this->userProvider->retrieveByCredentials($uid) : null; - Context::set($key, $user ?: 0); + Context::set($key, $user ?? 0); return $user; } @@ -139,7 +139,7 @@ public function guest(?string $token = null): bool */ public function refresh(?string $token = null): ?string { - $token = $token ?: $this->parseToken(); + $token = $token ?? $this->parseToken(); if ($token) { Context::set($this->resultKey($token), null); @@ -158,7 +158,7 @@ public function refresh(?string $token = null): ?string return null; } - public function logout($token = null) + public function logout(?string $token = null) { if ($token = $token ?? $this->parseToken()) { Context::set($this->resultKey($token), null); @@ -170,7 +170,7 @@ public function logout($token = null) return false; } - public function getPayload($token = null): ?array + public function getPayload(?string $token = null): ?array { if ($token = $token ?? $this->parseToken()) { return $this->getJwtManager()->justParse($token)->getPayload(); @@ -183,7 +183,7 @@ public function getJwtManager(): JWTManager return $this->jwtManager; } - public function id($token = null) + public function id(?string $token = null) { if ($token = $token ?? $this->parseToken()) { return $this->getJwtManager()->parse($token)->getPayload()['uid']; diff --git a/src/Guard/SessionGuard.php b/src/Guard/SessionGuard.php index bdb65a5..5e6747f 100644 --- a/src/Guard/SessionGuard.php +++ b/src/Guard/SessionGuard.php @@ -52,7 +52,7 @@ public function user(): ?Authenticatable if ($result instanceof \Throwable) { throw $result; } - return $result ?: null; + return $result ?? null; } try { diff --git a/src/Guard/SsoGuard.php b/src/Guard/SsoGuard.php index 09187d9..5471553 100644 --- a/src/Guard/SsoGuard.php +++ b/src/Guard/SsoGuard.php @@ -46,9 +46,9 @@ public function getClients(): array return $this->config['clients'] ?? ['unknown']; } - public function login(Authenticatable $user, array $payload = [], string $client = null) + public function login(Authenticatable $user, array $payload = [], ?string $client = null) { - $client = $client ?: $this->getClients()[0]; // 需要至少配置一个客户端 + $client = $client ?? $this->getClients()[0]; // 需要至少配置一个客户端 $token = parent::login($user, $payload); $redisKey = str_replace('{uid}', (string) $user->getId(), $this->config['redis_key'] ?? 'u:token:{uid}'); @@ -64,12 +64,12 @@ public function login(Authenticatable $user, array $payload = [], string $client return $token; } - public function refresh(?string $token = null, string $client = null): ?string + public function refresh(?string $token = null, ?string $client = null): ?string { $token = parent::refresh($token); if ($token) { - $client = $client ?: $this->getClients()[0]; // 需要至少配置一个客户端 + $client = $client ?? $this->getClients()[0]; // 需要至少配置一个客户端 $redisKey = str_replace('{uid}', (string) $this->id($token), $this->config['redis_key'] ?? 'u:token:{uid}'); $this->redis->hSet($redisKey, $client, $token); } From 1e3646a231be72147b07cba0a45ab0db501010c4 Mon Sep 17 00:00:00 2001 From: Eugeniy Date: Tue, 16 Jun 2026 17:46:17 +0300 Subject: [PATCH 2/2] fix(php85): Undo composer changes --- composer.json | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index c718f3b..009c5e7 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,10 @@ } }, "require": { - "php": ">=8.3", + "php": ">=8.1", "96qbhy/simple-jwt": "^v1.5", - "hyperf/cache": "^3.1|^3.2", - "hyperf/di": "^3.1|^3.2", + "hyperf/cache": "^3.1", + "hyperf/di": "^3.1", "ext-json": "*", "ext-redis": "*" }, @@ -36,15 +36,15 @@ "require-dev": { "brainmaestro/composer-git-hooks": "^2.8", "friendsofphp/php-cs-fixer": "^2.14", - "hyperf/command": "^3.2", - "hyperf/config": "^3.2", - "hyperf/database": "^3.2", - "hyperf/event": "^3.2", - "hyperf/framework": "^3.2", - "hyperf/redis": "^3.2", - "hyperf/session": "^3.2", - "hyperf/testing": "^3.2", - "hyperf/utils": "^3.2", + "hyperf/command": "^3.1", + "hyperf/config": "^3.1", + "hyperf/database": "^3.1", + "hyperf/event": "^3.1", + "hyperf/framework": "^3.1", + "hyperf/redis": "^3.1", + "hyperf/session": "^3.1", + "hyperf/testing": "^3.1", + "hyperf/utils": "^3.1", "itsgoingd/clockwork": "^5.0", "phpstan/phpstan": "^0.12", "swoft/swoole-ide-helper": "dev-master", @@ -74,5 +74,11 @@ "composer test" ] } + }, + "repositories": { + "packagist": { + "type": "composer", + "url": "https://mirrors.aliyun.com/composer/" + } } }