X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FContext.php;fp=vendor%2Fpsy%2Fpsysh%2Fsrc%2FPsy%2FContext.php;h=663f986b994b40897e42fbc09c59fc4d08e6ff18;hp=9f0edfad382122c6a7390f0c49a0ce3b1a0641b3;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/psy/psysh/src/Psy/Context.php b/vendor/psy/psysh/src/Psy/Context.php index 9f0edfad3..663f986b9 100644 --- a/vendor/psy/psysh/src/Psy/Context.php +++ b/vendor/psy/psysh/src/Psy/Context.php @@ -19,7 +19,7 @@ namespace Psy; */ class Context { - private static $specialNames = array('_', '_e', '__psysh__', 'this'); + private static $specialNames = array('_', '_e', '__out', '__psysh__', 'this'); // Whitelist a very limited number of command-scope magic variable names. // This might be a bad idea, but future me can sort it out. @@ -29,8 +29,9 @@ class Context private $scopeVariables = array(); private $commandScopeVariables = array(); - private $lastException; private $returnValue; + private $lastException; + private $lastStdout; private $boundObject; /** @@ -54,6 +55,12 @@ class Context } break; + case '__out': + if (isset($this->lastStdout)) { + return $this->lastStdout; + } + break; + case 'this': if (isset($this->boundObject)) { return $this->boundObject; @@ -93,7 +100,7 @@ class Context } /** - * Get all defined magic variables: $_, $_e, $__class, $__file, etc. + * Get all defined magic variables: $_, $_e, $__out, $__class, $__file, etc. * * @return array */ @@ -107,6 +114,10 @@ class Context $vars['_e'] = $this->lastException; } + if (isset($this->lastStdout)) { + $vars['__out'] = $this->lastStdout; + } + if (isset($this->boundObject)) { $vars['this'] = $this->boundObject; } @@ -117,7 +128,8 @@ class Context /** * Set all scope variables. * - * This method does *not* set any of the magic variables: $_, $_e, $__class, $__file, etc. + * This method does *not* set any of the magic variables: $_, $_e, $__out, + * $__class, $__file, etc. * * @param array $vars */ @@ -180,6 +192,32 @@ class Context return $this->lastException; } + /** + * Set the most recent output from evaluated code. + * + * @param string $lastStdout + */ + public function setLastStdout($lastStdout) + { + $this->lastStdout = $lastStdout; + } + + /** + * Get the most recent output from evaluated code. + * + * @throws InvalidArgumentException If no output has happened yet + * + * @return null|string + */ + public function getLastStdout() + { + if (!isset($this->lastStdout)) { + throw new \InvalidArgumentException('No most-recent output'); + } + + return $this->lastStdout; + } + /** * Set the bound object ($this variable) for the interactive shell. *