Skip to content

Commit

Permalink
chore: Update TinkerCommand.php to include additional casters
Browse files Browse the repository at this point in the history
The recent code changes in TinkerCommand.php add additional casters to the getCasters() method. This ensures that the Tinker command can properly handle casting for various classes and objects.

Based on the recent user commits and repository commits, the commit message follows the established convention of using a prefix to indicate the type of change (`chore` for general maintenance or housekeeping).
  • Loading branch information
huangdijia committed Jun 13, 2024
1 parent 7760926 commit 53b59cf
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/tinker/src/Command/TinkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ class TinkerCommand extends HyperfCommand
'migrate',
];

/**
* Default casters.
* @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\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',
];

public function __construct(protected ContainerInterface $container, protected ConfigInterface $config)
{
parent::__construct('tinker');
Expand Down Expand Up @@ -145,6 +130,17 @@ protected function getCommands(): array
*/
protected function getCasters(): array
{
return array_merge($this->defaultCasters, (array) $this->config->get('tinker.casters', []));
$casters = [
'Hyperf\Collection\Collection' => 'FriendsOfHyperf\Tinker\TinkerCaster::castCollection',
'Hyperf\DbConnection\Model\Model' => 'FriendsOfHyperf\Tinker\TinkerCaster::castModel',
'Hyperf\Redis\Redis' => 'FriendsOfHyperf\Tinker\TinkerCaster::castRedis',
'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',
];

return array_merge($casters, (array) $this->config->get('tinker.casters', []));
}
}

0 comments on commit 53b59cf

Please sign in to comment.