Mercurial > hg > isophonics-drupal-site
diff vendor/psy/psysh/src/Shell.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
line wrap: on
line diff
--- a/vendor/psy/psysh/src/Shell.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/psy/psysh/src/Shell.php Thu Feb 28 13:21:36 2019 +0000 @@ -47,7 +47,7 @@ */ class Shell extends Application { - const VERSION = 'v0.9.6'; + const VERSION = 'v0.9.9'; const PROMPT = '>>> '; const BUFF_PROMPT = '... '; @@ -73,6 +73,7 @@ private $autoCompleter; private $matchers = []; private $commandsMatcher; + private $lastExecSuccess = true; /** * Create a new Psy Shell. @@ -109,7 +110,7 @@ public static function isIncluded(array $trace) { return isset($trace[0]['function']) && - in_array($trace[0]['function'], ['require', 'include', 'require_once', 'include_once']); + \in_array($trace[0]['function'], ['require', 'include', 'require_once', 'include_once']); } /** @@ -234,7 +235,7 @@ */ protected function getTabCompletionMatchers() { - @trigger_error('getTabCompletionMatchers is no longer used', E_USER_DEPRECATED); + @\trigger_error('getTabCompletionMatchers is no longer used', E_USER_DEPRECATED); } /** @@ -264,7 +265,7 @@ */ public function addMatchers(array $matchers) { - $this->matchers = array_merge($this->matchers, $matchers); + $this->matchers = \array_merge($this->matchers, $matchers); if (isset($this->autoCompleter)) { $this->addMatchersToAutoCompleter($matchers); @@ -392,7 +393,7 @@ } // handle empty input - if (trim($input) === '' && !$this->codeBufferOpen) { + if (\trim($input) === '' && !$this->codeBufferOpen) { continue; } @@ -424,12 +425,12 @@ } $code = $this->codeBuffer; - array_push($code, $input); - $tokens = @token_get_all('<?php ' . implode("\n", $code)); - $last = array_pop($tokens); + \array_push($code, $input); + $tokens = @\token_get_all('<?php ' . \implode("\n", $code)); + $last = \array_pop($tokens); return $last === '"' || $last === '`' || - (is_array($last) && in_array($last[0], [T_ENCAPSED_AND_WHITESPACE, T_START_HEREDOC, T_COMMENT])); + (\is_array($last) && \in_array($last[0], [T_ENCAPSED_AND_WHITESPACE, T_START_HEREDOC, T_COMMENT])); } /** @@ -559,6 +560,30 @@ } /** + * Return the set of variables currently in scope which differ from the + * values passed as $currentVars. + * + * This is used inside the Execution Loop Closure to pick up scope variable + * changes made by commands while the loop is running. + * + * @param array $currentVars + * + * @return array Associative array of scope variables which differ from $currentVars + */ + public function getScopeVariablesDiff(array $currentVars) + { + $newVars = []; + + foreach ($this->getScopeVariables(false) as $key => $value) { + if (!array_key_exists($key, $currentVars) || $currentVars[$key] !== $value) { + $newVars[$key] = $value; + } + } + + return $newVars; + } + + /** * Get the set of unused command-scope variable names. * * @return array Array of unused variable names @@ -575,7 +600,7 @@ */ public function getScopeVariableNames() { - return array_keys($this->context->getAll()); + return \array_keys($this->context->getAll()); } /** @@ -647,7 +672,7 @@ */ public function getIncludes() { - return array_merge($this->config->getDefaultIncludes(), $this->includes); + return \array_merge($this->config->getDefaultIncludes(), $this->includes); } /** @@ -682,9 +707,9 @@ { try { // Code lines ending in \ keep the buffer open - if (substr(rtrim($code), -1) === '\\') { + if (\substr(\rtrim($code), -1) === '\\') { $this->codeBufferOpen = true; - $code = substr(rtrim($code), 0, -1); + $code = \substr(\rtrim($code), 0, -1); } else { $this->codeBufferOpen = false; } @@ -766,7 +791,7 @@ throw new \InvalidArgumentException('Command not found: ' . $input); } - $input = new ShellInput(str_replace('\\', '\\\\', rtrim($input, " \t\n\r\0\x0B;"))); + $input = new ShellInput(\str_replace('\\', '\\\\', \rtrim($input, " \t\n\r\0\x0B;"))); if ($input->hasParameterOption(['--help', '-h'])) { $helpCommand = $this->get('help'); @@ -835,7 +860,7 @@ return; } - list($codeBuffer, $codeBufferOpen, $code) = array_pop($this->codeStack); + list($codeBuffer, $codeBufferOpen, $code) = \array_pop($this->codeStack); $this->codeBuffer = $codeBuffer; $this->codeBufferOpen = $codeBufferOpen; @@ -861,7 +886,7 @@ } // Skip empty lines and lines starting with a space - if (trim($line) !== '' && substr($line, 0, 1) !== ' ') { + if (\trim($line) !== '' && \substr($line, 0, 1) !== ' ') { $this->readline->addHistory($line); } } @@ -871,11 +896,11 @@ */ private function addCodeBufferToHistory() { - $codeBuffer = array_filter($this->codeBuffer, function ($line) { + $codeBuffer = \array_filter($this->codeBuffer, function ($line) { return !$line instanceof SilentInput; }); - $this->addHistory(implode("\n", $codeBuffer)); + $this->addHistory(\implode("\n", $codeBuffer)); } /** @@ -888,7 +913,7 @@ public function getNamespace() { if ($namespace = $this->cleaner->getNamespace()) { - return implode('\\', $namespace); + return \implode('\\', $namespace); } } @@ -907,7 +932,7 @@ // Incremental flush if ($out !== '' && !$isCleaning) { $this->output->write($out, false, ShellOutput::OUTPUT_RAW); - $this->outputWantsNewline = (substr($out, -1) !== "\n"); + $this->outputWantsNewline = (\substr($out, -1) !== "\n"); $this->stdoutBuffer .= $out; } @@ -915,7 +940,7 @@ if ($phase & PHP_OUTPUT_HANDLER_END) { // Write an extra newline if stdout didn't end with one if ($this->outputWantsNewline) { - $this->output->writeln(sprintf('<aside>%s</aside>', $this->config->useUnicode() ? '⏎' : '\\n')); + $this->output->writeln(\sprintf('<aside>%s</aside>', $this->config->useUnicode() ? '⏎' : '\\n')); $this->outputWantsNewline = false; } @@ -939,15 +964,17 @@ */ public function writeReturnValue($ret) { + $this->lastExecSuccess = true; + if ($ret instanceof NoReturnValue) { return; } $this->context->setReturnValue($ret); $ret = $this->presentValue($ret); - $indent = str_repeat(' ', strlen(static::RETVAL)); + $indent = \str_repeat(' ', \strlen(static::RETVAL)); - $this->output->writeln(static::RETVAL . str_replace(PHP_EOL, PHP_EOL . $indent, $ret)); + $this->output->writeln(static::RETVAL . \str_replace(PHP_EOL, PHP_EOL . $indent, $ret)); } /** @@ -962,12 +989,25 @@ */ public function writeException(\Exception $e) { + $this->lastExecSuccess = false; $this->context->setLastException($e); $this->output->writeln($this->formatException($e)); $this->resetCodeBuffer(); } /** + * Check whether the last exec was successful. + * + * Returns true if a return value was logged rather than an exception. + * + * @return bool + */ + public function getLastExecSuccess() + { + return $this->lastExecSuccess; + } + + /** * Helper for formatting an exception for writeException(). * * @todo extract this to somewhere it makes more sense @@ -981,23 +1021,23 @@ $message = $e->getMessage(); if (!$e instanceof PsyException) { if ($message === '') { - $message = get_class($e); + $message = \get_class($e); } else { - $message = sprintf('%s with message \'%s\'', get_class($e), $message); + $message = \sprintf('%s with message \'%s\'', \get_class($e), $message); } } - $message = preg_replace( + $message = \preg_replace( "#(\\w:)?(/\\w+)*/src/Execution(?:Loop)?Closure.php\(\d+\) : eval\(\)'d code#", "eval()'d code", - str_replace('\\', '/', $message) + \str_replace('\\', '/', $message) ); - $message = str_replace(" in eval()'d code", ' in Psy Shell code', $message); + $message = \str_replace(" in eval()'d code", ' in Psy Shell code', $message); $severity = ($e instanceof \ErrorException) ? $this->getSeverity($e) : 'error'; - return sprintf('<%s>%s</%s>', $severity, OutputFormatter::escape($message), $severity); + return \sprintf('<%s>%s</%s>', $severity, OutputFormatter::escape($message), $severity); } /** @@ -1010,7 +1050,7 @@ protected function getSeverity(\ErrorException $e) { $severity = $e->getSeverity(); - if ($severity & error_reporting()) { + if ($severity & \error_reporting()) { switch ($severity) { case E_WARNING: case E_NOTICE: @@ -1086,7 +1126,7 @@ */ public function handleError($errno, $errstr, $errfile, $errline) { - if ($errno & error_reporting()) { + if ($errno & \error_reporting()) { ErrorException::throwException($errno, $errstr, $errfile, $errline); } elseif ($errno & $this->config->errorLoggingLevel()) { // log it and continue... @@ -1132,7 +1172,7 @@ */ protected function hasCommand($input) { - if (preg_match('/([^\s]+?)(?:\s|$)/A', ltrim($input), $match)) { + if (\preg_match('/([^\s]+?)(?:\s|$)/A', \ltrim($input), $match)) { return $this->has($match[1]); } @@ -1167,22 +1207,22 @@ protected function readline() { if (!empty($this->inputBuffer)) { - $line = array_shift($this->inputBuffer); + $line = \array_shift($this->inputBuffer); if (!$line instanceof SilentInput) { - $this->output->writeln(sprintf('<aside>%s %s</aside>', static::REPLAY, OutputFormatter::escape($line))); + $this->output->writeln(\sprintf('<aside>%s %s</aside>', static::REPLAY, OutputFormatter::escape($line))); } return $line; } if ($bracketedPaste = $this->config->useBracketedPaste()) { - printf("\e[?2004h"); // Enable bracketed paste + \printf("\e[?2004h"); // Enable bracketed paste } $line = $this->readline->readline($this->getPrompt()); if ($bracketedPaste) { - printf("\e[?2004l"); // ... and disable it again + \printf("\e[?2004l"); // ... and disable it again } return $line; @@ -1195,7 +1235,7 @@ */ protected function getHeader() { - return sprintf('<aside>%s by Justin Hileman</aside>', $this->getVersion()); + return \sprintf('<aside>%s by Justin Hileman</aside>', $this->getVersion()); } /** @@ -1207,7 +1247,7 @@ { $separator = $this->config->useUnicode() ? '—' : '-'; - return sprintf('Psy Shell %s (PHP %s %s %s)', self::VERSION, phpversion(), $separator, php_sapi_name()); + return \sprintf('Psy Shell %s (PHP %s %s %s)', self::VERSION, PHP_VERSION, $separator, PHP_SAPI); } /** @@ -1225,7 +1265,7 @@ */ protected function autocomplete($text) { - @trigger_error('Tab completion is provided by the AutoCompleter service', E_USER_DEPRECATED); + @\trigger_error('Tab completion is provided by the AutoCompleter service', E_USER_DEPRECATED); } /** @@ -1280,7 +1320,7 @@ try { $client = $this->config->getChecker(); if (!$client->isLatest()) { - $this->output->writeln(sprintf('New version is available (current: %s, latest: %s)', self::VERSION, $client->getLatest())); + $this->output->writeln(\sprintf('New version is available (current: %s, latest: %s)', self::VERSION, $client->getLatest())); } } catch (\InvalidArgumentException $e) { $this->output->writeln($e->getMessage());