From cc487815fba1ed57481b493f48c9a5d943ec469e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Wed, 29 Dec 2021 23:21:17 +0100 Subject: [PATCH] Fix Psysh command execution (#72) --- src/Command/PsyshCommand.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Command/PsyshCommand.php b/src/Command/PsyshCommand.php index 1fe19f3..0524d7d 100644 --- a/src/Command/PsyshCommand.php +++ b/src/Command/PsyshCommand.php @@ -11,9 +11,13 @@ namespace Fidry\PsyshBundle\Command; +use Psy\Output\ShellOutput; +use Psy\Shell; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; /** @@ -22,9 +26,9 @@ */ final class PsyshCommand extends Command { - private Application $psysh; + private Shell $psysh; - public function __construct(Application $psysh) + public function __construct(Shell $psysh) { parent::__construct(); @@ -38,6 +42,19 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + // Reset input & output if they are the default ones used. Indeed + // We call Psysh Application here which will do the necessary + // bootstrapping. + // If we don't we would force the regular Symfony Application + // bootstrapping instead not allowing the Psysh one to kick in at all. + if ($input instanceof ArgvInput) { + $input = null; + } + + if ($output instanceof ConsoleOutput) { + $output = null; + } + return $this->psysh->run($input, $output); } }