update v 1.0.7.5
This commit is contained in:
105
vendor/psy/psysh/src/Psy/Shell.php
vendored
105
vendor/psy/psysh/src/Psy/Shell.php
vendored
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2014 Justin Hileman
|
||||
* (c) 2012-2015 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -16,8 +16,8 @@ use Psy\Exception\ErrorException;
|
||||
use Psy\Exception\Exception as PsyException;
|
||||
use Psy\Exception\ThrowUpException;
|
||||
use Psy\Output\ShellOutput;
|
||||
use Psy\Presenter\PresenterManagerAware;
|
||||
use Psy\TabCompletion\Matcher;
|
||||
use Psy\VarDumper\PresenterAware;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
@@ -41,7 +41,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
class Shell extends Application
|
||||
{
|
||||
const VERSION = 'v0.4.4';
|
||||
const VERSION = 'v0.7.2';
|
||||
|
||||
const PROMPT = '>>> ';
|
||||
const BUFF_PROMPT = '... ';
|
||||
@@ -80,18 +80,6 @@ class Shell extends Application
|
||||
parent::__construct('Psy Shell', self::VERSION);
|
||||
|
||||
$this->config->setShell($this);
|
||||
// auto completer needs shell to be linked to configuration because of the context aware matchers
|
||||
if ($this->config->getTabCompletion()) {
|
||||
$this->completion = $this->config->getAutoCompleter();
|
||||
$this->addTabCompletionMatchers($this->config->getTabCompletionMatchers());
|
||||
foreach ($this->getTabCompletionMatchers() as $matcher) {
|
||||
if ($matcher instanceof ContextAware) {
|
||||
$matcher->setContext($this->context);
|
||||
}
|
||||
$this->completion->addMatcher($matcher);
|
||||
}
|
||||
$this->completion->activate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +146,7 @@ class Shell extends Application
|
||||
/**
|
||||
* Adds a command object.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param BaseCommand $command A Symfony Console Command object
|
||||
*
|
||||
@@ -171,8 +159,8 @@ class Shell extends Application
|
||||
$ret->setContext($this->context);
|
||||
}
|
||||
|
||||
if ($ret instanceof PresenterManagerAware) {
|
||||
$ret->setPresenterManager($this->config->getPresenterManager());
|
||||
if ($ret instanceof PresenterAware) {
|
||||
$ret->setPresenter($this->config->getPresenter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +195,9 @@ class Shell extends Application
|
||||
new Command\ListCommand(),
|
||||
new Command\DumpCommand(),
|
||||
new Command\DocCommand(),
|
||||
new Command\ShowCommand(),
|
||||
new Command\ShowCommand($this->config->colorMode()),
|
||||
new Command\WtfCommand(),
|
||||
new Command\WhereamiCommand(),
|
||||
new Command\WhereamiCommand($this->config->colorMode()),
|
||||
new Command\ThrowUpCommand(),
|
||||
new Command\TraceCommand(),
|
||||
new Command\BufferCommand(),
|
||||
@@ -267,10 +255,12 @@ class Shell extends Application
|
||||
* @param InputInterface $input An Input instance
|
||||
* @param OutputInterface $output An Output instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null)
|
||||
{
|
||||
$this->initializeTabCompletion();
|
||||
|
||||
if ($input === null && !isset($_SERVER['argv'])) {
|
||||
$input = new ArgvInput(array());
|
||||
}
|
||||
@@ -279,7 +269,11 @@ class Shell extends Application
|
||||
$output = $this->config->getOutput();
|
||||
}
|
||||
|
||||
return parent::run($input, $output);
|
||||
try {
|
||||
return parent::run($input, $output);
|
||||
} catch (\Exception $e) {
|
||||
$this->writeException($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +284,7 @@ class Shell extends Application
|
||||
* @param InputInterface $input An Input instance
|
||||
* @param OutputInterface $output An Output instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
public function doRun(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@@ -299,7 +293,7 @@ class Shell extends Application
|
||||
$this->resetCodeBuffer();
|
||||
|
||||
$this->setAutoExit(false);
|
||||
$this->setCatchExceptions(true);
|
||||
$this->setCatchExceptions(false);
|
||||
|
||||
$this->readline->readHistory();
|
||||
|
||||
@@ -312,8 +306,6 @@ class Shell extends Application
|
||||
try {
|
||||
$this->loop->run($this);
|
||||
} catch (ThrowUpException $e) {
|
||||
$this->setCatchExceptions(false);
|
||||
|
||||
throw $e->getPrevious();
|
||||
}
|
||||
}
|
||||
@@ -612,14 +604,14 @@ class Shell extends Application
|
||||
}
|
||||
|
||||
// Incremental flush
|
||||
if (!empty($out) && !$isCleaning) {
|
||||
if ($out !== '' && !$isCleaning) {
|
||||
$this->output->write($out, false, ShellOutput::OUTPUT_RAW);
|
||||
$this->outputWantsNewline = (substr($out, -1) !== "\n");
|
||||
}
|
||||
|
||||
// Output buffering is done!
|
||||
if ($this->outputWantsNewline && $phase & PHP_OUTPUT_HANDLER_END) {
|
||||
$this->output->writeln('<aside>⏎</aside>');
|
||||
$this->output->writeln(sprintf('<aside>%s</aside>', $this->config->useUnicode() ? '⏎' : '\\n'));
|
||||
$this->outputWantsNewline = false;
|
||||
}
|
||||
}
|
||||
@@ -643,18 +635,6 @@ class Shell extends Application
|
||||
$this->output->writeln(self::RETVAL . str_replace(PHP_EOL, PHP_EOL . $indent, $ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a caught Exception to stdout.
|
||||
*
|
||||
* @see self::renderException
|
||||
*
|
||||
* @param \Exception $e
|
||||
*/
|
||||
public function writeException(\Exception $e)
|
||||
{
|
||||
$this->renderException($e, $this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a caught Exception.
|
||||
*
|
||||
@@ -666,7 +646,7 @@ class Shell extends Application
|
||||
* @param \Exception $e An exception instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
public function renderException($e, $output)
|
||||
public function writeException(\Exception $e)
|
||||
{
|
||||
$this->context->setLastException($e);
|
||||
|
||||
@@ -676,7 +656,7 @@ class Shell extends Application
|
||||
}
|
||||
|
||||
$severity = ($e instanceof \ErrorException) ? $this->getSeverity($e) : 'error';
|
||||
$output->writeln(sprintf('<%s>%s</%s>', $severity, OutputFormatter::escape($message), $severity));
|
||||
$this->output->writeln(sprintf('<%s>%s</%s>', $severity, OutputFormatter::escape($message), $severity));
|
||||
|
||||
$this->resetCodeBuffer();
|
||||
}
|
||||
@@ -724,9 +704,14 @@ class Shell extends Application
|
||||
* threshold. This should probably only be used in the inner execution loop
|
||||
* of the shell, as most of the time a thrown exception is much more useful.
|
||||
*
|
||||
* If the error type matches the `errorLoggingLevel` config, it will be
|
||||
* logged as well, regardless of the `error_reporting` level.
|
||||
*
|
||||
* @see \Psy\Exception\ErrorException::throwException
|
||||
* @see \Psy\Shell::writeException
|
||||
*
|
||||
* @throws \Psy\Exception\ErrorException depending on the current error_reporting level.
|
||||
*
|
||||
* @param int $errno Error type
|
||||
* @param string $errstr Message
|
||||
* @param string $errfile Filename
|
||||
@@ -736,7 +721,7 @@ class Shell extends Application
|
||||
{
|
||||
if ($errno & error_reporting()) {
|
||||
ErrorException::throwException($errno, $errstr, $errfile, $errline);
|
||||
} else {
|
||||
} elseif ($errno & $this->config->errorLoggingLevel()) {
|
||||
// log it and continue...
|
||||
$this->writeException(new ErrorException($errstr, 0, $errno, $errfile, $errline));
|
||||
}
|
||||
@@ -745,7 +730,7 @@ class Shell extends Application
|
||||
/**
|
||||
* Format a value for display.
|
||||
*
|
||||
* @see PresenterManager::present
|
||||
* @see Presenter::present
|
||||
*
|
||||
* @param mixed $val
|
||||
*
|
||||
@@ -753,7 +738,7 @@ class Shell extends Application
|
||||
*/
|
||||
protected function presentValue($val)
|
||||
{
|
||||
return $this->config->getPresenterManager()->present($val);
|
||||
return $this->config->getPresenter()->present($val);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -828,7 +813,7 @@ class Shell extends Application
|
||||
*/
|
||||
protected function getHeader()
|
||||
{
|
||||
return sprintf("<aside>%s by Justin Hileman</aside>", $this->getVersion());
|
||||
return sprintf('<aside>%s by Justin Hileman</aside>', $this->getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -838,7 +823,9 @@ class Shell extends Application
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return sprintf("Psy Shell %s (PHP %s — %s)", self::VERSION, phpversion(), php_sapi_name());
|
||||
$separator = $this->config->useUnicode() ? '—' : '-';
|
||||
|
||||
return sprintf('Psy Shell %s (PHP %s %s %s)', self::VERSION, phpversion(), $separator, php_sapi_name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -875,4 +862,26 @@ class Shell extends Application
|
||||
return $this->getScopeVariableNames();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize tab completion matchers.
|
||||
*
|
||||
* If tab completion is enabled this adds tab completion matchers to the
|
||||
* auto completer and sets context if needed.
|
||||
*/
|
||||
protected function initializeTabCompletion()
|
||||
{
|
||||
// auto completer needs shell to be linked to configuration because of the context aware matchers
|
||||
if ($this->config->getTabCompletion()) {
|
||||
$this->completion = $this->config->getAutoCompleter();
|
||||
$this->addTabCompletionMatchers($this->config->getTabCompletionMatchers());
|
||||
foreach ($this->getTabCompletionMatchers() as $matcher) {
|
||||
if ($matcher instanceof ContextAware) {
|
||||
$matcher->setContext($this->context);
|
||||
}
|
||||
$this->completion->addMatcher($matcher);
|
||||
}
|
||||
$this->completion->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user