aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2025-12-09 12:42:40 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2025-12-09 12:42:40 +0000
commitc096814bed20ffd95b86322561b2f012c61118c6 (patch)
treeae1ad0968c233c82d25cbfb1ec28e8f3f4fbef01 /cli
parent6846b4ea8ef0ddeff45c5f0cbdba898dfccc6fdf (diff)
fix: more useful output of SORM objects in tinker
Closes #6098 Merge request studip/studip!4636
Diffstat (limited to 'cli')
-rw-r--r--cli/Commands/Base/Tinker.php11
-rw-r--r--cli/Commands/Base/TinkerCaster.php36
2 files changed, 42 insertions, 5 deletions
diff --git a/cli/Commands/Base/Tinker.php b/cli/Commands/Base/Tinker.php
index 1bc4f12..fff86dc 100644
--- a/cli/Commands/Base/Tinker.php
+++ b/cli/Commands/Base/Tinker.php
@@ -3,16 +3,13 @@
namespace Studip\Cli\Commands\Base;
use Symfony\Component\Console\Command\Command;
-use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Style\SymfonyStyle;
-use Symfony\Component\Process\PhpExecutableFinder;
-use Symfony\Component\Process\Process;
use Psy\Configuration;
use Psy\Shell;
use Psy\VersionUpdater\Checker;
+use SimpleCollection;
+use SimpleORMap;
class Tinker extends Command
{
@@ -32,6 +29,10 @@ class Tinker extends Command
$config = Configuration::fromInput($input);
$config->setUpdateCheck(Checker::NEVER);
$config->setDefaultIncludes([__DIR__ . '/../../studip_cli_env.inc.php']);
+ $config->addCasters([
+ SimpleCollection::class => TinkerCaster::class . '::castCollection',
+ SimpleORMap::class => TinkerCaster::class . '::castModel',
+ ]);
$shell = new Shell($config);
diff --git a/cli/Commands/Base/TinkerCaster.php b/cli/Commands/Base/TinkerCaster.php
new file mode 100644
index 0000000..9683ee2
--- /dev/null
+++ b/cli/Commands/Base/TinkerCaster.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Studip\Cli\Commands\Base;
+
+use SimpleCollection;
+use SimpleORMap;
+use Symfony\Component\VarDumper\Caster\Caster;
+
+class TinkerCaster
+{
+ /**
+ * Get an array representing the properties of a collection.
+ *
+ * @param SimpleCollection $collection
+ * @return array
+ */
+ public static function castCollection(SimpleCollection $collection)
+ {
+ return [
+ Caster::PREFIX_VIRTUAL . 'all' => [...$collection],
+ ];
+ }
+
+ /**
+ * Get an array representing the properties of a collection.
+ *
+ * @param SimpleORMap $collection
+ * @return array
+ */
+ public static function castModel(SimpleORMap $model)
+ {
+ return [
+ Caster::PREFIX_VIRTUAL . 'attributes' => $model->toArray(),
+ ];
+ }
+}