From af0d8528cc71de59628a43c4166ee8fbbbbac640 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:28:19 +0800 Subject: [PATCH] chore: Update TinkerCommand.php to include additional casters 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). --- src/Command/TinkerCommand.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Command/TinkerCommand.php b/src/Command/TinkerCommand.php index a1bb6c8..f86824b 100644 --- a/src/Command/TinkerCommand.php +++ b/src/Command/TinkerCommand.php @@ -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'); @@ -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', [])); } }