From 4a38cea6080c3cc4cbbe3d64415fe63d9bc13198 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sat, 11 May 2024 09:10:13 +0800 Subject: [PATCH] feat: Update TinkerCaster to use arrow function for retrieving poolName --- src/TinkerCaster.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TinkerCaster.php b/src/TinkerCaster.php index 4dc8b8f..ee31b50 100644 --- a/src/TinkerCaster.php +++ b/src/TinkerCaster.php @@ -11,12 +11,14 @@ namespace FriendsOfHyperf\Tinker; -use ReflectionException; -use ReflectionObject; use Stringable; use Symfony\Component\VarDumper\Caster\Caster; use Throwable; +/** + * @property string $poolName + * @property array appends + */ class TinkerCaster { /** @@ -149,15 +151,13 @@ public static function castModel($model): array * * @param \Hyperf\Redis\Redis $redis * @return string[] - * @throws ReflectionException */ public static function castRedis($redis): array { - $refObject = new ReflectionObject($redis); - $refProperty = $refObject->getProperty('poolName'); + $poolName = (fn () => $this->poolName ?? 'default')->call($redis); return [ - Caster::PREFIX_PROTECTED . 'poolName' => (string) $refProperty->getValue($redis), + Caster::PREFIX_PROTECTED . 'poolName' => $poolName, ]; } }