Skip to content

Commit

Permalink
feat: Update TinkerCommand and TinkerCaster to support additional typ…
Browse files Browse the repository at this point in the history
…es (#622)

* feat: Update TinkerCommand and TinkerCaster to support additional types

* Update TinkerCaster.php to fix property annotation for appends

---------

Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
huangdijia and huangdijia committed May 11, 2024
1 parent 4a38cea commit d5d9dae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Command/TinkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ class TinkerCommand extends HyperfCommand
* @var string[]
*/
protected array $defaultCasters = [
'Hyperf\Collection\Collection' => 'FriendsOfHyperf\Tinker\TinkerCaster::castCollection',
'Hyperf\DbConnection\Model\Model' => 'FriendsOfHyperf\Tinker\TinkerCaster::castModel',
'Hyperf\Redis\Redis' => 'FriendsOfHyperf\Tinker\TinkerCaster::castRedis',
'Hyperf\Collection\Collection' => 'FriendsOfHyperf\Tinker\TinkerCaster::castCollection',
'Stringable' => 'FriendsOfHyperf\Tinker\TinkerCaster::castStringable',
'Hyperf\Support\Fluent' => 'FriendsOfHyperf\Tinker\TinkerCaster::castFluent',
'Hyperf\Support\MessageBag' => 'FriendsOfHyperf\Tinker\TinkerCaster::castMessageBag',
'Hyperf\ViewEngine\HtmlString' => 'FriendsOfHyperf\Tinker\TinkerCaster::castHtmlString',
'Stringable' => 'FriendsOfHyperf\Tinker\TinkerCaster::castStringable',
'Symfony\Component\Console\Application' => 'FriendsOfHyperf\Tinker\TinkerCaster::castApplication',
];

Expand Down
27 changes: 26 additions & 1 deletion src/TinkerCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* @property string $poolName
* @property array appends
* @property array $appends
*/
class TinkerCaster
{
Expand Down Expand Up @@ -160,4 +160,29 @@ public static function castRedis($redis): array
Caster::PREFIX_PROTECTED . 'poolName' => $poolName,
];
}

/**
* Get an array representing the properties of a fluent.
*
* @param \Hyperf\Support\Fluent $fluent
*/
public static function castFluent($fluent): array
{
return [
Caster::PREFIX_PROTECTED . 'attributes' => $fluent->getAttributes(),
];
}

/**
* Get an array representing the properties of a message bag.
*
* @param \Hyperf\Support\MessageBag $messageBag
*/
public static function castMessageBag($messageBag): array
{
return [
Caster::PREFIX_PROTECTED . 'messages' => $messageBag->getMessages(),
Caster::PREFIX_PROTECTED . 'format' => $messageBag->getFormat(),
];
}
}

0 comments on commit d5d9dae

Please sign in to comment.