Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal: Session Reloading #466

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/Command/ReloadCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of Psy Shell.
*
* (c) 2012-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Psy\Command;

use Psy\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Reload the Psy Shell.
*/
class ReloadCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('reload')
->setAliases(['reload!'])
->setDefinition([])
->setDescription('Reload the current session.')
->setHelp(
<<<'HELP'
Reload the current session.

<warning>Note: The PCNTL extension is required for reload to work.</warning>

e.g.
<return>>>> reload</return>
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('<info>Reloading...</info>');

if (!defined('PHP_BINARY')) {
throw new RuntimeException('Unable to identify PHP binary path.');
}

pcntl_exec(PHP_BINARY, $_SERVER['argv']);
}
}
1 change: 1 addition & 0 deletions src/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down