Skip to content

Commit

Permalink
feat: Update TinkerCaster to use arrow function for retrieving poolName
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed May 11, 2024
1 parent 5552cb9 commit 4a38cea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/TinkerCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down Expand Up @@ -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,
];
}
}

0 comments on commit 4a38cea

Please sign in to comment.