diff options
| author | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2025-12-10 12:49:59 +0000 |
|---|---|---|
| committer | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2025-12-10 12:49:59 +0000 |
| commit | 30bbaa36a3c58993c3e19c3df1b96a3ffc63c6c4 (patch) | |
| tree | 606b7aaf881168faea6c27385c89065235cbf246 /cli/Commands | |
| parent | 7bc552bb856cd5ce09b352510ee922b1b9b7b7ea (diff) | |
fix: more useful output of Illuminate\Support\Collection objects in tinker
Closes #6102
Merge request studip/studip!4640
Diffstat (limited to 'cli/Commands')
| -rw-r--r-- | cli/Commands/Base/Tinker.php | 4 | ||||
| -rw-r--r-- | cli/Commands/Base/TinkerCaster.php | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/cli/Commands/Base/Tinker.php b/cli/Commands/Base/Tinker.php index fff86dc..b8161e8 100644 --- a/cli/Commands/Base/Tinker.php +++ b/cli/Commands/Base/Tinker.php @@ -2,6 +2,7 @@ namespace Studip\Cli\Commands\Base; +use Illuminate\Support\Collection; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -30,7 +31,8 @@ class Tinker extends Command $config->setUpdateCheck(Checker::NEVER); $config->setDefaultIncludes([__DIR__ . '/../../studip_cli_env.inc.php']); $config->addCasters([ - SimpleCollection::class => TinkerCaster::class . '::castCollection', + Collection::class => TinkerCaster::class . '::castCollection', + SimpleCollection::class => TinkerCaster::class . '::castSimpleCollection', SimpleORMap::class => TinkerCaster::class . '::castModel', ]); diff --git a/cli/Commands/Base/TinkerCaster.php b/cli/Commands/Base/TinkerCaster.php index 9683ee2..168de58 100644 --- a/cli/Commands/Base/TinkerCaster.php +++ b/cli/Commands/Base/TinkerCaster.php @@ -2,6 +2,7 @@ namespace Studip\Cli\Commands\Base; +use Illuminate\Support\Collection; use SimpleCollection; use SimpleORMap; use Symfony\Component\VarDumper\Caster\Caster; @@ -14,10 +15,10 @@ class TinkerCaster * @param SimpleCollection $collection * @return array */ - public static function castCollection(SimpleCollection $collection) + public static function castCollection(Collection $collection) { return [ - Caster::PREFIX_VIRTUAL . 'all' => [...$collection], + Caster::PREFIX_VIRTUAL . 'all' => $collection->all(), ]; } @@ -33,4 +34,17 @@ class TinkerCaster Caster::PREFIX_VIRTUAL . 'attributes' => $model->toArray(), ]; } + + /** + * Get an array representing the properties of a collection. + * + * @param SimpleCollection $collection + * @return array + */ + public static function castSimpleCollection(SimpleCollection $collection) + { + return [ + Caster::PREFIX_VIRTUAL . 'all' => [...$collection], + ]; + } } |
