*/
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.
private $scopeVariables = array();
private $commandScopeVariables = array();
- private $lastException;
private $returnValue;
+ private $lastException;
+ private $lastStdout;
private $boundObject;
/**
}
break;
+ case '__out':
+ if (isset($this->lastStdout)) {
+ return $this->lastStdout;
+ }
+ break;
+
case 'this':
if (isset($this->boundObject)) {
return $this->boundObject;
}
/**
- * Get all defined magic variables: $_, $_e, $__class, $__file, etc.
+ * Get all defined magic variables: $_, $_e, $__out, $__class, $__file, etc.
*
* @return array
*/
$vars['_e'] = $this->lastException;
}
+ if (isset($this->lastStdout)) {
+ $vars['__out'] = $this->lastStdout;
+ }
+
if (isset($this->boundObject)) {
$vars['this'] = $this->boundObject;
}
/**
* 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
*/
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.
*