From f871c3ea9670f610221ab4f90c51e4bd1dffb6c7 Mon Sep 17 00:00:00 2001 From: Zachary Flower Date: Wed, 24 Jan 2018 14:23:03 -0700 Subject: [PATCH 1/3] add proof-of-concept for restart psysh from within a session --- src/Command/ReloadCommand.php | 63 +++++++++++++++++++++++++++++++++++ src/Shell.php | 1 + 2 files changed, 64 insertions(+) create mode 100644 src/Command/ReloadCommand.php diff --git a/src/Command/ReloadCommand.php b/src/Command/ReloadCommand.php new file mode 100644 index 000000000..d3ab6392e --- /dev/null +++ b/src/Command/ReloadCommand.php @@ -0,0 +1,63 @@ +setName('reload') + ->setAliases(array('reload!')) + ->setDefinition(array()) + ->setDescription('Reload the current session.') + ->setHelp( + <<<'HELP' +Reload the current session. + +Note: The PCNTL extension is required for reload to work. + +e.g. +>>> reload +HELP + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ( !function_exists('pcntl_exec') ) { + throw new RuntimeException('Unable to reload session (PCNTL is required).'); + } + + $output->writeln('Reloading...'); + + if ( !defined('PHP_BINARY') ) { + throw new RuntimeException('Unable to identify PHP binary path.'); + } + + pcntl_exec(PHP_BINARY, $_SERVER['argv']); + } +} diff --git a/src/Shell.php b/src/Shell.php index 7d64c504b..82d96b59d 100644 --- a/src/Shell.php +++ b/src/Shell.php @@ -196,6 +196,7 @@ protected function getDefaultCommands() new Command\BufferCommand(), new Command\ClearCommand(), new Command\EditCommand($this->config->getRuntimeDir()), + new Command\ReloadCommand(), // new Command\PsyVersionCommand(), $sudo, $hist, From b4a24df4887feac4fd0ff4cece7459dde64e3a53 Mon Sep 17 00:00:00 2001 From: Zachary Flower Date: Wed, 24 Jan 2018 14:55:26 -0700 Subject: [PATCH 2/3] fix style issues --- src/Command/ReloadCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Command/ReloadCommand.php b/src/Command/ReloadCommand.php index d3ab6392e..9706f1097 100644 --- a/src/Command/ReloadCommand.php +++ b/src/Command/ReloadCommand.php @@ -28,8 +28,8 @@ protected function configure() { $this ->setName('reload') - ->setAliases(array('reload!')) - ->setDefinition(array()) + ->setAliases(['reload!']) + ->setDefinition([]) ->setDescription('Reload the current session.') ->setHelp( <<<'HELP' @@ -48,13 +48,13 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - if ( !function_exists('pcntl_exec') ) { + if (!function_exists('pcntl_exec')) { throw new RuntimeException('Unable to reload session (PCNTL is required).'); } $output->writeln('Reloading...'); - if ( !defined('PHP_BINARY') ) { + if (!defined('PHP_BINARY')) { throw new RuntimeException('Unable to identify PHP binary path.'); } From ae127cb91f2731fcc353d0482d14c129b3e12a05 Mon Sep 17 00:00:00 2001 From: Zachary Flower Date: Wed, 24 Jan 2018 14:57:57 -0700 Subject: [PATCH 3/3] remove unused namespace --- src/Command/ReloadCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Command/ReloadCommand.php b/src/Command/ReloadCommand.php index 9706f1097..8d1854b4e 100644 --- a/src/Command/ReloadCommand.php +++ b/src/Command/ReloadCommand.php @@ -11,10 +11,9 @@ namespace Psy\Command; -use Psy\Exception\BreakException; +use Psy\Exception\RuntimeException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Psy\Exception\RuntimeException; /** * Reload the Psy Shell.