repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
39
1.84M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
bobthecow/psysh
src/Shell.php
Shell.add
public function add(BaseCommand $command) { if ($ret = parent::add($command)) { if ($ret instanceof ContextAware) { $ret->setContext($this->context); } if ($ret instanceof PresenterAware) { $ret->setPresenter($this->config->getPresenter()); } if (isset($this->commandsMatcher)) { $this->commandsMatcher->setCommands($this->all()); } } return $ret; }
php
public function add(BaseCommand $command) { if ($ret = parent::add($command)) { if ($ret instanceof ContextAware) { $ret->setContext($this->context); } if ($ret instanceof PresenterAware) { $ret->setPresenter($this->config->getPresenter()); } if (isset($this->commandsMatcher)) { $this->commandsMatcher->setCommands($this->all()); } } return $ret; }
[ "public", "function", "add", "(", "BaseCommand", "$", "command", ")", "{", "if", "(", "$", "ret", "=", "parent", "::", "add", "(", "$", "command", ")", ")", "{", "if", "(", "$", "ret", "instanceof", "ContextAware", ")", "{", "$", "ret", "->", "setContext", "(", "$", "this", "->", "context", ")", ";", "}", "if", "(", "$", "ret", "instanceof", "PresenterAware", ")", "{", "$", "ret", "->", "setPresenter", "(", "$", "this", "->", "config", "->", "getPresenter", "(", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "commandsMatcher", ")", ")", "{", "$", "this", "->", "commandsMatcher", "->", "setCommands", "(", "$", "this", "->", "all", "(", ")", ")", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Adds a command object. {@inheritdoc} @param BaseCommand $command A Symfony Console Command object @return BaseCommand The registered command
[ "Adds", "a", "command", "object", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L141-L158
bobthecow/psysh
src/Shell.php
Shell.getDefaultCommands
protected function getDefaultCommands() { $sudo = new Command\SudoCommand(); $sudo->setReadline($this->readline); $hist = new Command\HistoryCommand(); $hist->setReadline($this->readline); return [ new Command\HelpCommand(), new Command\ListCommand(), new Command\DumpCommand(), new Command\DocCommand(), new Command\ShowCommand($this->config->colorMode()), new Command\WtfCommand($this->config->colorMode()), new Command\WhereamiCommand($this->config->colorMode()), new Command\ThrowUpCommand(), new Command\TimeitCommand(), new Command\TraceCommand(), new Command\BufferCommand(), new Command\ClearCommand(), new Command\EditCommand($this->config->getRuntimeDir()), // new Command\PsyVersionCommand(), $sudo, $hist, new Command\ExitCommand(), ]; }
php
protected function getDefaultCommands() { $sudo = new Command\SudoCommand(); $sudo->setReadline($this->readline); $hist = new Command\HistoryCommand(); $hist->setReadline($this->readline); return [ new Command\HelpCommand(), new Command\ListCommand(), new Command\DumpCommand(), new Command\DocCommand(), new Command\ShowCommand($this->config->colorMode()), new Command\WtfCommand($this->config->colorMode()), new Command\WhereamiCommand($this->config->colorMode()), new Command\ThrowUpCommand(), new Command\TimeitCommand(), new Command\TraceCommand(), new Command\BufferCommand(), new Command\ClearCommand(), new Command\EditCommand($this->config->getRuntimeDir()), $sudo, $hist, new Command\ExitCommand(), ]; }
[ "protected", "function", "getDefaultCommands", "(", ")", "{", "$", "sudo", "=", "new", "Command", "\\", "SudoCommand", "(", ")", ";", "$", "sudo", "->", "setReadline", "(", "$", "this", "->", "readline", ")", ";", "$", "hist", "=", "new", "Command", "\\", "HistoryCommand", "(", ")", ";", "$", "hist", "->", "setReadline", "(", "$", "this", "->", "readline", ")", ";", "return", "[", "new", "Command", "\\", "HelpCommand", "(", ")", ",", "new", "Command", "\\", "ListCommand", "(", ")", ",", "new", "Command", "\\", "DumpCommand", "(", ")", ",", "new", "Command", "\\", "DocCommand", "(", ")", ",", "new", "Command", "\\", "ShowCommand", "(", "$", "this", "->", "config", "->", "colorMode", "(", ")", ")", ",", "new", "Command", "\\", "WtfCommand", "(", "$", "this", "->", "config", "->", "colorMode", "(", ")", ")", ",", "new", "Command", "\\", "WhereamiCommand", "(", "$", "this", "->", "config", "->", "colorMode", "(", ")", ")", ",", "new", "Command", "\\", "ThrowUpCommand", "(", ")", ",", "new", "Command", "\\", "TimeitCommand", "(", ")", ",", "new", "Command", "\\", "TraceCommand", "(", ")", ",", "new", "Command", "\\", "BufferCommand", "(", ")", ",", "new", "Command", "\\", "ClearCommand", "(", ")", ",", "new", "Command", "\\", "EditCommand", "(", "$", "this", "->", "config", "->", "getRuntimeDir", "(", ")", ")", ",", "// new Command\\PsyVersionCommand(),", "$", "sudo", ",", "$", "hist", ",", "new", "Command", "\\", "ExitCommand", "(", ")", ",", "]", ";", "}" ]
Gets the default commands that should always be available. @return array An array of default Command instances
[ "Gets", "the", "default", "commands", "that", "should", "always", "be", "available", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L178-L205
bobthecow/psysh
src/Shell.php
Shell.getDefaultLoopListeners
protected function getDefaultLoopListeners() { $listeners = []; if (ProcessForker::isSupported() && $this->config->usePcntl()) { $listeners[] = new ProcessForker(); } if (RunkitReloader::isSupported()) { $listeners[] = new RunkitReloader(); } return $listeners; }
php
protected function getDefaultLoopListeners() { $listeners = []; if (ProcessForker::isSupported() && $this->config->usePcntl()) { $listeners[] = new ProcessForker(); } if (RunkitReloader::isSupported()) { $listeners[] = new RunkitReloader(); } return $listeners; }
[ "protected", "function", "getDefaultLoopListeners", "(", ")", "{", "$", "listeners", "=", "[", "]", ";", "if", "(", "ProcessForker", "::", "isSupported", "(", ")", "&&", "$", "this", "->", "config", "->", "usePcntl", "(", ")", ")", "{", "$", "listeners", "[", "]", "=", "new", "ProcessForker", "(", ")", ";", "}", "if", "(", "RunkitReloader", "::", "isSupported", "(", ")", ")", "{", "$", "listeners", "[", "]", "=", "new", "RunkitReloader", "(", ")", ";", "}", "return", "$", "listeners", ";", "}" ]
Gets the default command loop listeners. @return array An array of Execution Loop Listener instances
[ "Gets", "the", "default", "command", "loop", "listeners", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L246-L259
bobthecow/psysh
src/Shell.php
Shell.addMatchers
public function addMatchers(array $matchers) { $this->matchers = \array_merge($this->matchers, $matchers); if (isset($this->autoCompleter)) { $this->addMatchersToAutoCompleter($matchers); } }
php
public function addMatchers(array $matchers) { $this->matchers = \array_merge($this->matchers, $matchers); if (isset($this->autoCompleter)) { $this->addMatchersToAutoCompleter($matchers); } }
[ "public", "function", "addMatchers", "(", "array", "$", "matchers", ")", "{", "$", "this", "->", "matchers", "=", "\\", "array_merge", "(", "$", "this", "->", "matchers", ",", "$", "matchers", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "autoCompleter", ")", ")", "{", "$", "this", "->", "addMatchersToAutoCompleter", "(", "$", "matchers", ")", ";", "}", "}" ]
Add tab completion matchers. @param array $matchers
[ "Add", "tab", "completion", "matchers", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L266-L273
bobthecow/psysh
src/Shell.php
Shell.run
public function run(InputInterface $input = null, OutputInterface $output = null) { $this->initializeTabCompletion(); if ($input === null && !isset($_SERVER['argv'])) { $input = new ArgvInput([]); } if ($output === null) { $output = $this->config->getOutput(); } try { return parent::run($input, $output); } catch (\Exception $e) { $this->writeException($e); } return 1; }
php
public function run(InputInterface $input = null, OutputInterface $output = null) { $this->initializeTabCompletion(); if ($input === null && !isset($_SERVER['argv'])) { $input = new ArgvInput([]); } if ($output === null) { $output = $this->config->getOutput(); } try { return parent::run($input, $output); } catch (\Exception $e) { $this->writeException($e); } return 1; }
[ "public", "function", "run", "(", "InputInterface", "$", "input", "=", "null", ",", "OutputInterface", "$", "output", "=", "null", ")", "{", "$", "this", "->", "initializeTabCompletion", "(", ")", ";", "if", "(", "$", "input", "===", "null", "&&", "!", "isset", "(", "$", "_SERVER", "[", "'argv'", "]", ")", ")", "{", "$", "input", "=", "new", "ArgvInput", "(", "[", "]", ")", ";", "}", "if", "(", "$", "output", "===", "null", ")", "{", "$", "output", "=", "$", "this", "->", "config", "->", "getOutput", "(", ")", ";", "}", "try", "{", "return", "parent", "::", "run", "(", "$", "input", ",", "$", "output", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "writeException", "(", "$", "e", ")", ";", "}", "return", "1", ";", "}" ]
Runs the current application. @param InputInterface $input An Input instance @param OutputInterface $output An Output instance @return int 0 if everything went fine, or an error code
[ "Runs", "the", "current", "application", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L303-L322
bobthecow/psysh
src/Shell.php
Shell.doRun
public function doRun(InputInterface $input, OutputInterface $output) { $this->setOutput($output); $this->resetCodeBuffer(); $this->setAutoExit(false); $this->setCatchExceptions(false); $this->readline->readHistory(); $this->output->writeln($this->getHeader()); $this->writeVersionInfo(); $this->writeStartupMessage(); try { $this->beforeRun(); $this->loop->run($this); $this->afterRun(); } catch (ThrowUpException $e) { throw $e->getPrevious(); } catch (BreakException $e) { // The ProcessForker throws a BreakException to finish the main thread. return; } }
php
public function doRun(InputInterface $input, OutputInterface $output) { $this->setOutput($output); $this->resetCodeBuffer(); $this->setAutoExit(false); $this->setCatchExceptions(false); $this->readline->readHistory(); $this->output->writeln($this->getHeader()); $this->writeVersionInfo(); $this->writeStartupMessage(); try { $this->beforeRun(); $this->loop->run($this); $this->afterRun(); } catch (ThrowUpException $e) { throw $e->getPrevious(); } catch (BreakException $e) { return; } }
[ "public", "function", "doRun", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "setOutput", "(", "$", "output", ")", ";", "$", "this", "->", "resetCodeBuffer", "(", ")", ";", "$", "this", "->", "setAutoExit", "(", "false", ")", ";", "$", "this", "->", "setCatchExceptions", "(", "false", ")", ";", "$", "this", "->", "readline", "->", "readHistory", "(", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "$", "this", "->", "getHeader", "(", ")", ")", ";", "$", "this", "->", "writeVersionInfo", "(", ")", ";", "$", "this", "->", "writeStartupMessage", "(", ")", ";", "try", "{", "$", "this", "->", "beforeRun", "(", ")", ";", "$", "this", "->", "loop", "->", "run", "(", "$", "this", ")", ";", "$", "this", "->", "afterRun", "(", ")", ";", "}", "catch", "(", "ThrowUpException", "$", "e", ")", "{", "throw", "$", "e", "->", "getPrevious", "(", ")", ";", "}", "catch", "(", "BreakException", "$", "e", ")", "{", "// The ProcessForker throws a BreakException to finish the main thread.", "return", ";", "}", "}" ]
Runs the current application. @throws Exception if thrown via the `throw-up` command @param InputInterface $input An Input instance @param OutputInterface $output An Output instance @return int 0 if everything went fine, or an error code
[ "Runs", "the", "current", "application", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L334-L359
bobthecow/psysh
src/Shell.php
Shell.getInput
public function getInput() { $this->codeBufferOpen = false; do { // reset output verbosity (in case it was altered by a subcommand) $this->output->setVerbosity(ShellOutput::VERBOSITY_VERBOSE); $input = $this->readline(); /* * Handle Ctrl+D. It behaves differently in different cases: * * 1) In an expression, like a function or "if" block, clear the input buffer * 2) At top-level session, behave like the exit command */ if ($input === false) { $this->output->writeln(''); if ($this->hasCode()) { $this->resetCodeBuffer(); } else { throw new BreakException('Ctrl+D'); } } // handle empty input if (\trim($input) === '' && !$this->codeBufferOpen) { continue; } $input = $this->onInput($input); // If the input isn't in an open string or comment, check for commands to run. if ($this->hasCommand($input) && !$this->inputInOpenStringOrComment($input)) { $this->addHistory($input); $this->runCommand($input); continue; } $this->addCode($input); } while (!$this->hasValidCode()); }
php
public function getInput() { $this->codeBufferOpen = false; do { $this->output->setVerbosity(ShellOutput::VERBOSITY_VERBOSE); $input = $this->readline(); if ($input === false) { $this->output->writeln(''); if ($this->hasCode()) { $this->resetCodeBuffer(); } else { throw new BreakException('Ctrl+D'); } } if (\trim($input) === '' && !$this->codeBufferOpen) { continue; } $input = $this->onInput($input); if ($this->hasCommand($input) && !$this->inputInOpenStringOrComment($input)) { $this->addHistory($input); $this->runCommand($input); continue; } $this->addCode($input); } while (!$this->hasValidCode()); }
[ "public", "function", "getInput", "(", ")", "{", "$", "this", "->", "codeBufferOpen", "=", "false", ";", "do", "{", "// reset output verbosity (in case it was altered by a subcommand)", "$", "this", "->", "output", "->", "setVerbosity", "(", "ShellOutput", "::", "VERBOSITY_VERBOSE", ")", ";", "$", "input", "=", "$", "this", "->", "readline", "(", ")", ";", "/*\n * Handle Ctrl+D. It behaves differently in different cases:\n *\n * 1) In an expression, like a function or \"if\" block, clear the input buffer\n * 2) At top-level session, behave like the exit command\n */", "if", "(", "$", "input", "===", "false", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "''", ")", ";", "if", "(", "$", "this", "->", "hasCode", "(", ")", ")", "{", "$", "this", "->", "resetCodeBuffer", "(", ")", ";", "}", "else", "{", "throw", "new", "BreakException", "(", "'Ctrl+D'", ")", ";", "}", "}", "// handle empty input", "if", "(", "\\", "trim", "(", "$", "input", ")", "===", "''", "&&", "!", "$", "this", "->", "codeBufferOpen", ")", "{", "continue", ";", "}", "$", "input", "=", "$", "this", "->", "onInput", "(", "$", "input", ")", ";", "// If the input isn't in an open string or comment, check for commands to run.", "if", "(", "$", "this", "->", "hasCommand", "(", "$", "input", ")", "&&", "!", "$", "this", "->", "inputInOpenStringOrComment", "(", "$", "input", ")", ")", "{", "$", "this", "->", "addHistory", "(", "$", "input", ")", ";", "$", "this", "->", "runCommand", "(", "$", "input", ")", ";", "continue", ";", "}", "$", "this", "->", "addCode", "(", "$", "input", ")", ";", "}", "while", "(", "!", "$", "this", "->", "hasValidCode", "(", ")", ")", ";", "}" ]
Read user input. This will continue fetching user input until the code buffer contains valid code. @throws BreakException if user hits Ctrl+D
[ "Read", "user", "input", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L369-L412
bobthecow/psysh
src/Shell.php
Shell.inputInOpenStringOrComment
private function inputInOpenStringOrComment($input) { if (!$this->hasCode()) { return; } $code = $this->codeBuffer; \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])); }
php
private function inputInOpenStringOrComment($input) { if (!$this->hasCode()) { return; } $code = $this->codeBuffer; \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])); }
[ "private", "function", "inputInOpenStringOrComment", "(", "$", "input", ")", "{", "if", "(", "!", "$", "this", "->", "hasCode", "(", ")", ")", "{", "return", ";", "}", "$", "code", "=", "$", "this", "->", "codeBuffer", ";", "\\", "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", "]", ")", ")", ";", "}" ]
Check whether the code buffer (plus current input) is in an open string or comment. @param string $input current line of input @return bool true if the input is in an open string or comment
[ "Check", "whether", "the", "code", "buffer", "(", "plus", "current", "input", ")", "is", "in", "an", "open", "string", "or", "comment", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L421-L434
bobthecow/psysh
src/Shell.php
Shell.onInput
public function onInput($input) { foreach ($this->loopListeners as $listeners) { if (($return = $listeners->onInput($this, $input)) !== null) { $input = $return; } } return $input; }
php
public function onInput($input) { foreach ($this->loopListeners as $listeners) { if (($return = $listeners->onInput($this, $input)) !== null) { $input = $return; } } return $input; }
[ "public", "function", "onInput", "(", "$", "input", ")", "{", "foreach", "(", "$", "this", "->", "loopListeners", "as", "$", "listeners", ")", "{", "if", "(", "(", "$", "return", "=", "$", "listeners", "->", "onInput", "(", "$", "this", ",", "$", "input", ")", ")", "!==", "null", ")", "{", "$", "input", "=", "$", "return", ";", "}", "}", "return", "$", "input", ";", "}" ]
Run execution loop listeners on user input. @param string $input @return string
[ "Run", "execution", "loop", "listeners", "on", "user", "input", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L463-L472
bobthecow/psysh
src/Shell.php
Shell.onExecute
public function onExecute($code) { foreach ($this->loopListeners as $listener) { if (($return = $listener->onExecute($this, $code)) !== null) { $code = $return; } } return $code; }
php
public function onExecute($code) { foreach ($this->loopListeners as $listener) { if (($return = $listener->onExecute($this, $code)) !== null) { $code = $return; } } return $code; }
[ "public", "function", "onExecute", "(", "$", "code", ")", "{", "foreach", "(", "$", "this", "->", "loopListeners", "as", "$", "listener", ")", "{", "if", "(", "(", "$", "return", "=", "$", "listener", "->", "onExecute", "(", "$", "this", ",", "$", "code", ")", ")", "!==", "null", ")", "{", "$", "code", "=", "$", "return", ";", "}", "}", "return", "$", "code", ";", "}" ]
Run execution loop listeners on code to be executed. @param string $code @return string
[ "Run", "execution", "loop", "listeners", "on", "code", "to", "be", "executed", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L481-L490
bobthecow/psysh
src/Shell.php
Shell.getScopeVariables
public function getScopeVariables($includeBoundObject = true) { $vars = $this->context->getAll(); if (!$includeBoundObject) { unset($vars['this']); } return $vars; }
php
public function getScopeVariables($includeBoundObject = true) { $vars = $this->context->getAll(); if (!$includeBoundObject) { unset($vars['this']); } return $vars; }
[ "public", "function", "getScopeVariables", "(", "$", "includeBoundObject", "=", "true", ")", "{", "$", "vars", "=", "$", "this", "->", "context", "->", "getAll", "(", ")", ";", "if", "(", "!", "$", "includeBoundObject", ")", "{", "unset", "(", "$", "vars", "[", "'this'", "]", ")", ";", "}", "return", "$", "vars", ";", "}" ]
Return the set of variables currently in scope. @param bool $includeBoundObject Pass false to exclude 'this'. If you're passing the scope variables to `extract` in PHP 7.1+, you _must_ exclude 'this' @return array Associative array of scope variables
[ "Return", "the", "set", "of", "variables", "currently", "in", "scope", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L531-L540
bobthecow/psysh
src/Shell.php
Shell.getSpecialScopeVariables
public function getSpecialScopeVariables($includeBoundObject = true) { $vars = $this->context->getSpecialVariables(); if (!$includeBoundObject) { unset($vars['this']); } return $vars; }
php
public function getSpecialScopeVariables($includeBoundObject = true) { $vars = $this->context->getSpecialVariables(); if (!$includeBoundObject) { unset($vars['this']); } return $vars; }
[ "public", "function", "getSpecialScopeVariables", "(", "$", "includeBoundObject", "=", "true", ")", "{", "$", "vars", "=", "$", "this", "->", "context", "->", "getSpecialVariables", "(", ")", ";", "if", "(", "!", "$", "includeBoundObject", ")", "{", "unset", "(", "$", "vars", "[", "'this'", "]", ")", ";", "}", "return", "$", "vars", ";", "}" ]
Return the set of magic variables currently in scope. @param bool $includeBoundObject Pass false to exclude 'this'. If you're passing the scope variables to `extract` in PHP 7.1+, you _must_ exclude 'this' @return array Associative array of magic scope variables
[ "Return", "the", "set", "of", "magic", "variables", "currently", "in", "scope", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L551-L560
bobthecow/psysh
src/Shell.php
Shell.getScopeVariablesDiff
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; }
php
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; }
[ "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", ";", "}" ]
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
[ "Return", "the", "set", "of", "variables", "currently", "in", "scope", "which", "differ", "from", "the", "values", "passed", "as", "$currentVars", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L573-L584
bobthecow/psysh
src/Shell.php
Shell.addCode
public function addCode($code, $silent = false) { try { // Code lines ending in \ keep the buffer open if (\substr(\rtrim($code), -1) === '\\') { $this->codeBufferOpen = true; $code = \substr(\rtrim($code), 0, -1); } else { $this->codeBufferOpen = false; } $this->codeBuffer[] = $silent ? new SilentInput($code) : $code; $this->code = $this->cleaner->clean($this->codeBuffer, $this->config->requireSemicolons()); } catch (\Exception $e) { // Add failed code blocks to the readline history. $this->addCodeBufferToHistory(); throw $e; } }
php
public function addCode($code, $silent = false) { try { if (\substr(\rtrim($code), -1) === '\\') { $this->codeBufferOpen = true; $code = \substr(\rtrim($code), 0, -1); } else { $this->codeBufferOpen = false; } $this->codeBuffer[] = $silent ? new SilentInput($code) : $code; $this->code = $this->cleaner->clean($this->codeBuffer, $this->config->requireSemicolons()); } catch (\Exception $e) { $this->addCodeBufferToHistory(); throw $e; } }
[ "public", "function", "addCode", "(", "$", "code", ",", "$", "silent", "=", "false", ")", "{", "try", "{", "// Code lines ending in \\ keep the buffer open", "if", "(", "\\", "substr", "(", "\\", "rtrim", "(", "$", "code", ")", ",", "-", "1", ")", "===", "'\\\\'", ")", "{", "$", "this", "->", "codeBufferOpen", "=", "true", ";", "$", "code", "=", "\\", "substr", "(", "\\", "rtrim", "(", "$", "code", ")", ",", "0", ",", "-", "1", ")", ";", "}", "else", "{", "$", "this", "->", "codeBufferOpen", "=", "false", ";", "}", "$", "this", "->", "codeBuffer", "[", "]", "=", "$", "silent", "?", "new", "SilentInput", "(", "$", "code", ")", ":", "$", "code", ";", "$", "this", "->", "code", "=", "$", "this", "->", "cleaner", "->", "clean", "(", "$", "this", "->", "codeBuffer", ",", "$", "this", "->", "config", "->", "requireSemicolons", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// Add failed code blocks to the readline history.", "$", "this", "->", "addCodeBufferToHistory", "(", ")", ";", "throw", "$", "e", ";", "}", "}" ]
Add code to the code buffer. @param string $code @param bool $silent
[ "Add", "code", "to", "the", "code", "buffer", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L706-L725
bobthecow/psysh
src/Shell.php
Shell.setCode
private function setCode($code, $silent = false) { if ($this->hasCode()) { $this->codeStack[] = [$this->codeBuffer, $this->codeBufferOpen, $this->code]; } $this->resetCodeBuffer(); try { $this->addCode($code, $silent); } catch (\Throwable $e) { $this->popCodeStack(); throw $e; } catch (\Exception $e) { $this->popCodeStack(); throw $e; } if (!$this->hasValidCode()) { $this->popCodeStack(); throw new \InvalidArgumentException('Unexpected end of input'); } }
php
private function setCode($code, $silent = false) { if ($this->hasCode()) { $this->codeStack[] = [$this->codeBuffer, $this->codeBufferOpen, $this->code]; } $this->resetCodeBuffer(); try { $this->addCode($code, $silent); } catch (\Throwable $e) { $this->popCodeStack(); throw $e; } catch (\Exception $e) { $this->popCodeStack(); throw $e; } if (!$this->hasValidCode()) { $this->popCodeStack(); throw new \InvalidArgumentException('Unexpected end of input'); } }
[ "private", "function", "setCode", "(", "$", "code", ",", "$", "silent", "=", "false", ")", "{", "if", "(", "$", "this", "->", "hasCode", "(", ")", ")", "{", "$", "this", "->", "codeStack", "[", "]", "=", "[", "$", "this", "->", "codeBuffer", ",", "$", "this", "->", "codeBufferOpen", ",", "$", "this", "->", "code", "]", ";", "}", "$", "this", "->", "resetCodeBuffer", "(", ")", ";", "try", "{", "$", "this", "->", "addCode", "(", "$", "code", ",", "$", "silent", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "this", "->", "popCodeStack", "(", ")", ";", "throw", "$", "e", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "popCodeStack", "(", ")", ";", "throw", "$", "e", ";", "}", "if", "(", "!", "$", "this", "->", "hasValidCode", "(", ")", ")", "{", "$", "this", "->", "popCodeStack", "(", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unexpected end of input'", ")", ";", "}", "}" ]
Set the code buffer. This is mostly used by `Shell::execute`. Any existing code in the input buffer is pushed onto a stack and will come back after this new code is executed. @throws \InvalidArgumentException if $code isn't a complete statement @param string $code @param bool $silent
[ "Set", "the", "code", "buffer", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L739-L763
bobthecow/psysh
src/Shell.php
Shell.runCommand
protected function runCommand($input) { $command = $this->getCommand($input); if (empty($command)) { throw new \InvalidArgumentException('Command not found: ' . $input); } $input = new ShellInput(\str_replace('\\', '\\\\', \rtrim($input, " \t\n\r\0\x0B;"))); if ($input->hasParameterOption(['--help', '-h'])) { $helpCommand = $this->get('help'); $helpCommand->setCommand($command); return $helpCommand->run($input, $this->output); } return $command->run($input, $this->output); }
php
protected function runCommand($input) { $command = $this->getCommand($input); if (empty($command)) { throw new \InvalidArgumentException('Command not found: ' . $input); } $input = new ShellInput(\str_replace('\\', '\\\\', \rtrim($input, " \t\n\r\0\x0B;"))); if ($input->hasParameterOption(['--help', '-h'])) { $helpCommand = $this->get('help'); $helpCommand->setCommand($command); return $helpCommand->run($input, $this->output); } return $command->run($input, $this->output); }
[ "protected", "function", "runCommand", "(", "$", "input", ")", "{", "$", "command", "=", "$", "this", "->", "getCommand", "(", "$", "input", ")", ";", "if", "(", "empty", "(", "$", "command", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Command not found: '", ".", "$", "input", ")", ";", "}", "$", "input", "=", "new", "ShellInput", "(", "\\", "str_replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ",", "\\", "rtrim", "(", "$", "input", ",", "\" \\t\\n\\r\\0\\x0B;\"", ")", ")", ")", ";", "if", "(", "$", "input", "->", "hasParameterOption", "(", "[", "'--help'", ",", "'-h'", "]", ")", ")", "{", "$", "helpCommand", "=", "$", "this", "->", "get", "(", "'help'", ")", ";", "$", "helpCommand", "->", "setCommand", "(", "$", "command", ")", ";", "return", "$", "helpCommand", "->", "run", "(", "$", "input", ",", "$", "this", "->", "output", ")", ";", "}", "return", "$", "command", "->", "run", "(", "$", "input", ",", "$", "this", "->", "output", ")", ";", "}" ]
Run a Psy Shell command given the user input. @throws InvalidArgumentException if the input is not a valid command @param string $input User input string @return mixed Who knows?
[ "Run", "a", "Psy", "Shell", "command", "given", "the", "user", "input", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L786-L804
bobthecow/psysh
src/Shell.php
Shell.addInput
public function addInput($input, $silent = false) { foreach ((array) $input as $line) { $this->inputBuffer[] = $silent ? new SilentInput($line) : $line; } }
php
public function addInput($input, $silent = false) { foreach ((array) $input as $line) { $this->inputBuffer[] = $silent ? new SilentInput($line) : $line; } }
[ "public", "function", "addInput", "(", "$", "input", ",", "$", "silent", "=", "false", ")", "{", "foreach", "(", "(", "array", ")", "$", "input", "as", "$", "line", ")", "{", "$", "this", "->", "inputBuffer", "[", "]", "=", "$", "silent", "?", "new", "SilentInput", "(", "$", "line", ")", ":", "$", "line", ";", "}", "}" ]
Inject input into the input buffer. This is useful for commands which want to replay history. @param string|array $input @param bool $silent
[ "Inject", "input", "into", "the", "input", "buffer", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L826-L831
bobthecow/psysh
src/Shell.php
Shell.flushCode
public function flushCode() { if ($this->hasValidCode()) { $this->addCodeBufferToHistory(); $code = $this->code; $this->popCodeStack(); return $code; } }
php
public function flushCode() { if ($this->hasValidCode()) { $this->addCodeBufferToHistory(); $code = $this->code; $this->popCodeStack(); return $code; } }
[ "public", "function", "flushCode", "(", ")", "{", "if", "(", "$", "this", "->", "hasValidCode", "(", ")", ")", "{", "$", "this", "->", "addCodeBufferToHistory", "(", ")", ";", "$", "code", "=", "$", "this", "->", "code", ";", "$", "this", "->", "popCodeStack", "(", ")", ";", "return", "$", "code", ";", "}", "}" ]
Flush the current (valid) code buffer. If the code buffer is valid, resets the code buffer and returns the current code. @return string PHP code buffer contents
[ "Flush", "the", "current", "(", "valid", ")", "code", "buffer", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L841-L850
bobthecow/psysh
src/Shell.php
Shell.popCodeStack
private function popCodeStack() { $this->resetCodeBuffer(); if (empty($this->codeStack)) { return; } list($codeBuffer, $codeBufferOpen, $code) = \array_pop($this->codeStack); $this->codeBuffer = $codeBuffer; $this->codeBufferOpen = $codeBufferOpen; $this->code = $code; }
php
private function popCodeStack() { $this->resetCodeBuffer(); if (empty($this->codeStack)) { return; } list($codeBuffer, $codeBufferOpen, $code) = \array_pop($this->codeStack); $this->codeBuffer = $codeBuffer; $this->codeBufferOpen = $codeBufferOpen; $this->code = $code; }
[ "private", "function", "popCodeStack", "(", ")", "{", "$", "this", "->", "resetCodeBuffer", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "codeStack", ")", ")", "{", "return", ";", "}", "list", "(", "$", "codeBuffer", ",", "$", "codeBufferOpen", ",", "$", "code", ")", "=", "\\", "array_pop", "(", "$", "this", "->", "codeStack", ")", ";", "$", "this", "->", "codeBuffer", "=", "$", "codeBuffer", ";", "$", "this", "->", "codeBufferOpen", "=", "$", "codeBufferOpen", ";", "$", "this", "->", "code", "=", "$", "code", ";", "}" ]
Reset the code buffer and restore any code pushed during `execute` calls.
[ "Reset", "the", "code", "buffer", "and", "restore", "any", "code", "pushed", "during", "execute", "calls", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L855-L868
bobthecow/psysh
src/Shell.php
Shell.addHistory
private function addHistory($line) { if ($line instanceof SilentInput) { return; } // Skip empty lines and lines starting with a space if (\trim($line) !== '' && \substr($line, 0, 1) !== ' ') { $this->readline->addHistory($line); } }
php
private function addHistory($line) { if ($line instanceof SilentInput) { return; } if (\trim($line) !== '' && \substr($line, 0, 1) !== ' ') { $this->readline->addHistory($line); } }
[ "private", "function", "addHistory", "(", "$", "line", ")", "{", "if", "(", "$", "line", "instanceof", "SilentInput", ")", "{", "return", ";", "}", "// Skip empty lines and lines starting with a space", "if", "(", "\\", "trim", "(", "$", "line", ")", "!==", "''", "&&", "\\", "substr", "(", "$", "line", ",", "0", ",", "1", ")", "!==", "' '", ")", "{", "$", "this", "->", "readline", "->", "addHistory", "(", "$", "line", ")", ";", "}", "}" ]
(Possibly) add a line to the readline history. Like Bash, if the line starts with a space character, it will be omitted from history. Note that an entire block multi-line code input will be omitted iff the first line begins with a space. Additionally, if a line is "silent", i.e. it was initially added with the silent flag, it will also be omitted. @param string|SilentInput $line
[ "(", "Possibly", ")", "add", "a", "line", "to", "the", "readline", "history", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L882-L892
bobthecow/psysh
src/Shell.php
Shell.addCodeBufferToHistory
private function addCodeBufferToHistory() { $codeBuffer = \array_filter($this->codeBuffer, function ($line) { return !$line instanceof SilentInput; }); $this->addHistory(\implode("\n", $codeBuffer)); }
php
private function addCodeBufferToHistory() { $codeBuffer = \array_filter($this->codeBuffer, function ($line) { return !$line instanceof SilentInput; }); $this->addHistory(\implode("\n", $codeBuffer)); }
[ "private", "function", "addCodeBufferToHistory", "(", ")", "{", "$", "codeBuffer", "=", "\\", "array_filter", "(", "$", "this", "->", "codeBuffer", ",", "function", "(", "$", "line", ")", "{", "return", "!", "$", "line", "instanceof", "SilentInput", ";", "}", ")", ";", "$", "this", "->", "addHistory", "(", "\\", "implode", "(", "\"\\n\"", ",", "$", "codeBuffer", ")", ")", ";", "}" ]
Filter silent input from code buffer, write the rest to readline history.
[ "Filter", "silent", "input", "from", "code", "buffer", "write", "the", "rest", "to", "readline", "history", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L897-L904
bobthecow/psysh
src/Shell.php
Shell.writeStdout
public function writeStdout($out, $phase = PHP_OUTPUT_HANDLER_END) { $isCleaning = $phase & PHP_OUTPUT_HANDLER_CLEAN; // Incremental flush if ($out !== '' && !$isCleaning) { $this->output->write($out, false, ShellOutput::OUTPUT_RAW); $this->outputWantsNewline = (\substr($out, -1) !== "\n"); $this->stdoutBuffer .= $out; } // Output buffering is done! 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->outputWantsNewline = false; } // Save the stdout buffer as $__out if ($this->stdoutBuffer !== '') { $this->context->setLastStdout($this->stdoutBuffer); $this->stdoutBuffer = ''; } } }
php
public function writeStdout($out, $phase = PHP_OUTPUT_HANDLER_END) { $isCleaning = $phase & PHP_OUTPUT_HANDLER_CLEAN; if ($out !== '' && !$isCleaning) { $this->output->write($out, false, ShellOutput::OUTPUT_RAW); $this->outputWantsNewline = (\substr($out, -1) !== "\n"); $this->stdoutBuffer .= $out; } if ($phase & PHP_OUTPUT_HANDLER_END) { if ($this->outputWantsNewline) { $this->output->writeln(\sprintf('<aside>%s</aside>', $this->config->useUnicode() ? '⏎' : '\\n')); $this->outputWantsNewline = false; } if ($this->stdoutBuffer !== '') { $this->context->setLastStdout($this->stdoutBuffer); $this->stdoutBuffer = ''; } } }
[ "public", "function", "writeStdout", "(", "$", "out", ",", "$", "phase", "=", "PHP_OUTPUT_HANDLER_END", ")", "{", "$", "isCleaning", "=", "$", "phase", "&", "PHP_OUTPUT_HANDLER_CLEAN", ";", "// Incremental flush", "if", "(", "$", "out", "!==", "''", "&&", "!", "$", "isCleaning", ")", "{", "$", "this", "->", "output", "->", "write", "(", "$", "out", ",", "false", ",", "ShellOutput", "::", "OUTPUT_RAW", ")", ";", "$", "this", "->", "outputWantsNewline", "=", "(", "\\", "substr", "(", "$", "out", ",", "-", "1", ")", "!==", "\"\\n\"", ")", ";", "$", "this", "->", "stdoutBuffer", ".=", "$", "out", ";", "}", "// Output buffering is done!", "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", "->", "outputWantsNewline", "=", "false", ";", "}", "// Save the stdout buffer as $__out", "if", "(", "$", "this", "->", "stdoutBuffer", "!==", "''", ")", "{", "$", "this", "->", "context", "->", "setLastStdout", "(", "$", "this", "->", "stdoutBuffer", ")", ";", "$", "this", "->", "stdoutBuffer", "=", "''", ";", "}", "}", "}" ]
Write a string to stdout. This is used by the shell loop for rendering output from evaluated code. @param string $out @param int $phase Output buffering phase
[ "Write", "a", "string", "to", "stdout", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L928-L953
bobthecow/psysh
src/Shell.php
Shell.writeReturnValue
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)); $this->output->writeln(static::RETVAL . \str_replace(PHP_EOL, PHP_EOL . $indent, $ret)); }
php
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)); $this->output->writeln(static::RETVAL . \str_replace(PHP_EOL, PHP_EOL . $indent, $ret)); }
[ "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", ")", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "static", "::", "RETVAL", ".", "\\", "str_replace", "(", "PHP_EOL", ",", "PHP_EOL", ".", "$", "indent", ",", "$", "ret", ")", ")", ";", "}" ]
Write a return value to stdout. The return value is formatted or pretty-printed, and rendered in a visibly distinct manner (in this case, as cyan). @see self::presentValue @param mixed $ret
[ "Write", "a", "return", "value", "to", "stdout", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L965-L978
bobthecow/psysh
src/Shell.php
Shell.writeException
public function writeException(\Exception $e) { $this->lastExecSuccess = false; $this->context->setLastException($e); $this->output->writeln($this->formatException($e)); $this->resetCodeBuffer(); }
php
public function writeException(\Exception $e) { $this->lastExecSuccess = false; $this->context->setLastException($e); $this->output->writeln($this->formatException($e)); $this->resetCodeBuffer(); }
[ "public", "function", "writeException", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "lastExecSuccess", "=", "false", ";", "$", "this", "->", "context", "->", "setLastException", "(", "$", "e", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "$", "this", "->", "formatException", "(", "$", "e", ")", ")", ";", "$", "this", "->", "resetCodeBuffer", "(", ")", ";", "}" ]
Renders a caught Exception. Exceptions are formatted according to severity. ErrorExceptions which were warnings or Strict errors aren't rendered as harshly as real errors. Stores $e as the last Exception in the Shell Context. @param \Exception $e An exception instance
[ "Renders", "a", "caught", "Exception", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L990-L996
bobthecow/psysh
src/Shell.php
Shell.formatException
public function formatException(\Exception $e) { $message = $e->getMessage(); if (!$e instanceof PsyException) { if ($message === '') { $message = \get_class($e); } else { $message = \sprintf('%s with message \'%s\'', \get_class($e), $message); } } $message = \preg_replace( "#(\\w:)?(/\\w+)*/src/Execution(?:Loop)?Closure.php\(\d+\) : eval\(\)'d code#", "eval()'d code", \str_replace('\\', '/', $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); }
php
public function formatException(\Exception $e) { $message = $e->getMessage(); if (!$e instanceof PsyException) { if ($message === '') { $message = \get_class($e); } else { $message = \sprintf('%s with message \'%s\'', \get_class($e), $message); } } $message = \preg_replace( " "eval()'d code", \str_replace('\\', '/', $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); }
[ "public", "function", "formatException", "(", "\\", "Exception", "$", "e", ")", "{", "$", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "if", "(", "!", "$", "e", "instanceof", "PsyException", ")", "{", "if", "(", "$", "message", "===", "''", ")", "{", "$", "message", "=", "\\", "get_class", "(", "$", "e", ")", ";", "}", "else", "{", "$", "message", "=", "\\", "sprintf", "(", "'%s with message \\'%s\\''", ",", "\\", "get_class", "(", "$", "e", ")", ",", "$", "message", ")", ";", "}", "}", "$", "message", "=", "\\", "preg_replace", "(", "\"#(\\\\w:)?(/\\\\w+)*/src/Execution(?:Loop)?Closure.php\\(\\d+\\) : eval\\(\\)'d code#\"", ",", "\"eval()'d code\"", ",", "\\", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "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", ")", ";", "}" ]
Helper for formatting an exception for writeException(). @todo extract this to somewhere it makes more sense @param \Exception $e @return string
[ "Helper", "for", "formatting", "an", "exception", "for", "writeException", "()", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1019-L1041
bobthecow/psysh
src/Shell.php
Shell.getSeverity
protected function getSeverity(\ErrorException $e) { $severity = $e->getSeverity(); if ($severity & \error_reporting()) { switch ($severity) { case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: return 'warning'; default: return 'error'; } } else { // Since this is below the user's reporting threshold, it's always going to be a warning. return 'warning'; } }
php
protected function getSeverity(\ErrorException $e) { $severity = $e->getSeverity(); if ($severity & \error_reporting()) { switch ($severity) { case E_WARNING: case E_NOTICE: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: return 'warning'; default: return 'error'; } } else { return 'warning'; } }
[ "protected", "function", "getSeverity", "(", "\\", "ErrorException", "$", "e", ")", "{", "$", "severity", "=", "$", "e", "->", "getSeverity", "(", ")", ";", "if", "(", "$", "severity", "&", "\\", "error_reporting", "(", ")", ")", "{", "switch", "(", "$", "severity", ")", "{", "case", "E_WARNING", ":", "case", "E_NOTICE", ":", "case", "E_CORE_WARNING", ":", "case", "E_COMPILE_WARNING", ":", "case", "E_USER_WARNING", ":", "case", "E_USER_NOTICE", ":", "case", "E_STRICT", ":", "return", "'warning'", ";", "default", ":", "return", "'error'", ";", "}", "}", "else", "{", "// Since this is below the user's reporting threshold, it's always going to be a warning.", "return", "'warning'", ";", "}", "}" ]
Helper for getting an output style for the given ErrorException's level. @param \ErrorException $e @return string
[ "Helper", "for", "getting", "an", "output", "style", "for", "the", "given", "ErrorException", "s", "level", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1050-L1071
bobthecow/psysh
src/Shell.php
Shell.execute
public function execute($code, $throwExceptions = false) { $this->setCode($code, true); $closure = new ExecutionClosure($this); if ($throwExceptions) { return $closure->execute(); } try { return $closure->execute(); } catch (\TypeError $_e) { $this->writeException(TypeErrorException::fromTypeError($_e)); } catch (\Error $_e) { $this->writeException(ErrorException::fromError($_e)); } catch (\Exception $_e) { $this->writeException($_e); } }
php
public function execute($code, $throwExceptions = false) { $this->setCode($code, true); $closure = new ExecutionClosure($this); if ($throwExceptions) { return $closure->execute(); } try { return $closure->execute(); } catch (\TypeError $_e) { $this->writeException(TypeErrorException::fromTypeError($_e)); } catch (\Error $_e) { $this->writeException(ErrorException::fromError($_e)); } catch (\Exception $_e) { $this->writeException($_e); } }
[ "public", "function", "execute", "(", "$", "code", ",", "$", "throwExceptions", "=", "false", ")", "{", "$", "this", "->", "setCode", "(", "$", "code", ",", "true", ")", ";", "$", "closure", "=", "new", "ExecutionClosure", "(", "$", "this", ")", ";", "if", "(", "$", "throwExceptions", ")", "{", "return", "$", "closure", "->", "execute", "(", ")", ";", "}", "try", "{", "return", "$", "closure", "->", "execute", "(", ")", ";", "}", "catch", "(", "\\", "TypeError", "$", "_e", ")", "{", "$", "this", "->", "writeException", "(", "TypeErrorException", "::", "fromTypeError", "(", "$", "_e", ")", ")", ";", "}", "catch", "(", "\\", "Error", "$", "_e", ")", "{", "$", "this", "->", "writeException", "(", "ErrorException", "::", "fromError", "(", "$", "_e", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "_e", ")", "{", "$", "this", "->", "writeException", "(", "$", "_e", ")", ";", "}", "}" ]
Execute code in the shell execution context. @param string $code @param bool $throwExceptions @return mixed
[ "Execute", "code", "in", "the", "shell", "execution", "context", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1081-L1099
bobthecow/psysh
src/Shell.php
Shell.handleError
public function handleError($errno, $errstr, $errfile, $errline) { if ($errno & \error_reporting()) { ErrorException::throwException($errno, $errstr, $errfile, $errline); } elseif ($errno & $this->config->errorLoggingLevel()) { // log it and continue... $this->writeException(new ErrorException($errstr, 0, $errno, $errfile, $errline)); } }
php
public function handleError($errno, $errstr, $errfile, $errline) { if ($errno & \error_reporting()) { ErrorException::throwException($errno, $errstr, $errfile, $errline); } elseif ($errno & $this->config->errorLoggingLevel()) { $this->writeException(new ErrorException($errstr, 0, $errno, $errfile, $errline)); } }
[ "public", "function", "handleError", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ")", "{", "if", "(", "$", "errno", "&", "\\", "error_reporting", "(", ")", ")", "{", "ErrorException", "::", "throwException", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ")", ";", "}", "elseif", "(", "$", "errno", "&", "$", "this", "->", "config", "->", "errorLoggingLevel", "(", ")", ")", "{", "// log it and continue...", "$", "this", "->", "writeException", "(", "new", "ErrorException", "(", "$", "errstr", ",", "0", ",", "$", "errno", ",", "$", "errfile", ",", "$", "errline", ")", ")", ";", "}", "}" ]
Helper for throwing an ErrorException. This allows us to: set_error_handler(array($psysh, 'handleError')); Unlike ErrorException::throwException, this error handler respects the current error_reporting level; i.e. it logs warnings and notices, but doesn't throw an exception unless it's above the current error_reporting 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 @param int $errline Line number
[ "Helper", "for", "throwing", "an", "ErrorException", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1127-L1135
bobthecow/psysh
src/Shell.php
Shell.getCommand
protected function getCommand($input) { $input = new StringInput($input); if ($name = $input->getFirstArgument()) { return $this->get($name); } }
php
protected function getCommand($input) { $input = new StringInput($input); if ($name = $input->getFirstArgument()) { return $this->get($name); } }
[ "protected", "function", "getCommand", "(", "$", "input", ")", "{", "$", "input", "=", "new", "StringInput", "(", "$", "input", ")", ";", "if", "(", "$", "name", "=", "$", "input", "->", "getFirstArgument", "(", ")", ")", "{", "return", "$", "this", "->", "get", "(", "$", "name", ")", ";", "}", "}" ]
Get a command (if one exists) for the current input string. @param string $input @return null|BaseCommand
[ "Get", "a", "command", "(", "if", "one", "exists", ")", "for", "the", "current", "input", "string", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1158-L1164
bobthecow/psysh
src/Shell.php
Shell.hasCommand
protected function hasCommand($input) { if (\preg_match('/([^\s]+?)(?:\s|$)/A', \ltrim($input), $match)) { return $this->has($match[1]); } return false; }
php
protected function hasCommand($input) { if (\preg_match('/([^\s]+?)(?:\s|$)/A', \ltrim($input), $match)) { return $this->has($match[1]); } return false; }
[ "protected", "function", "hasCommand", "(", "$", "input", ")", "{", "if", "(", "\\", "preg_match", "(", "'/([^\\s]+?)(?:\\s|$)/A'", ",", "\\", "ltrim", "(", "$", "input", ")", ",", "$", "match", ")", ")", "{", "return", "$", "this", "->", "has", "(", "$", "match", "[", "1", "]", ")", ";", "}", "return", "false", ";", "}" ]
Check whether a command is set for the current input string. @param string $input @return bool True if the shell has a command for the given input
[ "Check", "whether", "a", "command", "is", "set", "for", "the", "current", "input", "string", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1173-L1180
bobthecow/psysh
src/Shell.php
Shell.readline
protected function readline() { if (!empty($this->inputBuffer)) { $line = \array_shift($this->inputBuffer); if (!$line instanceof SilentInput) { $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 } $line = $this->readline->readline($this->getPrompt()); if ($bracketedPaste) { \printf("\e[?2004l"); // ... and disable it again } return $line; }
php
protected function readline() { if (!empty($this->inputBuffer)) { $line = \array_shift($this->inputBuffer); if (!$line instanceof SilentInput) { $this->output->writeln(\sprintf('<aside>%s %s</aside>', static::REPLAY, OutputFormatter::escape($line))); } return $line; } if ($bracketedPaste = $this->config->useBracketedPaste()) { \printf("\e[?2004h"); } $line = $this->readline->readline($this->getPrompt()); if ($bracketedPaste) { \printf("\e[?2004l"); } return $line; }
[ "protected", "function", "readline", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "inputBuffer", ")", ")", "{", "$", "line", "=", "\\", "array_shift", "(", "$", "this", "->", "inputBuffer", ")", ";", "if", "(", "!", "$", "line", "instanceof", "SilentInput", ")", "{", "$", "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", "}", "$", "line", "=", "$", "this", "->", "readline", "->", "readline", "(", "$", "this", "->", "getPrompt", "(", ")", ")", ";", "if", "(", "$", "bracketedPaste", ")", "{", "\\", "printf", "(", "\"\\e[?2004l\"", ")", ";", "// ... and disable it again", "}", "return", "$", "line", ";", "}" ]
Read a line of user input. This will return a line from the input buffer (if any exist). Otherwise, it will ask the user for input. If readline is enabled, this delegates to readline. Otherwise, it's an ugly `fgets` call. @return string One line of user input
[ "Read", "a", "line", "of", "user", "input", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1207-L1229
bobthecow/psysh
src/Shell.php
Shell.getVersion
public function getVersion() { $separator = $this->config->useUnicode() ? '—' : '-'; return \sprintf('Psy Shell %s (PHP %s %s %s)', self::VERSION, PHP_VERSION, $separator, PHP_SAPI); }
php
public function getVersion() { $separator = $this->config->useUnicode() ? '—' : '-'; return \sprintf('Psy Shell %s (PHP %s %s %s)', self::VERSION, PHP_VERSION, $separator, PHP_SAPI); }
[ "public", "function", "getVersion", "(", ")", "{", "$", "separator", "=", "$", "this", "->", "config", "->", "useUnicode", "(", ")", "?", "'—' :", "'", "';", "", "return", "\\", "sprintf", "(", "'Psy Shell %s (PHP %s %s %s)'", ",", "self", "::", "VERSION", ",", "PHP_VERSION", ",", "$", "separator", ",", "PHP_SAPI", ")", ";", "}" ]
Get the current version of Psy Shell. @return string
[ "Get", "the", "current", "version", "of", "Psy", "Shell", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1246-L1251
bobthecow/psysh
src/Shell.php
Shell.initializeTabCompletion
protected function initializeTabCompletion() { if (!$this->config->useTabCompletion()) { return; } $this->autoCompleter = $this->config->getAutoCompleter(); // auto completer needs shell to be linked to configuration because of // the context aware matchers $this->addMatchersToAutoCompleter($this->getDefaultMatchers()); $this->addMatchersToAutoCompleter($this->matchers); $this->autoCompleter->activate(); }
php
protected function initializeTabCompletion() { if (!$this->config->useTabCompletion()) { return; } $this->autoCompleter = $this->config->getAutoCompleter(); $this->addMatchersToAutoCompleter($this->getDefaultMatchers()); $this->addMatchersToAutoCompleter($this->matchers); $this->autoCompleter->activate(); }
[ "protected", "function", "initializeTabCompletion", "(", ")", "{", "if", "(", "!", "$", "this", "->", "config", "->", "useTabCompletion", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "autoCompleter", "=", "$", "this", "->", "config", "->", "getAutoCompleter", "(", ")", ";", "// auto completer needs shell to be linked to configuration because of", "// the context aware matchers", "$", "this", "->", "addMatchersToAutoCompleter", "(", "$", "this", "->", "getDefaultMatchers", "(", ")", ")", ";", "$", "this", "->", "addMatchersToAutoCompleter", "(", "$", "this", "->", "matchers", ")", ";", "$", "this", "->", "autoCompleter", "->", "activate", "(", ")", ";", "}" ]
Initialize tab completion matchers. If tab completion is enabled this adds tab completion matchers to the auto completer and sets context if needed.
[ "Initialize", "tab", "completion", "matchers", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1277-L1291
bobthecow/psysh
src/Shell.php
Shell.addMatchersToAutoCompleter
private function addMatchersToAutoCompleter(array $matchers) { foreach ($matchers as $matcher) { if ($matcher instanceof ContextAware) { $matcher->setContext($this->context); } $this->autoCompleter->addMatcher($matcher); } }
php
private function addMatchersToAutoCompleter(array $matchers) { foreach ($matchers as $matcher) { if ($matcher instanceof ContextAware) { $matcher->setContext($this->context); } $this->autoCompleter->addMatcher($matcher); } }
[ "private", "function", "addMatchersToAutoCompleter", "(", "array", "$", "matchers", ")", "{", "foreach", "(", "$", "matchers", "as", "$", "matcher", ")", "{", "if", "(", "$", "matcher", "instanceof", "ContextAware", ")", "{", "$", "matcher", "->", "setContext", "(", "$", "this", "->", "context", ")", ";", "}", "$", "this", "->", "autoCompleter", "->", "addMatcher", "(", "$", "matcher", ")", ";", "}", "}" ]
Add matchers to the auto completer, setting context if needed. @param array $matchers
[ "Add", "matchers", "to", "the", "auto", "completer", "setting", "context", "if", "needed", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1298-L1306
bobthecow/psysh
src/Shell.php
Shell.writeVersionInfo
protected function writeVersionInfo() { if (PHP_SAPI !== 'cli') { return; } try { $client = $this->config->getChecker(); if (!$client->isLatest()) { $this->output->writeln(\sprintf('New version is available (current: %s, latest: %s)', self::VERSION, $client->getLatest())); } } catch (\InvalidArgumentException $e) { $this->output->writeln($e->getMessage()); } }
php
protected function writeVersionInfo() { if (PHP_SAPI !== 'cli') { return; } try { $client = $this->config->getChecker(); if (!$client->isLatest()) { $this->output->writeln(\sprintf('New version is available (current: %s, latest: %s)', self::VERSION, $client->getLatest())); } } catch (\InvalidArgumentException $e) { $this->output->writeln($e->getMessage()); } }
[ "protected", "function", "writeVersionInfo", "(", ")", "{", "if", "(", "PHP_SAPI", "!==", "'cli'", ")", "{", "return", ";", "}", "try", "{", "$", "client", "=", "$", "this", "->", "config", "->", "getChecker", "(", ")", ";", "if", "(", "!", "$", "client", "->", "isLatest", "(", ")", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "\\", "sprintf", "(", "'New version is available (current: %s, latest: %s)'", ",", "self", "::", "VERSION", ",", "$", "client", "->", "getLatest", "(", ")", ")", ")", ";", "}", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
@todo Implement self-update @todo Implement prompt to start update @return void|string
[ "@todo", "Implement", "self", "-", "update", "@todo", "Implement", "prompt", "to", "start", "update" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1314-L1328
bobthecow/psysh
src/Shell.php
Shell.writeStartupMessage
protected function writeStartupMessage() { $message = $this->config->getStartupMessage(); if ($message !== null && $message !== '') { $this->output->writeln($message); } }
php
protected function writeStartupMessage() { $message = $this->config->getStartupMessage(); if ($message !== null && $message !== '') { $this->output->writeln($message); } }
[ "protected", "function", "writeStartupMessage", "(", ")", "{", "$", "message", "=", "$", "this", "->", "config", "->", "getStartupMessage", "(", ")", ";", "if", "(", "$", "message", "!==", "null", "&&", "$", "message", "!==", "''", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "$", "message", ")", ";", "}", "}" ]
Write a startup message if set.
[ "Write", "a", "startup", "message", "if", "set", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Shell.php#L1333-L1339
bobthecow/psysh
src/Command/HelpCommand.php
HelpCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { if ($this->command !== null) { // help for an individual command $output->page($this->command->asText()); $this->command = null; } elseif ($name = $input->getArgument('command_name')) { // help for an individual command $output->page($this->getApplication()->get($name)->asText()); } else { // list available commands $commands = $this->getApplication()->all(); $table = $this->getTable($output); foreach ($commands as $name => $command) { if ($name !== $command->getName()) { continue; } if ($command->getAliases()) { $aliases = \sprintf('<comment>Aliases:</comment> %s', \implode(', ', $command->getAliases())); } else { $aliases = ''; } $table->addRow([ \sprintf('<info>%s</info>', $name), $command->getDescription(), $aliases, ]); } $output->startPaging(); if ($table instanceof TableHelper) { $table->render($output); } else { $table->render(); } $output->stopPaging(); } }
php
protected function execute(InputInterface $input, OutputInterface $output) { if ($this->command !== null) { $output->page($this->command->asText()); $this->command = null; } elseif ($name = $input->getArgument('command_name')) { $output->page($this->getApplication()->get($name)->asText()); } else { $commands = $this->getApplication()->all(); $table = $this->getTable($output); foreach ($commands as $name => $command) { if ($name !== $command->getName()) { continue; } if ($command->getAliases()) { $aliases = \sprintf('<comment>Aliases:</comment> %s', \implode(', ', $command->getAliases())); } else { $aliases = ''; } $table->addRow([ \sprintf('<info>%s</info>', $name), $command->getDescription(), $aliases, ]); } $output->startPaging(); if ($table instanceof TableHelper) { $table->render($output); } else { $table->render(); } $output->stopPaging(); } }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "if", "(", "$", "this", "->", "command", "!==", "null", ")", "{", "// help for an individual command", "$", "output", "->", "page", "(", "$", "this", "->", "command", "->", "asText", "(", ")", ")", ";", "$", "this", "->", "command", "=", "null", ";", "}", "elseif", "(", "$", "name", "=", "$", "input", "->", "getArgument", "(", "'command_name'", ")", ")", "{", "// help for an individual command", "$", "output", "->", "page", "(", "$", "this", "->", "getApplication", "(", ")", "->", "get", "(", "$", "name", ")", "->", "asText", "(", ")", ")", ";", "}", "else", "{", "// list available commands", "$", "commands", "=", "$", "this", "->", "getApplication", "(", ")", "->", "all", "(", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", "$", "output", ")", ";", "foreach", "(", "$", "commands", "as", "$", "name", "=>", "$", "command", ")", "{", "if", "(", "$", "name", "!==", "$", "command", "->", "getName", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "command", "->", "getAliases", "(", ")", ")", "{", "$", "aliases", "=", "\\", "sprintf", "(", "'<comment>Aliases:</comment> %s'", ",", "\\", "implode", "(", "', '", ",", "$", "command", "->", "getAliases", "(", ")", ")", ")", ";", "}", "else", "{", "$", "aliases", "=", "''", ";", "}", "$", "table", "->", "addRow", "(", "[", "\\", "sprintf", "(", "'<info>%s</info>'", ",", "$", "name", ")", ",", "$", "command", "->", "getDescription", "(", ")", ",", "$", "aliases", ",", "]", ")", ";", "}", "$", "output", "->", "startPaging", "(", ")", ";", "if", "(", "$", "table", "instanceof", "TableHelper", ")", "{", "$", "table", "->", "render", "(", "$", "output", ")", ";", "}", "else", "{", "$", "table", "->", "render", "(", ")", ";", "}", "$", "output", "->", "stopPaging", "(", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/HelpCommand.php#L56-L97
bobthecow/psysh
src/TabCompletion/Matcher/MongoClientMatcher.php
MongoClientMatcher.getMatches
public function getMatches(array $tokens, array $info = []) { $input = $this->getInput($tokens); $firstToken = \array_pop($tokens); if (self::tokenIs($firstToken, self::T_STRING)) { // second token is the object operator \array_pop($tokens); } $objectToken = \array_pop($tokens); $objectName = \str_replace('$', '', $objectToken[1]); $object = $this->getVariable($objectName); if (!$object instanceof \MongoClient) { return []; } $list = $object->listDBs(); return \array_filter( \array_map(function ($info) { return $info['name']; }, $list['databases']), function ($var) use ($input) { return AbstractMatcher::startsWith($input, $var); } ); }
php
public function getMatches(array $tokens, array $info = []) { $input = $this->getInput($tokens); $firstToken = \array_pop($tokens); if (self::tokenIs($firstToken, self::T_STRING)) { \array_pop($tokens); } $objectToken = \array_pop($tokens); $objectName = \str_replace('$', '', $objectToken[1]); $object = $this->getVariable($objectName); if (!$object instanceof \MongoClient) { return []; } $list = $object->listDBs(); return \array_filter( \array_map(function ($info) { return $info['name']; }, $list['databases']), function ($var) use ($input) { return AbstractMatcher::startsWith($input, $var); } ); }
[ "public", "function", "getMatches", "(", "array", "$", "tokens", ",", "array", "$", "info", "=", "[", "]", ")", "{", "$", "input", "=", "$", "this", "->", "getInput", "(", "$", "tokens", ")", ";", "$", "firstToken", "=", "\\", "array_pop", "(", "$", "tokens", ")", ";", "if", "(", "self", "::", "tokenIs", "(", "$", "firstToken", ",", "self", "::", "T_STRING", ")", ")", "{", "// second token is the object operator", "\\", "array_pop", "(", "$", "tokens", ")", ";", "}", "$", "objectToken", "=", "\\", "array_pop", "(", "$", "tokens", ")", ";", "$", "objectName", "=", "\\", "str_replace", "(", "'$'", ",", "''", ",", "$", "objectToken", "[", "1", "]", ")", ";", "$", "object", "=", "$", "this", "->", "getVariable", "(", "$", "objectName", ")", ";", "if", "(", "!", "$", "object", "instanceof", "\\", "MongoClient", ")", "{", "return", "[", "]", ";", "}", "$", "list", "=", "$", "object", "->", "listDBs", "(", ")", ";", "return", "\\", "array_filter", "(", "\\", "array_map", "(", "function", "(", "$", "info", ")", "{", "return", "$", "info", "[", "'name'", "]", ";", "}", ",", "$", "list", "[", "'databases'", "]", ")", ",", "function", "(", "$", "var", ")", "use", "(", "$", "input", ")", "{", "return", "AbstractMatcher", "::", "startsWith", "(", "$", "input", ",", "$", "var", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/MongoClientMatcher.php#L26-L53
bobthecow/psysh
src/CodeCleaner/NamespaceAwarePass.php
NamespaceAwarePass.enterNode
public function enterNode(Node $node) { if ($node instanceof Namespace_) { $this->namespace = isset($node->name) ? $node->name->parts : []; } }
php
public function enterNode(Node $node) { if ($node instanceof Namespace_) { $this->namespace = isset($node->name) ? $node->name->parts : []; } }
[ "public", "function", "enterNode", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Namespace_", ")", "{", "$", "this", "->", "namespace", "=", "isset", "(", "$", "node", "->", "name", ")", "?", "$", "node", "->", "name", "->", "parts", ":", "[", "]", ";", "}", "}" ]
@todo should this be final? Extending classes should be sure to either use leaveNode or call parent::enterNode() when overloading @param Node $node
[ "@todo", "should", "this", "be", "final?", "Extending", "classes", "should", "be", "sure", "to", "either", "use", "leaveNode", "or", "call", "parent", "::", "enterNode", "()", "when", "overloading" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/NamespaceAwarePass.php#L45-L50
bobthecow/psysh
src/CodeCleaner/NamespaceAwarePass.php
NamespaceAwarePass.getFullyQualifiedName
protected function getFullyQualifiedName($name) { if ($name instanceof FullyQualifiedName) { return \implode('\\', $name->parts); } elseif ($name instanceof Name) { $name = $name->parts; } elseif (!\is_array($name)) { $name = [$name]; } return \implode('\\', \array_merge($this->namespace, $name)); }
php
protected function getFullyQualifiedName($name) { if ($name instanceof FullyQualifiedName) { return \implode('\\', $name->parts); } elseif ($name instanceof Name) { $name = $name->parts; } elseif (!\is_array($name)) { $name = [$name]; } return \implode('\\', \array_merge($this->namespace, $name)); }
[ "protected", "function", "getFullyQualifiedName", "(", "$", "name", ")", "{", "if", "(", "$", "name", "instanceof", "FullyQualifiedName", ")", "{", "return", "\\", "implode", "(", "'\\\\'", ",", "$", "name", "->", "parts", ")", ";", "}", "elseif", "(", "$", "name", "instanceof", "Name", ")", "{", "$", "name", "=", "$", "name", "->", "parts", ";", "}", "elseif", "(", "!", "\\", "is_array", "(", "$", "name", ")", ")", "{", "$", "name", "=", "[", "$", "name", "]", ";", "}", "return", "\\", "implode", "(", "'\\\\'", ",", "\\", "array_merge", "(", "$", "this", "->", "namespace", ",", "$", "name", ")", ")", ";", "}" ]
Get a fully-qualified name (class, function, interface, etc). @param mixed $name @return string
[ "Get", "a", "fully", "-", "qualified", "name", "(", "class", "function", "interface", "etc", ")", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/NamespaceAwarePass.php#L59-L70
bobthecow/psysh
src/Readline/Libedit.php
Libedit.listHistory
public function listHistory() { $history = \file_get_contents($this->historyFile); if (!$history) { return []; } // libedit doesn't seem to support non-unix line separators. $history = \explode("\n", $history); // shift the history signature, ensure it's valid if (\array_shift($history) !== '_HiStOrY_V2_') { return []; } // decode the line $history = \array_map([$this, 'parseHistoryLine'], $history); // filter empty lines & comments return \array_values(\array_filter($history)); }
php
public function listHistory() { $history = \file_get_contents($this->historyFile); if (!$history) { return []; } $history = \explode("\n", $history); if (\array_shift($history) !== '_HiStOrY_V2_') { return []; } $history = \array_map([$this, 'parseHistoryLine'], $history); return \array_values(\array_filter($history)); }
[ "public", "function", "listHistory", "(", ")", "{", "$", "history", "=", "\\", "file_get_contents", "(", "$", "this", "->", "historyFile", ")", ";", "if", "(", "!", "$", "history", ")", "{", "return", "[", "]", ";", "}", "// libedit doesn't seem to support non-unix line separators.", "$", "history", "=", "\\", "explode", "(", "\"\\n\"", ",", "$", "history", ")", ";", "// shift the history signature, ensure it's valid", "if", "(", "\\", "array_shift", "(", "$", "history", ")", "!==", "'_HiStOrY_V2_'", ")", "{", "return", "[", "]", ";", "}", "// decode the line", "$", "history", "=", "\\", "array_map", "(", "[", "$", "this", ",", "'parseHistoryLine'", "]", ",", "$", "history", ")", ";", "// filter empty lines & comments", "return", "\\", "array_values", "(", "\\", "array_filter", "(", "$", "history", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Readline/Libedit.php#L38-L57
bobthecow/psysh
src/Readline/Libedit.php
Libedit.parseHistoryLine
protected function parseHistoryLine($line) { // empty line, comment or timestamp if (!$line || $line[0] === "\0") { return; } // if "\0" is found in an entry, then // everything from it until the end of line is a comment. if (($pos = \strpos($line, "\0")) !== false) { $line = \substr($line, 0, $pos); } return ($line !== '') ? Str::unvis($line) : null; }
php
protected function parseHistoryLine($line) { if (!$line || $line[0] === "\0") { return; } if (($pos = \strpos($line, "\0")) !== false) { $line = \substr($line, 0, $pos); } return ($line !== '') ? Str::unvis($line) : null; }
[ "protected", "function", "parseHistoryLine", "(", "$", "line", ")", "{", "// empty line, comment or timestamp", "if", "(", "!", "$", "line", "||", "$", "line", "[", "0", "]", "===", "\"\\0\"", ")", "{", "return", ";", "}", "// if \"\\0\" is found in an entry, then", "// everything from it until the end of line is a comment.", "if", "(", "(", "$", "pos", "=", "\\", "strpos", "(", "$", "line", ",", "\"\\0\"", ")", ")", "!==", "false", ")", "{", "$", "line", "=", "\\", "substr", "(", "$", "line", ",", "0", ",", "$", "pos", ")", ";", "}", "return", "(", "$", "line", "!==", "''", ")", "?", "Str", "::", "unvis", "(", "$", "line", ")", ":", "null", ";", "}" ]
From GNUReadline (readline/histfile.c & readline/histexpand.c): lines starting with "\0" are comments or timestamps; if "\0" is found in an entry, everything from it until the next line is a comment. @param string $line The history line to parse @return string | null
[ "From", "GNUReadline", "(", "readline", "/", "histfile", ".", "c", "&", "readline", "/", "histexpand", ".", "c", ")", ":", "lines", "starting", "with", "\\", "0", "are", "comments", "or", "timestamps", ";", "if", "\\", "0", "is", "found", "in", "an", "entry", "everything", "from", "it", "until", "the", "next", "line", "is", "a", "comment", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Readline/Libedit.php#L69-L82
bobthecow/psysh
src/TabCompletion/Matcher/FunctionsMatcher.php
FunctionsMatcher.getMatches
public function getMatches(array $tokens, array $info = []) { $func = $this->getInput($tokens); $functions = \get_defined_functions(); $allFunctions = \array_merge($functions['user'], $functions['internal']); return \array_filter($allFunctions, function ($function) use ($func) { return AbstractMatcher::startsWith($func, $function); }); }
php
public function getMatches(array $tokens, array $info = []) { $func = $this->getInput($tokens); $functions = \get_defined_functions(); $allFunctions = \array_merge($functions['user'], $functions['internal']); return \array_filter($allFunctions, function ($function) use ($func) { return AbstractMatcher::startsWith($func, $function); }); }
[ "public", "function", "getMatches", "(", "array", "$", "tokens", ",", "array", "$", "info", "=", "[", "]", ")", "{", "$", "func", "=", "$", "this", "->", "getInput", "(", "$", "tokens", ")", ";", "$", "functions", "=", "\\", "get_defined_functions", "(", ")", ";", "$", "allFunctions", "=", "\\", "array_merge", "(", "$", "functions", "[", "'user'", "]", ",", "$", "functions", "[", "'internal'", "]", ")", ";", "return", "\\", "array_filter", "(", "$", "allFunctions", ",", "function", "(", "$", "function", ")", "use", "(", "$", "func", ")", "{", "return", "AbstractMatcher", "::", "startsWith", "(", "$", "func", ",", "$", "function", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/FunctionsMatcher.php#L26-L36
bobthecow/psysh
src/TabCompletion/Matcher/FunctionsMatcher.php
FunctionsMatcher.hasMatched
public function hasMatched(array $tokens) { $token = \array_pop($tokens); $prevToken = \array_pop($tokens); switch (true) { case self::tokenIs($prevToken, self::T_NEW): return false; case self::hasToken([self::T_OPEN_TAG, self::T_STRING], $token): case self::isOperator($token): return true; } return false; }
php
public function hasMatched(array $tokens) { $token = \array_pop($tokens); $prevToken = \array_pop($tokens); switch (true) { case self::tokenIs($prevToken, self::T_NEW): return false; case self::hasToken([self::T_OPEN_TAG, self::T_STRING], $token): case self::isOperator($token): return true; } return false; }
[ "public", "function", "hasMatched", "(", "array", "$", "tokens", ")", "{", "$", "token", "=", "\\", "array_pop", "(", "$", "tokens", ")", ";", "$", "prevToken", "=", "\\", "array_pop", "(", "$", "tokens", ")", ";", "switch", "(", "true", ")", "{", "case", "self", "::", "tokenIs", "(", "$", "prevToken", ",", "self", "::", "T_NEW", ")", ":", "return", "false", ";", "case", "self", "::", "hasToken", "(", "[", "self", "::", "T_OPEN_TAG", ",", "self", "::", "T_STRING", "]", ",", "$", "token", ")", ":", "case", "self", "::", "isOperator", "(", "$", "token", ")", ":", "return", "true", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/FunctionsMatcher.php#L41-L55
bobthecow/psysh
src/Command/ListCommand/ClassConstantEnumerator.php
ClassConstantEnumerator.listItems
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null) { // only list constants when a Reflector is present. if ($reflector === null) { return; } // We can only list constants on actual class (or object) reflectors. if (!$reflector instanceof \ReflectionClass) { // @todo handle ReflectionExtension as well return; } // only list constants if we are specifically asked if (!$input->getOption('constants')) { return; } $noInherit = $input->getOption('no-inherit'); $constants = $this->prepareConstants($this->getConstants($reflector, $noInherit)); if (empty($constants)) { return; } $ret = []; $ret[$this->getKindLabel($reflector)] = $constants; return $ret; }
php
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null) { if ($reflector === null) { return; } if (!$reflector instanceof \ReflectionClass) { return; } if (!$input->getOption('constants')) { return; } $noInherit = $input->getOption('no-inherit'); $constants = $this->prepareConstants($this->getConstants($reflector, $noInherit)); if (empty($constants)) { return; } $ret = []; $ret[$this->getKindLabel($reflector)] = $constants; return $ret; }
[ "protected", "function", "listItems", "(", "InputInterface", "$", "input", ",", "\\", "Reflector", "$", "reflector", "=", "null", ",", "$", "target", "=", "null", ")", "{", "// only list constants when a Reflector is present.", "if", "(", "$", "reflector", "===", "null", ")", "{", "return", ";", "}", "// We can only list constants on actual class (or object) reflectors.", "if", "(", "!", "$", "reflector", "instanceof", "\\", "ReflectionClass", ")", "{", "// @todo handle ReflectionExtension as well", "return", ";", "}", "// only list constants if we are specifically asked", "if", "(", "!", "$", "input", "->", "getOption", "(", "'constants'", ")", ")", "{", "return", ";", "}", "$", "noInherit", "=", "$", "input", "->", "getOption", "(", "'no-inherit'", ")", ";", "$", "constants", "=", "$", "this", "->", "prepareConstants", "(", "$", "this", "->", "getConstants", "(", "$", "reflector", ",", "$", "noInherit", ")", ")", ";", "if", "(", "empty", "(", "$", "constants", ")", ")", "{", "return", ";", "}", "$", "ret", "=", "[", "]", ";", "$", "ret", "[", "$", "this", "->", "getKindLabel", "(", "$", "reflector", ")", "]", "=", "$", "constants", ";", "return", "$", "ret", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ClassConstantEnumerator.php#L25-L55
bobthecow/psysh
src/Command/ListCommand/ClassConstantEnumerator.php
ClassConstantEnumerator.getConstants
protected function getConstants(\Reflector $reflector, $noInherit = false) { $className = $reflector->getName(); $constants = []; foreach ($reflector->getConstants() as $name => $constant) { $constReflector = ReflectionClassConstant::create($reflector->name, $name); if ($noInherit && $constReflector->getDeclaringClass()->getName() !== $className) { continue; } $constants[$name] = $constReflector; } \ksort($constants, SORT_NATURAL | SORT_FLAG_CASE); return $constants; }
php
protected function getConstants(\Reflector $reflector, $noInherit = false) { $className = $reflector->getName(); $constants = []; foreach ($reflector->getConstants() as $name => $constant) { $constReflector = ReflectionClassConstant::create($reflector->name, $name); if ($noInherit && $constReflector->getDeclaringClass()->getName() !== $className) { continue; } $constants[$name] = $constReflector; } \ksort($constants, SORT_NATURAL | SORT_FLAG_CASE); return $constants; }
[ "protected", "function", "getConstants", "(", "\\", "Reflector", "$", "reflector", ",", "$", "noInherit", "=", "false", ")", "{", "$", "className", "=", "$", "reflector", "->", "getName", "(", ")", ";", "$", "constants", "=", "[", "]", ";", "foreach", "(", "$", "reflector", "->", "getConstants", "(", ")", "as", "$", "name", "=>", "$", "constant", ")", "{", "$", "constReflector", "=", "ReflectionClassConstant", "::", "create", "(", "$", "reflector", "->", "name", ",", "$", "name", ")", ";", "if", "(", "$", "noInherit", "&&", "$", "constReflector", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", "!==", "$", "className", ")", "{", "continue", ";", "}", "$", "constants", "[", "$", "name", "]", "=", "$", "constReflector", ";", "}", "\\", "ksort", "(", "$", "constants", ",", "SORT_NATURAL", "|", "SORT_FLAG_CASE", ")", ";", "return", "$", "constants", ";", "}" ]
Get defined constants for the given class or object Reflector. @param \Reflector $reflector @param bool $noInherit Exclude inherited constants @return array
[ "Get", "defined", "constants", "for", "the", "given", "class", "or", "object", "Reflector", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ClassConstantEnumerator.php#L65-L83
bobthecow/psysh
src/Command/ListCommand/ClassConstantEnumerator.php
ClassConstantEnumerator.prepareConstants
protected function prepareConstants(array $constants) { // My kingdom for a generator. $ret = []; foreach ($constants as $name => $constant) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, 'style' => self::IS_CONSTANT, 'value' => $this->presentRef($constant->getValue()), ]; } } return $ret; }
php
protected function prepareConstants(array $constants) { $ret = []; foreach ($constants as $name => $constant) { if ($this->showItem($name)) { $ret[$name] = [ 'name' => $name, 'style' => self::IS_CONSTANT, 'value' => $this->presentRef($constant->getValue()), ]; } } return $ret; }
[ "protected", "function", "prepareConstants", "(", "array", "$", "constants", ")", "{", "// My kingdom for a generator.", "$", "ret", "=", "[", "]", ";", "foreach", "(", "$", "constants", "as", "$", "name", "=>", "$", "constant", ")", "{", "if", "(", "$", "this", "->", "showItem", "(", "$", "name", ")", ")", "{", "$", "ret", "[", "$", "name", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'style'", "=>", "self", "::", "IS_CONSTANT", ",", "'value'", "=>", "$", "this", "->", "presentRef", "(", "$", "constant", "->", "getValue", "(", ")", ")", ",", "]", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Prepare formatted constant array. @param array $constants @return array
[ "Prepare", "formatted", "constant", "array", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/ClassConstantEnumerator.php#L92-L108
bobthecow/psysh
src/ConsoleColorFactory.php
ConsoleColorFactory.getConsoleColor
public function getConsoleColor() { if ($this->colorMode === Configuration::COLOR_MODE_AUTO) { return $this->getDefaultConsoleColor(); } elseif ($this->colorMode === Configuration::COLOR_MODE_FORCED) { return $this->getForcedConsoleColor(); } elseif ($this->colorMode === Configuration::COLOR_MODE_DISABLED) { return $this->getDisabledConsoleColor(); } }
php
public function getConsoleColor() { if ($this->colorMode === Configuration::COLOR_MODE_AUTO) { return $this->getDefaultConsoleColor(); } elseif ($this->colorMode === Configuration::COLOR_MODE_FORCED) { return $this->getForcedConsoleColor(); } elseif ($this->colorMode === Configuration::COLOR_MODE_DISABLED) { return $this->getDisabledConsoleColor(); } }
[ "public", "function", "getConsoleColor", "(", ")", "{", "if", "(", "$", "this", "->", "colorMode", "===", "Configuration", "::", "COLOR_MODE_AUTO", ")", "{", "return", "$", "this", "->", "getDefaultConsoleColor", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "colorMode", "===", "Configuration", "::", "COLOR_MODE_FORCED", ")", "{", "return", "$", "this", "->", "getForcedConsoleColor", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "colorMode", "===", "Configuration", "::", "COLOR_MODE_DISABLED", ")", "{", "return", "$", "this", "->", "getDisabledConsoleColor", "(", ")", ";", "}", "}" ]
Get a `ConsoleColor` instance configured according to the given color mode. @return ConsoleColor
[ "Get", "a", "ConsoleColor", "instance", "configured", "according", "to", "the", "given", "color", "mode", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/ConsoleColorFactory.php#L38-L47
bobthecow/psysh
src/Context.php
Context.get
public function get($name) { switch ($name) { case '_': return $this->returnValue; case '_e': if (isset($this->lastException)) { return $this->lastException; } break; case '__out': if (isset($this->lastStdout)) { return $this->lastStdout; } break; case 'this': if (isset($this->boundObject)) { return $this->boundObject; } break; case '__function': case '__method': case '__class': case '__namespace': case '__file': case '__line': case '__dir': if (\array_key_exists($name, $this->commandScopeVariables)) { return $this->commandScopeVariables[$name]; } break; default: if (\array_key_exists($name, $this->scopeVariables)) { return $this->scopeVariables[$name]; } break; } throw new \InvalidArgumentException('Unknown variable: $' . $name); }
php
public function get($name) { switch ($name) { case '_': return $this->returnValue; case '_e': if (isset($this->lastException)) { return $this->lastException; } break; case '__out': if (isset($this->lastStdout)) { return $this->lastStdout; } break; case 'this': if (isset($this->boundObject)) { return $this->boundObject; } break; case '__function': case '__method': case '__class': case '__namespace': case '__file': case '__line': case '__dir': if (\array_key_exists($name, $this->commandScopeVariables)) { return $this->commandScopeVariables[$name]; } break; default: if (\array_key_exists($name, $this->scopeVariables)) { return $this->scopeVariables[$name]; } break; } throw new \InvalidArgumentException('Unknown variable: $' . $name); }
[ "public", "function", "get", "(", "$", "name", ")", "{", "switch", "(", "$", "name", ")", "{", "case", "'_'", ":", "return", "$", "this", "->", "returnValue", ";", "case", "'_e'", ":", "if", "(", "isset", "(", "$", "this", "->", "lastException", ")", ")", "{", "return", "$", "this", "->", "lastException", ";", "}", "break", ";", "case", "'__out'", ":", "if", "(", "isset", "(", "$", "this", "->", "lastStdout", ")", ")", "{", "return", "$", "this", "->", "lastStdout", ";", "}", "break", ";", "case", "'this'", ":", "if", "(", "isset", "(", "$", "this", "->", "boundObject", ")", ")", "{", "return", "$", "this", "->", "boundObject", ";", "}", "break", ";", "case", "'__function'", ":", "case", "'__method'", ":", "case", "'__class'", ":", "case", "'__namespace'", ":", "case", "'__file'", ":", "case", "'__line'", ":", "case", "'__dir'", ":", "if", "(", "\\", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "commandScopeVariables", ")", ")", "{", "return", "$", "this", "->", "commandScopeVariables", "[", "$", "name", "]", ";", "}", "break", ";", "default", ":", "if", "(", "\\", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "scopeVariables", ")", ")", "{", "return", "$", "this", "->", "scopeVariables", "[", "$", "name", "]", ";", "}", "break", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unknown variable: $'", ".", "$", "name", ")", ";", "}" ]
Get a context variable. @throws InvalidArgumentException If the variable is not found in the current context @param string $name @return mixed
[ "Get", "a", "context", "variable", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L47-L91
bobthecow/psysh
src/Context.php
Context.getSpecialVariables
public function getSpecialVariables() { $vars = [ '_' => $this->returnValue, ]; if (isset($this->lastException)) { $vars['_e'] = $this->lastException; } if (isset($this->lastStdout)) { $vars['__out'] = $this->lastStdout; } if (isset($this->boundObject)) { $vars['this'] = $this->boundObject; } return \array_merge($vars, $this->commandScopeVariables); }
php
public function getSpecialVariables() { $vars = [ '_' => $this->returnValue, ]; if (isset($this->lastException)) { $vars['_e'] = $this->lastException; } if (isset($this->lastStdout)) { $vars['__out'] = $this->lastStdout; } if (isset($this->boundObject)) { $vars['this'] = $this->boundObject; } return \array_merge($vars, $this->commandScopeVariables); }
[ "public", "function", "getSpecialVariables", "(", ")", "{", "$", "vars", "=", "[", "'_'", "=>", "$", "this", "->", "returnValue", ",", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "lastException", ")", ")", "{", "$", "vars", "[", "'_e'", "]", "=", "$", "this", "->", "lastException", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "lastStdout", ")", ")", "{", "$", "vars", "[", "'__out'", "]", "=", "$", "this", "->", "lastStdout", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "boundObject", ")", ")", "{", "$", "vars", "[", "'this'", "]", "=", "$", "this", "->", "boundObject", ";", "}", "return", "\\", "array_merge", "(", "$", "vars", ",", "$", "this", "->", "commandScopeVariables", ")", ";", "}" ]
Get all defined magic variables: $_, $_e, $__out, $__class, $__file, etc. @return array
[ "Get", "all", "defined", "magic", "variables", ":", "$_", "$_e", "$__out", "$__class", "$__file", "etc", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L108-L127
bobthecow/psysh
src/Context.php
Context.setAll
public function setAll(array $vars) { foreach (self::$specialNames as $key) { unset($vars[$key]); } foreach (self::$commandScopeNames as $key) { unset($vars[$key]); } $this->scopeVariables = $vars; }
php
public function setAll(array $vars) { foreach (self::$specialNames as $key) { unset($vars[$key]); } foreach (self::$commandScopeNames as $key) { unset($vars[$key]); } $this->scopeVariables = $vars; }
[ "public", "function", "setAll", "(", "array", "$", "vars", ")", "{", "foreach", "(", "self", "::", "$", "specialNames", "as", "$", "key", ")", "{", "unset", "(", "$", "vars", "[", "$", "key", "]", ")", ";", "}", "foreach", "(", "self", "::", "$", "commandScopeNames", "as", "$", "key", ")", "{", "unset", "(", "$", "vars", "[", "$", "key", "]", ")", ";", "}", "$", "this", "->", "scopeVariables", "=", "$", "vars", ";", "}" ]
Set all scope variables. This method does *not* set any of the magic variables: $_, $_e, $__out, $__class, $__file, etc. @param array $vars
[ "Set", "all", "scope", "variables", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L137-L148
bobthecow/psysh
src/Context.php
Context.setBoundObject
public function setBoundObject($boundObject) { $this->boundObject = \is_object($boundObject) ? $boundObject : null; $this->boundClass = null; }
php
public function setBoundObject($boundObject) { $this->boundObject = \is_object($boundObject) ? $boundObject : null; $this->boundClass = null; }
[ "public", "function", "setBoundObject", "(", "$", "boundObject", ")", "{", "$", "this", "->", "boundObject", "=", "\\", "is_object", "(", "$", "boundObject", ")", "?", "$", "boundObject", ":", "null", ";", "$", "this", "->", "boundClass", "=", "null", ";", "}" ]
Set the bound object ($this variable) for the interactive shell. Note that this unsets the bound class, if any exists. @param object|null $boundObject
[ "Set", "the", "bound", "object", "(", "$this", "variable", ")", "for", "the", "interactive", "shell", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L229-L233
bobthecow/psysh
src/Context.php
Context.setBoundClass
public function setBoundClass($boundClass) { $this->boundClass = (\is_string($boundClass) && $boundClass !== '') ? $boundClass : null; $this->boundObject = null; }
php
public function setBoundClass($boundClass) { $this->boundClass = (\is_string($boundClass) && $boundClass !== '') ? $boundClass : null; $this->boundObject = null; }
[ "public", "function", "setBoundClass", "(", "$", "boundClass", ")", "{", "$", "this", "->", "boundClass", "=", "(", "\\", "is_string", "(", "$", "boundClass", ")", "&&", "$", "boundClass", "!==", "''", ")", "?", "$", "boundClass", ":", "null", ";", "$", "this", "->", "boundObject", "=", "null", ";", "}" ]
Set the bound class (self) for the interactive shell. Note that this unsets the bound object, if any exists. @param string|null $boundClass
[ "Set", "the", "bound", "class", "(", "self", ")", "for", "the", "interactive", "shell", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L252-L256
bobthecow/psysh
src/Context.php
Context.setCommandScopeVariables
public function setCommandScopeVariables(array $commandScopeVariables) { $vars = []; foreach ($commandScopeVariables as $key => $value) { // kind of type check if (\is_scalar($value) && \in_array($key, self::$commandScopeNames)) { $vars[$key] = $value; } } $this->commandScopeVariables = $vars; }
php
public function setCommandScopeVariables(array $commandScopeVariables) { $vars = []; foreach ($commandScopeVariables as $key => $value) { if (\is_scalar($value) && \in_array($key, self::$commandScopeNames)) { $vars[$key] = $value; } } $this->commandScopeVariables = $vars; }
[ "public", "function", "setCommandScopeVariables", "(", "array", "$", "commandScopeVariables", ")", "{", "$", "vars", "=", "[", "]", ";", "foreach", "(", "$", "commandScopeVariables", "as", "$", "key", "=>", "$", "value", ")", "{", "// kind of type check", "if", "(", "\\", "is_scalar", "(", "$", "value", ")", "&&", "\\", "in_array", "(", "$", "key", ",", "self", "::", "$", "commandScopeNames", ")", ")", "{", "$", "vars", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "$", "this", "->", "commandScopeVariables", "=", "$", "vars", ";", "}" ]
Set command-scope magic variables: $__class, $__file, etc. @param array $commandScopeVariables
[ "Set", "command", "-", "scope", "magic", "variables", ":", "$__class", "$__file", "etc", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L273-L284
bobthecow/psysh
src/Context.php
Context.isSpecialVariableName
public static function isSpecialVariableName($name) { return \in_array($name, self::$specialNames) || \in_array($name, self::$commandScopeNames); }
php
public static function isSpecialVariableName($name) { return \in_array($name, self::$specialNames) || \in_array($name, self::$commandScopeNames); }
[ "public", "static", "function", "isSpecialVariableName", "(", "$", "name", ")", "{", "return", "\\", "in_array", "(", "$", "name", ",", "self", "::", "$", "specialNames", ")", "||", "\\", "in_array", "(", "$", "name", ",", "self", "::", "$", "commandScopeNames", ")", ";", "}" ]
Check whether a variable name is a magic variable. @param string $name @return bool
[ "Check", "whether", "a", "variable", "name", "is", "a", "magic", "variable", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Context.php#L316-L319
bobthecow/psysh
src/Command/EditCommand.php
EditCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('exec') && $input->getOption('no-exec')) { throw new \InvalidArgumentException('The --exec and --no-exec flags are mutually exclusive'); } $filePath = $this->extractFilePath($input->getArgument('file')); $execute = $this->shouldExecuteFile( $input->getOption('exec'), $input->getOption('no-exec'), $filePath ); $shouldRemoveFile = false; if ($filePath === null) { $filePath = \tempnam($this->runtimeDir, 'psysh-edit-command'); $shouldRemoveFile = true; } $editedContent = $this->editFile($filePath, $shouldRemoveFile); if ($execute) { $this->getApplication()->addInput($editedContent); } }
php
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('exec') && $input->getOption('no-exec')) { throw new \InvalidArgumentException('The --exec and --no-exec flags are mutually exclusive'); } $filePath = $this->extractFilePath($input->getArgument('file')); $execute = $this->shouldExecuteFile( $input->getOption('exec'), $input->getOption('no-exec'), $filePath ); $shouldRemoveFile = false; if ($filePath === null) { $filePath = \tempnam($this->runtimeDir, 'psysh-edit-command'); $shouldRemoveFile = true; } $editedContent = $this->editFile($filePath, $shouldRemoveFile); if ($execute) { $this->getApplication()->addInput($editedContent); } }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "if", "(", "$", "input", "->", "getOption", "(", "'exec'", ")", "&&", "$", "input", "->", "getOption", "(", "'no-exec'", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The --exec and --no-exec flags are mutually exclusive'", ")", ";", "}", "$", "filePath", "=", "$", "this", "->", "extractFilePath", "(", "$", "input", "->", "getArgument", "(", "'file'", ")", ")", ";", "$", "execute", "=", "$", "this", "->", "shouldExecuteFile", "(", "$", "input", "->", "getOption", "(", "'exec'", ")", ",", "$", "input", "->", "getOption", "(", "'no-exec'", ")", ",", "$", "filePath", ")", ";", "$", "shouldRemoveFile", "=", "false", ";", "if", "(", "$", "filePath", "===", "null", ")", "{", "$", "filePath", "=", "\\", "tempnam", "(", "$", "this", "->", "runtimeDir", ",", "'psysh-edit-command'", ")", ";", "$", "shouldRemoveFile", "=", "true", ";", "}", "$", "editedContent", "=", "$", "this", "->", "editFile", "(", "$", "filePath", ",", "$", "shouldRemoveFile", ")", ";", "if", "(", "$", "execute", ")", "{", "$", "this", "->", "getApplication", "(", ")", "->", "addInput", "(", "$", "editedContent", ")", ";", "}", "}" ]
@param InputInterface $input @param OutputInterface $output @throws \InvalidArgumentException when both exec and no-exec flags are given or if a given variable is not found in the current context @throws \UnexpectedValueException if file_get_contents on the edited file returns false instead of a string
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/EditCommand.php#L80-L107
bobthecow/psysh
src/Command/EditCommand.php
EditCommand.shouldExecuteFile
private function shouldExecuteFile($execOption, $noExecOption, $filePath) { if ($execOption) { return true; } if ($noExecOption) { return false; } // By default, code that is edited is executed if there was no given input file path return $filePath === null; }
php
private function shouldExecuteFile($execOption, $noExecOption, $filePath) { if ($execOption) { return true; } if ($noExecOption) { return false; } return $filePath === null; }
[ "private", "function", "shouldExecuteFile", "(", "$", "execOption", ",", "$", "noExecOption", ",", "$", "filePath", ")", "{", "if", "(", "$", "execOption", ")", "{", "return", "true", ";", "}", "if", "(", "$", "noExecOption", ")", "{", "return", "false", ";", "}", "// By default, code that is edited is executed if there was no given input file path", "return", "$", "filePath", "===", "null", ";", "}" ]
@param bool $execOption @param bool $noExecOption @param string|null $filePath @return bool
[ "@param", "bool", "$execOption", "@param", "bool", "$noExecOption", "@param", "string|null", "$filePath" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/EditCommand.php#L116-L128
bobthecow/psysh
src/Command/EditCommand.php
EditCommand.extractFilePath
private function extractFilePath($fileArgument) { // If the file argument was a variable, get it from the context if ($fileArgument !== null && \strlen($fileArgument) > 0 && $fileArgument[0] === '$') { $fileArgument = $this->context->get(\preg_replace('/^\$/', '', $fileArgument)); } return $fileArgument; }
php
private function extractFilePath($fileArgument) { if ($fileArgument !== null && \strlen($fileArgument) > 0 && $fileArgument[0] === '$') { $fileArgument = $this->context->get(\preg_replace('/^\$/', '', $fileArgument)); } return $fileArgument; }
[ "private", "function", "extractFilePath", "(", "$", "fileArgument", ")", "{", "// If the file argument was a variable, get it from the context", "if", "(", "$", "fileArgument", "!==", "null", "&&", "\\", "strlen", "(", "$", "fileArgument", ")", ">", "0", "&&", "$", "fileArgument", "[", "0", "]", "===", "'$'", ")", "{", "$", "fileArgument", "=", "$", "this", "->", "context", "->", "get", "(", "\\", "preg_replace", "(", "'/^\\$/'", ",", "''", ",", "$", "fileArgument", ")", ")", ";", "}", "return", "$", "fileArgument", ";", "}" ]
@param string|null $fileArgument @return string|null The file path to edit, null if the input was null, or the value of the referenced variable @throws \InvalidArgumentException If the variable is not found in the current context
[ "@param", "string|null", "$fileArgument" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/EditCommand.php#L137-L147
bobthecow/psysh
src/Command/EditCommand.php
EditCommand.editFile
private function editFile($filePath, $shouldRemoveFile) { $escapedFilePath = \escapeshellarg($filePath); $pipes = []; $proc = \proc_open((\getenv('EDITOR') ?: 'nano') . " {$escapedFilePath}", [STDIN, STDOUT, STDERR], $pipes); \proc_close($proc); $editedContent = @\file_get_contents($filePath); if ($shouldRemoveFile) { @\unlink($filePath); } if ($editedContent === false) { throw new \UnexpectedValueException("Reading {$filePath} returned false"); } return $editedContent; }
php
private function editFile($filePath, $shouldRemoveFile) { $escapedFilePath = \escapeshellarg($filePath); $pipes = []; $proc = \proc_open((\getenv('EDITOR') ?: 'nano') . " {$escapedFilePath}", [STDIN, STDOUT, STDERR], $pipes); \proc_close($proc); $editedContent = @\file_get_contents($filePath); if ($shouldRemoveFile) { @\unlink($filePath); } if ($editedContent === false) { throw new \UnexpectedValueException("Reading {$filePath} returned false"); } return $editedContent; }
[ "private", "function", "editFile", "(", "$", "filePath", ",", "$", "shouldRemoveFile", ")", "{", "$", "escapedFilePath", "=", "\\", "escapeshellarg", "(", "$", "filePath", ")", ";", "$", "pipes", "=", "[", "]", ";", "$", "proc", "=", "\\", "proc_open", "(", "(", "\\", "getenv", "(", "'EDITOR'", ")", "?", ":", "'nano'", ")", ".", "\" {$escapedFilePath}\"", ",", "[", "STDIN", ",", "STDOUT", ",", "STDERR", "]", ",", "$", "pipes", ")", ";", "\\", "proc_close", "(", "$", "proc", ")", ";", "$", "editedContent", "=", "@", "\\", "file_get_contents", "(", "$", "filePath", ")", ";", "if", "(", "$", "shouldRemoveFile", ")", "{", "@", "\\", "unlink", "(", "$", "filePath", ")", ";", "}", "if", "(", "$", "editedContent", "===", "false", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Reading {$filePath} returned false\"", ")", ";", "}", "return", "$", "editedContent", ";", "}" ]
@param string $filePath @param string $shouldRemoveFile @return string @throws \UnexpectedValueException if file_get_contents on $filePath returns false instead of a string
[ "@param", "string", "$filePath", "@param", "string", "$shouldRemoveFile" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/EditCommand.php#L157-L176
bobthecow/psysh
src/TabCompletion/Matcher/ConstantsMatcher.php
ConstantsMatcher.getMatches
public function getMatches(array $tokens, array $info = []) { $const = $this->getInput($tokens); return \array_filter(\array_keys(\get_defined_constants()), function ($constant) use ($const) { return AbstractMatcher::startsWith($const, $constant); }); }
php
public function getMatches(array $tokens, array $info = []) { $const = $this->getInput($tokens); return \array_filter(\array_keys(\get_defined_constants()), function ($constant) use ($const) { return AbstractMatcher::startsWith($const, $constant); }); }
[ "public", "function", "getMatches", "(", "array", "$", "tokens", ",", "array", "$", "info", "=", "[", "]", ")", "{", "$", "const", "=", "$", "this", "->", "getInput", "(", "$", "tokens", ")", ";", "return", "\\", "array_filter", "(", "\\", "array_keys", "(", "\\", "get_defined_constants", "(", ")", ")", ",", "function", "(", "$", "constant", ")", "use", "(", "$", "const", ")", "{", "return", "AbstractMatcher", "::", "startsWith", "(", "$", "const", ",", "$", "constant", ")", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/TabCompletion/Matcher/ConstantsMatcher.php#L26-L33
bobthecow/psysh
src/Exception/ThrowUpException.php
ThrowUpException.fromThrowable
public static function fromThrowable($throwable) { if ($throwable instanceof \Error) { $throwable = ErrorException::fromError($throwable); } if (!$throwable instanceof \Exception) { throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors'); } return new self($throwable); }
php
public static function fromThrowable($throwable) { if ($throwable instanceof \Error) { $throwable = ErrorException::fromError($throwable); } if (!$throwable instanceof \Exception) { throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors'); } return new self($throwable); }
[ "public", "static", "function", "fromThrowable", "(", "$", "throwable", ")", "{", "if", "(", "$", "throwable", "instanceof", "\\", "Error", ")", "{", "$", "throwable", "=", "ErrorException", "::", "fromError", "(", "$", "throwable", ")", ";", "}", "if", "(", "!", "$", "throwable", "instanceof", "\\", "Exception", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'throw-up can only throw Exceptions and Errors'", ")", ";", "}", "return", "new", "self", "(", "$", "throwable", ")", ";", "}" ]
Create a ThrowUpException from a Throwable. @param \Throwable $throwable @return ThrowUpException
[ "Create", "a", "ThrowUpException", "from", "a", "Throwable", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Exception/ThrowUpException.php#L45-L56
bobthecow/psysh
src/CodeCleaner/UseStatementPass.php
UseStatementPass.enterNode
public function enterNode(Node $node) { if ($node instanceof Namespace_) { // If this is the same namespace as last namespace, let's do ourselves // a favor and reload all the aliases... if (\strtolower($node->name) === \strtolower($this->lastNamespace)) { $this->aliases = $this->lastAliases; } } }
php
public function enterNode(Node $node) { if ($node instanceof Namespace_) { if (\strtolower($node->name) === \strtolower($this->lastNamespace)) { $this->aliases = $this->lastAliases; } } }
[ "public", "function", "enterNode", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Namespace_", ")", "{", "// If this is the same namespace as last namespace, let's do ourselves", "// a favor and reload all the aliases...", "if", "(", "\\", "strtolower", "(", "$", "node", "->", "name", ")", "===", "\\", "strtolower", "(", "$", "this", "->", "lastNamespace", ")", ")", "{", "$", "this", "->", "aliases", "=", "$", "this", "->", "lastAliases", ";", "}", "}", "}" ]
Re-load the last set of use statements on re-entering a namespace. This isn't how namespaces normally work, but because PsySH has to spin up a new namespace for every line of code, we do this to make things work like you'd expect. @param Node $node
[ "Re", "-", "load", "the", "last", "set", "of", "use", "statements", "on", "re", "-", "entering", "a", "namespace", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/UseStatementPass.php#L47-L56
bobthecow/psysh
src/CodeCleaner/UseStatementPass.php
UseStatementPass.leaveNode
public function leaveNode(Node $node) { if ($node instanceof Use_) { // Store a reference to every "use" statement, because we'll need // them in a bit. foreach ($node->uses as $use) { $alias = $use->alias ?: \end($use->name->parts); $this->aliases[\strtolower($alias)] = $use->name; } return NodeTraverser::REMOVE_NODE; } elseif ($node instanceof GroupUse) { // Expand every "use" statement in the group into a full, standalone // "use" and store 'em with the others. foreach ($node->uses as $use) { $alias = $use->alias ?: \end($use->name->parts); $this->aliases[\strtolower($alias)] = Name::concat($node->prefix, $use->name, [ 'startLine' => $node->prefix->getAttribute('startLine'), 'endLine' => $use->name->getAttribute('endLine'), ]); } return NodeTraverser::REMOVE_NODE; } elseif ($node instanceof Namespace_) { // Start fresh, since we're done with this namespace. $this->lastNamespace = $node->name; $this->lastAliases = $this->aliases; $this->aliases = []; } else { foreach ($node as $name => $subNode) { if ($subNode instanceof Name) { // Implicitly thunk all aliases. if ($replacement = $this->findAlias($subNode)) { $node->$name = $replacement; } } } return $node; } }
php
public function leaveNode(Node $node) { if ($node instanceof Use_) { foreach ($node->uses as $use) { $alias = $use->alias ?: \end($use->name->parts); $this->aliases[\strtolower($alias)] = $use->name; } return NodeTraverser::REMOVE_NODE; } elseif ($node instanceof GroupUse) { foreach ($node->uses as $use) { $alias = $use->alias ?: \end($use->name->parts); $this->aliases[\strtolower($alias)] = Name::concat($node->prefix, $use->name, [ 'startLine' => $node->prefix->getAttribute('startLine'), 'endLine' => $use->name->getAttribute('endLine'), ]); } return NodeTraverser::REMOVE_NODE; } elseif ($node instanceof Namespace_) { $this->lastNamespace = $node->name; $this->lastAliases = $this->aliases; $this->aliases = []; } else { foreach ($node as $name => $subNode) { if ($subNode instanceof Name) { if ($replacement = $this->findAlias($subNode)) { $node->$name = $replacement; } } } return $node; } }
[ "public", "function", "leaveNode", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Use_", ")", "{", "// Store a reference to every \"use\" statement, because we'll need", "// them in a bit.", "foreach", "(", "$", "node", "->", "uses", "as", "$", "use", ")", "{", "$", "alias", "=", "$", "use", "->", "alias", "?", ":", "\\", "end", "(", "$", "use", "->", "name", "->", "parts", ")", ";", "$", "this", "->", "aliases", "[", "\\", "strtolower", "(", "$", "alias", ")", "]", "=", "$", "use", "->", "name", ";", "}", "return", "NodeTraverser", "::", "REMOVE_NODE", ";", "}", "elseif", "(", "$", "node", "instanceof", "GroupUse", ")", "{", "// Expand every \"use\" statement in the group into a full, standalone", "// \"use\" and store 'em with the others.", "foreach", "(", "$", "node", "->", "uses", "as", "$", "use", ")", "{", "$", "alias", "=", "$", "use", "->", "alias", "?", ":", "\\", "end", "(", "$", "use", "->", "name", "->", "parts", ")", ";", "$", "this", "->", "aliases", "[", "\\", "strtolower", "(", "$", "alias", ")", "]", "=", "Name", "::", "concat", "(", "$", "node", "->", "prefix", ",", "$", "use", "->", "name", ",", "[", "'startLine'", "=>", "$", "node", "->", "prefix", "->", "getAttribute", "(", "'startLine'", ")", ",", "'endLine'", "=>", "$", "use", "->", "name", "->", "getAttribute", "(", "'endLine'", ")", ",", "]", ")", ";", "}", "return", "NodeTraverser", "::", "REMOVE_NODE", ";", "}", "elseif", "(", "$", "node", "instanceof", "Namespace_", ")", "{", "// Start fresh, since we're done with this namespace.", "$", "this", "->", "lastNamespace", "=", "$", "node", "->", "name", ";", "$", "this", "->", "lastAliases", "=", "$", "this", "->", "aliases", ";", "$", "this", "->", "aliases", "=", "[", "]", ";", "}", "else", "{", "foreach", "(", "$", "node", "as", "$", "name", "=>", "$", "subNode", ")", "{", "if", "(", "$", "subNode", "instanceof", "Name", ")", "{", "// Implicitly thunk all aliases.", "if", "(", "$", "replacement", "=", "$", "this", "->", "findAlias", "(", "$", "subNode", ")", ")", "{", "$", "node", "->", "$", "name", "=", "$", "replacement", ";", "}", "}", "}", "return", "$", "node", ";", "}", "}" ]
If this statement is a namespace, forget all the aliases we had. If it's a use statement, remember the alias for later. Otherwise, apply remembered aliases to the code. @param Node $node
[ "If", "this", "statement", "is", "a", "namespace", "forget", "all", "the", "aliases", "we", "had", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/UseStatementPass.php#L66-L106
bobthecow/psysh
src/CodeCleaner/UseStatementPass.php
UseStatementPass.findAlias
private function findAlias(Name $name) { $that = \strtolower($name); foreach ($this->aliases as $alias => $prefix) { if ($that === $alias) { return new FullyQualifiedName($prefix->toString()); } elseif (\substr($that, 0, \strlen($alias) + 1) === $alias . '\\') { return new FullyQualifiedName($prefix->toString() . \substr($name, \strlen($alias))); } } }
php
private function findAlias(Name $name) { $that = \strtolower($name); foreach ($this->aliases as $alias => $prefix) { if ($that === $alias) { return new FullyQualifiedName($prefix->toString()); } elseif (\substr($that, 0, \strlen($alias) + 1) === $alias . '\\') { return new FullyQualifiedName($prefix->toString() . \substr($name, \strlen($alias))); } } }
[ "private", "function", "findAlias", "(", "Name", "$", "name", ")", "{", "$", "that", "=", "\\", "strtolower", "(", "$", "name", ")", ";", "foreach", "(", "$", "this", "->", "aliases", "as", "$", "alias", "=>", "$", "prefix", ")", "{", "if", "(", "$", "that", "===", "$", "alias", ")", "{", "return", "new", "FullyQualifiedName", "(", "$", "prefix", "->", "toString", "(", ")", ")", ";", "}", "elseif", "(", "\\", "substr", "(", "$", "that", ",", "0", ",", "\\", "strlen", "(", "$", "alias", ")", "+", "1", ")", "===", "$", "alias", ".", "'\\\\'", ")", "{", "return", "new", "FullyQualifiedName", "(", "$", "prefix", "->", "toString", "(", ")", ".", "\\", "substr", "(", "$", "name", ",", "\\", "strlen", "(", "$", "alias", ")", ")", ")", ";", "}", "}", "}" ]
Find class/namespace aliases. @param Name $name @return FullyQualifiedName|null
[ "Find", "class", "/", "namespace", "aliases", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/UseStatementPass.php#L115-L125
bobthecow/psysh
src/CodeCleaner/CalledClassPass.php
CalledClassPass.enterNode
public function enterNode(Node $node) { if ($node instanceof Class_ || $node instanceof Trait_) { $this->inClass = true; } elseif ($node instanceof FuncCall && !$this->inClass) { // We'll give any args at all (besides null) a pass. // Technically we should be checking whether the args are objects, but this will do for now. // // @todo switch this to actually validate args when we get context-aware code cleaner passes. if (!empty($node->args) && !$this->isNull($node->args[0])) { return; } // We'll ignore name expressions as well (things like `$foo()`) if (!($node->name instanceof Name)) { return; } $name = \strtolower($node->name); if (\in_array($name, ['get_class', 'get_called_class'])) { $msg = \sprintf('%s() called without object from outside a class', $name); throw new ErrorException($msg, 0, E_USER_WARNING, null, $node->getLine()); } } }
php
public function enterNode(Node $node) { if ($node instanceof Class_ || $node instanceof Trait_) { $this->inClass = true; } elseif ($node instanceof FuncCall && !$this->inClass) { if (!empty($node->args) && !$this->isNull($node->args[0])) { return; } if (!($node->name instanceof Name)) { return; } $name = \strtolower($node->name); if (\in_array($name, ['get_class', 'get_called_class'])) { $msg = \sprintf('%s() called without object from outside a class', $name); throw new ErrorException($msg, 0, E_USER_WARNING, null, $node->getLine()); } } }
[ "public", "function", "enterNode", "(", "Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Class_", "||", "$", "node", "instanceof", "Trait_", ")", "{", "$", "this", "->", "inClass", "=", "true", ";", "}", "elseif", "(", "$", "node", "instanceof", "FuncCall", "&&", "!", "$", "this", "->", "inClass", ")", "{", "// We'll give any args at all (besides null) a pass.", "// Technically we should be checking whether the args are objects, but this will do for now.", "//", "// @todo switch this to actually validate args when we get context-aware code cleaner passes.", "if", "(", "!", "empty", "(", "$", "node", "->", "args", ")", "&&", "!", "$", "this", "->", "isNull", "(", "$", "node", "->", "args", "[", "0", "]", ")", ")", "{", "return", ";", "}", "// We'll ignore name expressions as well (things like `$foo()`)", "if", "(", "!", "(", "$", "node", "->", "name", "instanceof", "Name", ")", ")", "{", "return", ";", "}", "$", "name", "=", "\\", "strtolower", "(", "$", "node", "->", "name", ")", ";", "if", "(", "\\", "in_array", "(", "$", "name", ",", "[", "'get_class'", ",", "'get_called_class'", "]", ")", ")", "{", "$", "msg", "=", "\\", "sprintf", "(", "'%s() called without object from outside a class'", ",", "$", "name", ")", ";", "throw", "new", "ErrorException", "(", "$", "msg", ",", "0", ",", "E_USER_WARNING", ",", "null", ",", "$", "node", "->", "getLine", "(", ")", ")", ";", "}", "}", "}" ]
@throws ErrorException if get_class or get_called_class is called without an object from outside a class @param Node $node
[ "@throws", "ErrorException", "if", "get_class", "or", "get_called_class", "is", "called", "without", "an", "object", "from", "outside", "a", "class" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/CalledClassPass.php#L43-L67
bobthecow/psysh
src/Command/ListCommand/Enumerator.php
Enumerator.enumerate
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null) { $this->filter->bind($input); return $this->listItems($input, $reflector, $target); }
php
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null) { $this->filter->bind($input); return $this->listItems($input, $reflector, $target); }
[ "public", "function", "enumerate", "(", "InputInterface", "$", "input", ",", "\\", "Reflector", "$", "reflector", "=", "null", ",", "$", "target", "=", "null", ")", "{", "$", "this", "->", "filter", "->", "bind", "(", "$", "input", ")", ";", "return", "$", "this", "->", "listItems", "(", "$", "input", ",", "$", "reflector", ",", "$", "target", ")", ";", "}" ]
Return a list of categorized things with the given input options and target. @param InputInterface $input @param \Reflector $reflector @param mixed $target @return array
[ "Return", "a", "list", "of", "categorized", "things", "with", "the", "given", "input", "options", "and", "target", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ListCommand/Enumerator.php#L57-L62
bobthecow/psysh
src/Configuration.php
Configuration.init
public function init() { // feature detection $this->hasReadline = \function_exists('readline'); $this->hasPcntl = \function_exists('pcntl_signal') && \function_exists('posix_getpid'); if ($configFile = $this->getConfigFile()) { $this->loadConfigFile($configFile); } if (!$this->configFile && $localConfig = $this->getLocalConfigFile()) { $this->loadConfigFile($localConfig); } }
php
public function init() { $this->hasReadline = \function_exists('readline'); $this->hasPcntl = \function_exists('pcntl_signal') && \function_exists('posix_getpid'); if ($configFile = $this->getConfigFile()) { $this->loadConfigFile($configFile); } if (!$this->configFile && $localConfig = $this->getLocalConfigFile()) { $this->loadConfigFile($localConfig); } }
[ "public", "function", "init", "(", ")", "{", "// feature detection", "$", "this", "->", "hasReadline", "=", "\\", "function_exists", "(", "'readline'", ")", ";", "$", "this", "->", "hasPcntl", "=", "\\", "function_exists", "(", "'pcntl_signal'", ")", "&&", "\\", "function_exists", "(", "'posix_getpid'", ")", ";", "if", "(", "$", "configFile", "=", "$", "this", "->", "getConfigFile", "(", ")", ")", "{", "$", "this", "->", "loadConfigFile", "(", "$", "configFile", ")", ";", "}", "if", "(", "!", "$", "this", "->", "configFile", "&&", "$", "localConfig", "=", "$", "this", "->", "getLocalConfigFile", "(", ")", ")", "{", "$", "this", "->", "loadConfigFile", "(", "$", "localConfig", ")", ";", "}", "}" ]
Initialize the configuration. This checks for the presence of Readline and Pcntl extensions. If a config file is available, it will be loaded and merged with the current config. If no custom config file was specified and a local project config file is available, it will be loaded and merged with the current config.
[ "Initialize", "the", "configuration", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L145-L158
bobthecow/psysh
src/Configuration.php
Configuration.getConfigFile
public function getConfigFile() { if (isset($this->configFile)) { return $this->configFile; } $files = ConfigPaths::getConfigFiles(['config.php', 'rc.php'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple configuration files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } return $files[0]; } }
php
public function getConfigFile() { if (isset($this->configFile)) { return $this->configFile; } $files = ConfigPaths::getConfigFiles(['config.php', 'rc.php'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple configuration files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } return $files[0]; } }
[ "public", "function", "getConfigFile", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "configFile", ")", ")", "{", "return", "$", "this", "->", "configFile", ";", "}", "$", "files", "=", "ConfigPaths", "::", "getConfigFiles", "(", "[", "'config.php'", ",", "'rc.php'", "]", ",", "$", "this", "->", "configDir", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "if", "(", "$", "this", "->", "warnOnMultipleConfigs", "&&", "\\", "count", "(", "$", "files", ")", ">", "1", ")", "{", "$", "msg", "=", "\\", "sprintf", "(", "'Multiple configuration files found: %s. Using %s'", ",", "\\", "implode", "(", "$", "files", ",", "', '", ")", ",", "$", "files", "[", "0", "]", ")", ";", "\\", "trigger_error", "(", "$", "msg", ",", "E_USER_NOTICE", ")", ";", "}", "return", "$", "files", "[", "0", "]", ";", "}", "}" ]
Get the current PsySH config file. If a `configFile` option was passed to the Configuration constructor, this file will be returned. If not, all possible config directories will be searched, and the first `config.php` or `rc.php` file which exists will be returned. If you're trying to decide where to put your config file, pick ~/.config/psysh/config.php @return string
[ "Get", "the", "current", "PsySH", "config", "file", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L174-L190
bobthecow/psysh
src/Configuration.php
Configuration.loadConfig
public function loadConfig(array $options) { foreach (self::$AVAILABLE_OPTIONS as $option) { if (isset($options[$option])) { $method = 'set' . \ucfirst($option); $this->$method($options[$option]); } } // legacy `tabCompletion` option if (isset($options['tabCompletion'])) { $msg = '`tabCompletion` is deprecated; use `useTabCompletion` instead.'; @\trigger_error($msg, E_USER_DEPRECATED); $this->setUseTabCompletion($options['tabCompletion']); } foreach (['commands', 'matchers', 'casters'] as $option) { if (isset($options[$option])) { $method = 'add' . \ucfirst($option); $this->$method($options[$option]); } } // legacy `tabCompletionMatchers` option if (isset($options['tabCompletionMatchers'])) { $msg = '`tabCompletionMatchers` is deprecated; use `matchers` instead.'; @\trigger_error($msg, E_USER_DEPRECATED); $this->addMatchers($options['tabCompletionMatchers']); } }
php
public function loadConfig(array $options) { foreach (self::$AVAILABLE_OPTIONS as $option) { if (isset($options[$option])) { $method = 'set' . \ucfirst($option); $this->$method($options[$option]); } } if (isset($options['tabCompletion'])) { $msg = '`tabCompletion` is deprecated; use `useTabCompletion` instead.'; @\trigger_error($msg, E_USER_DEPRECATED); $this->setUseTabCompletion($options['tabCompletion']); } foreach (['commands', 'matchers', 'casters'] as $option) { if (isset($options[$option])) { $method = 'add' . \ucfirst($option); $this->$method($options[$option]); } } if (isset($options['tabCompletionMatchers'])) { $msg = '`tabCompletionMatchers` is deprecated; use `matchers` instead.'; @\trigger_error($msg, E_USER_DEPRECATED); $this->addMatchers($options['tabCompletionMatchers']); } }
[ "public", "function", "loadConfig", "(", "array", "$", "options", ")", "{", "foreach", "(", "self", "::", "$", "AVAILABLE_OPTIONS", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "option", "]", ")", ")", "{", "$", "method", "=", "'set'", ".", "\\", "ucfirst", "(", "$", "option", ")", ";", "$", "this", "->", "$", "method", "(", "$", "options", "[", "$", "option", "]", ")", ";", "}", "}", "// legacy `tabCompletion` option", "if", "(", "isset", "(", "$", "options", "[", "'tabCompletion'", "]", ")", ")", "{", "$", "msg", "=", "'`tabCompletion` is deprecated; use `useTabCompletion` instead.'", ";", "@", "\\", "trigger_error", "(", "$", "msg", ",", "E_USER_DEPRECATED", ")", ";", "$", "this", "->", "setUseTabCompletion", "(", "$", "options", "[", "'tabCompletion'", "]", ")", ";", "}", "foreach", "(", "[", "'commands'", ",", "'matchers'", ",", "'casters'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "option", "]", ")", ")", "{", "$", "method", "=", "'add'", ".", "\\", "ucfirst", "(", "$", "option", ")", ";", "$", "this", "->", "$", "method", "(", "$", "options", "[", "$", "option", "]", ")", ";", "}", "}", "// legacy `tabCompletionMatchers` option", "if", "(", "isset", "(", "$", "options", "[", "'tabCompletionMatchers'", "]", ")", ")", "{", "$", "msg", "=", "'`tabCompletionMatchers` is deprecated; use `matchers` instead.'", ";", "@", "\\", "trigger_error", "(", "$", "msg", ",", "E_USER_DEPRECATED", ")", ";", "$", "this", "->", "addMatchers", "(", "$", "options", "[", "'tabCompletionMatchers'", "]", ")", ";", "}", "}" ]
Load configuration values from an array of options. @param array $options
[ "Load", "configuration", "values", "from", "an", "array", "of", "options", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L214-L245
bobthecow/psysh
src/Configuration.php
Configuration.loadConfigFile
public function loadConfigFile($file) { $__psysh_config_file__ = $file; $load = function ($config) use ($__psysh_config_file__) { $result = require $__psysh_config_file__; if ($result !== 1) { return $result; } }; $result = $load($this); if (!empty($result)) { if (\is_array($result)) { $this->loadConfig($result); } else { throw new \InvalidArgumentException('Psy Shell configuration must return an array of options'); } } }
php
public function loadConfigFile($file) { $__psysh_config_file__ = $file; $load = function ($config) use ($__psysh_config_file__) { $result = require $__psysh_config_file__; if ($result !== 1) { return $result; } }; $result = $load($this); if (!empty($result)) { if (\is_array($result)) { $this->loadConfig($result); } else { throw new \InvalidArgumentException('Psy Shell configuration must return an array of options'); } } }
[ "public", "function", "loadConfigFile", "(", "$", "file", ")", "{", "$", "__psysh_config_file__", "=", "$", "file", ";", "$", "load", "=", "function", "(", "$", "config", ")", "use", "(", "$", "__psysh_config_file__", ")", "{", "$", "result", "=", "require", "$", "__psysh_config_file__", ";", "if", "(", "$", "result", "!==", "1", ")", "{", "return", "$", "result", ";", "}", "}", ";", "$", "result", "=", "$", "load", "(", "$", "this", ")", ";", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "if", "(", "\\", "is_array", "(", "$", "result", ")", ")", "{", "$", "this", "->", "loadConfig", "(", "$", "result", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Psy Shell configuration must return an array of options'", ")", ";", "}", "}", "}" ]
Load a configuration file (default: `$HOME/.config/psysh/config.php`). This configuration instance will be available to the config file as $config. The config file may directly manipulate the configuration, or may return an array of options which will be merged with the current configuration. @throws \InvalidArgumentException if the config file returns a non-array result @param string $file
[ "Load", "a", "configuration", "file", "(", "default", ":", "$HOME", "/", ".", "config", "/", "psysh", "/", "config", ".", "php", ")", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L258-L276
bobthecow/psysh
src/Configuration.php
Configuration.getRuntimeDir
public function getRuntimeDir() { if (!isset($this->runtimeDir)) { $this->runtimeDir = ConfigPaths::getRuntimeDir(); } if (!\is_dir($this->runtimeDir)) { \mkdir($this->runtimeDir, 0700, true); } return $this->runtimeDir; }
php
public function getRuntimeDir() { if (!isset($this->runtimeDir)) { $this->runtimeDir = ConfigPaths::getRuntimeDir(); } if (!\is_dir($this->runtimeDir)) { \mkdir($this->runtimeDir, 0700, true); } return $this->runtimeDir; }
[ "public", "function", "getRuntimeDir", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "runtimeDir", ")", ")", "{", "$", "this", "->", "runtimeDir", "=", "ConfigPaths", "::", "getRuntimeDir", "(", ")", ";", "}", "if", "(", "!", "\\", "is_dir", "(", "$", "this", "->", "runtimeDir", ")", ")", "{", "\\", "mkdir", "(", "$", "this", "->", "runtimeDir", ",", "0700", ",", "true", ")", ";", "}", "return", "$", "this", "->", "runtimeDir", ";", "}" ]
Get the shell's temporary directory location. Defaults to `/psysh` inside the system's temp dir unless explicitly overridden. @return string
[ "Get", "the", "shell", "s", "temporary", "directory", "location", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L356-L367
bobthecow/psysh
src/Configuration.php
Configuration.getHistoryFile
public function getHistoryFile() { if (isset($this->historyFile)) { return $this->historyFile; } $files = ConfigPaths::getConfigFiles(['psysh_history', 'history'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple history files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } $this->setHistoryFile($files[0]); } else { // fallback: create our own history file $dir = $this->configDir ?: ConfigPaths::getCurrentConfigDir(); $this->setHistoryFile($dir . '/psysh_history'); } return $this->historyFile; }
php
public function getHistoryFile() { if (isset($this->historyFile)) { return $this->historyFile; } $files = ConfigPaths::getConfigFiles(['psysh_history', 'history'], $this->configDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple history files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } $this->setHistoryFile($files[0]); } else { $dir = $this->configDir ?: ConfigPaths::getCurrentConfigDir(); $this->setHistoryFile($dir . '/psysh_history'); } return $this->historyFile; }
[ "public", "function", "getHistoryFile", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "historyFile", ")", ")", "{", "return", "$", "this", "->", "historyFile", ";", "}", "$", "files", "=", "ConfigPaths", "::", "getConfigFiles", "(", "[", "'psysh_history'", ",", "'history'", "]", ",", "$", "this", "->", "configDir", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "if", "(", "$", "this", "->", "warnOnMultipleConfigs", "&&", "\\", "count", "(", "$", "files", ")", ">", "1", ")", "{", "$", "msg", "=", "\\", "sprintf", "(", "'Multiple history files found: %s. Using %s'", ",", "\\", "implode", "(", "$", "files", ",", "', '", ")", ",", "$", "files", "[", "0", "]", ")", ";", "\\", "trigger_error", "(", "$", "msg", ",", "E_USER_NOTICE", ")", ";", "}", "$", "this", "->", "setHistoryFile", "(", "$", "files", "[", "0", "]", ")", ";", "}", "else", "{", "// fallback: create our own history file", "$", "dir", "=", "$", "this", "->", "configDir", "?", ":", "ConfigPaths", "::", "getCurrentConfigDir", "(", ")", ";", "$", "this", "->", "setHistoryFile", "(", "$", "dir", ".", "'/psysh_history'", ")", ";", "}", "return", "$", "this", "->", "historyFile", ";", "}" ]
Get the readline history file path. Defaults to `/history` inside the shell's base config dir unless explicitly overridden. @return string
[ "Get", "the", "readline", "history", "file", "path", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L387-L409
bobthecow/psysh
src/Configuration.php
Configuration.useReadline
public function useReadline() { return isset($this->useReadline) ? ($this->hasReadline && $this->useReadline) : $this->hasReadline; }
php
public function useReadline() { return isset($this->useReadline) ? ($this->hasReadline && $this->useReadline) : $this->hasReadline; }
[ "public", "function", "useReadline", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "useReadline", ")", "?", "(", "$", "this", "->", "hasReadline", "&&", "$", "this", "->", "useReadline", ")", ":", "$", "this", "->", "hasReadline", ";", "}" ]
Check whether to use Readline. If `setUseReadline` as been set to true, but Readline is not actually available, this will return false. @return bool True if the current Shell should use Readline
[ "Check", "whether", "to", "use", "Readline", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L511-L514
bobthecow/psysh
src/Configuration.php
Configuration.getReadline
public function getReadline() { if (!isset($this->readline)) { $className = $this->getReadlineClass(); $this->readline = new $className( $this->getHistoryFile(), $this->getHistorySize(), $this->getEraseDuplicates() ); } return $this->readline; }
php
public function getReadline() { if (!isset($this->readline)) { $className = $this->getReadlineClass(); $this->readline = new $className( $this->getHistoryFile(), $this->getHistorySize(), $this->getEraseDuplicates() ); } return $this->readline; }
[ "public", "function", "getReadline", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "readline", ")", ")", "{", "$", "className", "=", "$", "this", "->", "getReadlineClass", "(", ")", ";", "$", "this", "->", "readline", "=", "new", "$", "className", "(", "$", "this", "->", "getHistoryFile", "(", ")", ",", "$", "this", "->", "getHistorySize", "(", ")", ",", "$", "this", "->", "getEraseDuplicates", "(", ")", ")", ";", "}", "return", "$", "this", "->", "readline", ";", "}" ]
Get the Psy Shell readline service. By default, this service uses (in order of preference): * GNU Readline * Libedit * A transient array-based readline emulation. @return Readline
[ "Get", "the", "Psy", "Shell", "readline", "service", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L537-L549
bobthecow/psysh
src/Configuration.php
Configuration.usePcntl
public function usePcntl() { return isset($this->usePcntl) ? ($this->hasPcntl && $this->usePcntl) : $this->hasPcntl; }
php
public function usePcntl() { return isset($this->usePcntl) ? ($this->hasPcntl && $this->usePcntl) : $this->hasPcntl; }
[ "public", "function", "usePcntl", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "usePcntl", ")", "?", "(", "$", "this", "->", "hasPcntl", "&&", "$", "this", "->", "usePcntl", ")", ":", "$", "this", "->", "hasPcntl", ";", "}" ]
Check whether to use Pcntl. If `setUsePcntl` has been set to true, but Pcntl is not actually available, this will return false. @return bool True if the current Shell should use Pcntl
[ "Check", "whether", "to", "use", "Pcntl", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L639-L642
bobthecow/psysh
src/Configuration.php
Configuration.useTabCompletion
public function useTabCompletion() { return isset($this->useTabCompletion) ? ($this->hasReadline && $this->useTabCompletion) : $this->hasReadline; }
php
public function useTabCompletion() { return isset($this->useTabCompletion) ? ($this->hasReadline && $this->useTabCompletion) : $this->hasReadline; }
[ "public", "function", "useTabCompletion", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "useTabCompletion", ")", "?", "(", "$", "this", "->", "hasReadline", "&&", "$", "this", "->", "useTabCompletion", ")", ":", "$", "this", "->", "hasReadline", ";", "}" ]
Check whether to use tab completion. If `setUseTabCompletion` has been set to true, but readline is not actually available, this will return false. @return bool True if the current Shell should use tab completion
[ "Check", "whether", "to", "use", "tab", "completion", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L787-L790
bobthecow/psysh
src/Configuration.php
Configuration.getOutput
public function getOutput() { if (!isset($this->output)) { $this->output = new ShellOutput( ShellOutput::VERBOSITY_NORMAL, $this->getOutputDecorated(), null, $this->getPager() ); } return $this->output; }
php
public function getOutput() { if (!isset($this->output)) { $this->output = new ShellOutput( ShellOutput::VERBOSITY_NORMAL, $this->getOutputDecorated(), null, $this->getPager() ); } return $this->output; }
[ "public", "function", "getOutput", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "output", ")", ")", "{", "$", "this", "->", "output", "=", "new", "ShellOutput", "(", "ShellOutput", "::", "VERBOSITY_NORMAL", ",", "$", "this", "->", "getOutputDecorated", "(", ")", ",", "null", ",", "$", "this", "->", "getPager", "(", ")", ")", ";", "}", "return", "$", "this", "->", "output", ";", "}" ]
Get a Shell Output service instance. If none has been explicitly provided, this will create a new instance with VERBOSITY_NORMAL and the output page supplied by self::getPager @see self::getPager @return ShellOutput
[ "Get", "a", "Shell", "Output", "service", "instance", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L822-L834
bobthecow/psysh
src/Configuration.php
Configuration.getOutputDecorated
public function getOutputDecorated() { if ($this->colorMode() === self::COLOR_MODE_AUTO) { return; } elseif ($this->colorMode() === self::COLOR_MODE_FORCED) { return true; } elseif ($this->colorMode() === self::COLOR_MODE_DISABLED) { return false; } }
php
public function getOutputDecorated() { if ($this->colorMode() === self::COLOR_MODE_AUTO) { return; } elseif ($this->colorMode() === self::COLOR_MODE_FORCED) { return true; } elseif ($this->colorMode() === self::COLOR_MODE_DISABLED) { return false; } }
[ "public", "function", "getOutputDecorated", "(", ")", "{", "if", "(", "$", "this", "->", "colorMode", "(", ")", "===", "self", "::", "COLOR_MODE_AUTO", ")", "{", "return", ";", "}", "elseif", "(", "$", "this", "->", "colorMode", "(", ")", "===", "self", "::", "COLOR_MODE_FORCED", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "this", "->", "colorMode", "(", ")", "===", "self", "::", "COLOR_MODE_DISABLED", ")", "{", "return", "false", ";", "}", "}" ]
Get the decoration (i.e. color) setting for the Shell Output service. @return null|bool 3-state boolean corresponding to the current color mode
[ "Get", "the", "decoration", "(", "i", ".", "e", ".", "color", ")", "setting", "for", "the", "Shell", "Output", "service", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L841-L850
bobthecow/psysh
src/Configuration.php
Configuration.setPager
public function setPager($pager) { if ($pager && !\is_string($pager) && !$pager instanceof OutputPager) { throw new \InvalidArgumentException('Unexpected pager instance'); } $this->pager = $pager; }
php
public function setPager($pager) { if ($pager && !\is_string($pager) && !$pager instanceof OutputPager) { throw new \InvalidArgumentException('Unexpected pager instance'); } $this->pager = $pager; }
[ "public", "function", "setPager", "(", "$", "pager", ")", "{", "if", "(", "$", "pager", "&&", "!", "\\", "is_string", "(", "$", "pager", ")", "&&", "!", "$", "pager", "instanceof", "OutputPager", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unexpected pager instance'", ")", ";", "}", "$", "this", "->", "pager", "=", "$", "pager", ";", "}" ]
Set the OutputPager service. If a string is supplied, a ProcOutputPager will be used which shells out to the specified command. @throws \InvalidArgumentException if $pager is not a string or OutputPager instance @param string|OutputPager $pager
[ "Set", "the", "OutputPager", "service", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L862-L869
bobthecow/psysh
src/Configuration.php
Configuration.getPager
public function getPager() { if (!isset($this->pager) && $this->usePcntl()) { if ($pager = \ini_get('cli.pager')) { // use the default pager $this->pager = $pager; } elseif ($less = \exec('which less 2>/dev/null')) { // check for the presence of less... $this->pager = $less . ' -R -S -F -X'; } } return $this->pager; }
php
public function getPager() { if (!isset($this->pager) && $this->usePcntl()) { if ($pager = \ini_get('cli.pager')) { $this->pager = $pager; } elseif ($less = \exec('which less 2>/dev/null')) { $this->pager = $less . ' -R -S -F -X'; } } return $this->pager; }
[ "public", "function", "getPager", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "pager", ")", "&&", "$", "this", "->", "usePcntl", "(", ")", ")", "{", "if", "(", "$", "pager", "=", "\\", "ini_get", "(", "'cli.pager'", ")", ")", "{", "// use the default pager", "$", "this", "->", "pager", "=", "$", "pager", ";", "}", "elseif", "(", "$", "less", "=", "\\", "exec", "(", "'which less 2>/dev/null'", ")", ")", "{", "// check for the presence of less...", "$", "this", "->", "pager", "=", "$", "less", ".", "' -R -S -F -X'", ";", "}", "}", "return", "$", "this", "->", "pager", ";", "}" ]
Get an OutputPager instance or a command for an external Proc pager. If no Pager has been explicitly provided, and Pcntl is available, this will default to `cli.pager` ini value, falling back to `which less`. @return string|OutputPager
[ "Get", "an", "OutputPager", "instance", "or", "a", "command", "for", "an", "external", "Proc", "pager", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L879-L892
bobthecow/psysh
src/Configuration.php
Configuration.addMatchers
public function addMatchers(array $matchers) { $this->newMatchers = \array_merge($this->newMatchers, $matchers); if (isset($this->shell)) { $this->doAddMatchers(); } }
php
public function addMatchers(array $matchers) { $this->newMatchers = \array_merge($this->newMatchers, $matchers); if (isset($this->shell)) { $this->doAddMatchers(); } }
[ "public", "function", "addMatchers", "(", "array", "$", "matchers", ")", "{", "$", "this", "->", "newMatchers", "=", "\\", "array_merge", "(", "$", "this", "->", "newMatchers", ",", "$", "matchers", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "shell", ")", ")", "{", "$", "this", "->", "doAddMatchers", "(", ")", ";", "}", "}" ]
Add tab completion matchers to the AutoCompleter. This will buffer new matchers in the event that the Shell has not yet been instantiated. This allows the user to specify matchers in their config rc file, despite the fact that their file is needed in the Shell constructor. @param array $matchers
[ "Add", "tab", "completion", "matchers", "to", "the", "AutoCompleter", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L938-L944
bobthecow/psysh
src/Configuration.php
Configuration.doAddMatchers
private function doAddMatchers() { if (!empty($this->newMatchers)) { $this->shell->addMatchers($this->newMatchers); $this->newMatchers = []; } }
php
private function doAddMatchers() { if (!empty($this->newMatchers)) { $this->shell->addMatchers($this->newMatchers); $this->newMatchers = []; } }
[ "private", "function", "doAddMatchers", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "newMatchers", ")", ")", "{", "$", "this", "->", "shell", "->", "addMatchers", "(", "$", "this", "->", "newMatchers", ")", ";", "$", "this", "->", "newMatchers", "=", "[", "]", ";", "}", "}" ]
Internal method for adding tab completion matchers. This will set any new matchers once a Shell is available.
[ "Internal", "method", "for", "adding", "tab", "completion", "matchers", ".", "This", "will", "set", "any", "new", "matchers", "once", "a", "Shell", "is", "available", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L950-L956
bobthecow/psysh
src/Configuration.php
Configuration.addCommands
public function addCommands(array $commands) { $this->newCommands = \array_merge($this->newCommands, $commands); if (isset($this->shell)) { $this->doAddCommands(); } }
php
public function addCommands(array $commands) { $this->newCommands = \array_merge($this->newCommands, $commands); if (isset($this->shell)) { $this->doAddCommands(); } }
[ "public", "function", "addCommands", "(", "array", "$", "commands", ")", "{", "$", "this", "->", "newCommands", "=", "\\", "array_merge", "(", "$", "this", "->", "newCommands", ",", "$", "commands", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "shell", ")", ")", "{", "$", "this", "->", "doAddCommands", "(", ")", ";", "}", "}" ]
Add commands to the Shell. This will buffer new commands in the event that the Shell has not yet been instantiated. This allows the user to specify commands in their config rc file, despite the fact that their file is needed in the Shell constructor. @param array $commands
[ "Add", "commands", "to", "the", "Shell", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L978-L984
bobthecow/psysh
src/Configuration.php
Configuration.doAddCommands
private function doAddCommands() { if (!empty($this->newCommands)) { $this->shell->addCommands($this->newCommands); $this->newCommands = []; } }
php
private function doAddCommands() { if (!empty($this->newCommands)) { $this->shell->addCommands($this->newCommands); $this->newCommands = []; } }
[ "private", "function", "doAddCommands", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "newCommands", ")", ")", "{", "$", "this", "->", "shell", "->", "addCommands", "(", "$", "this", "->", "newCommands", ")", ";", "$", "this", "->", "newCommands", "=", "[", "]", ";", "}", "}" ]
Internal method for adding commands. This will set any new commands once a Shell is available.
[ "Internal", "method", "for", "adding", "commands", ".", "This", "will", "set", "any", "new", "commands", "once", "a", "Shell", "is", "available", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L990-L996
bobthecow/psysh
src/Configuration.php
Configuration.setShell
public function setShell(Shell $shell) { $this->shell = $shell; $this->doAddCommands(); $this->doAddMatchers(); }
php
public function setShell(Shell $shell) { $this->shell = $shell; $this->doAddCommands(); $this->doAddMatchers(); }
[ "public", "function", "setShell", "(", "Shell", "$", "shell", ")", "{", "$", "this", "->", "shell", "=", "$", "shell", ";", "$", "this", "->", "doAddCommands", "(", ")", ";", "$", "this", "->", "doAddMatchers", "(", ")", ";", "}" ]
Set the Shell backreference and add any new commands to the Shell. @param Shell $shell
[ "Set", "the", "Shell", "backreference", "and", "add", "any", "new", "commands", "to", "the", "Shell", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1003-L1008
bobthecow/psysh
src/Configuration.php
Configuration.getManualDbFile
public function getManualDbFile() { if (isset($this->manualDbFile)) { return $this->manualDbFile; } $files = ConfigPaths::getDataFiles(['php_manual.sqlite'], $this->dataDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple manual database files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } return $this->manualDbFile = $files[0]; } }
php
public function getManualDbFile() { if (isset($this->manualDbFile)) { return $this->manualDbFile; } $files = ConfigPaths::getDataFiles(['php_manual.sqlite'], $this->dataDir); if (!empty($files)) { if ($this->warnOnMultipleConfigs && \count($files) > 1) { $msg = \sprintf('Multiple manual database files found: %s. Using %s', \implode($files, ', '), $files[0]); \trigger_error($msg, E_USER_NOTICE); } return $this->manualDbFile = $files[0]; } }
[ "public", "function", "getManualDbFile", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "manualDbFile", ")", ")", "{", "return", "$", "this", "->", "manualDbFile", ";", "}", "$", "files", "=", "ConfigPaths", "::", "getDataFiles", "(", "[", "'php_manual.sqlite'", "]", ",", "$", "this", "->", "dataDir", ")", ";", "if", "(", "!", "empty", "(", "$", "files", ")", ")", "{", "if", "(", "$", "this", "->", "warnOnMultipleConfigs", "&&", "\\", "count", "(", "$", "files", ")", ">", "1", ")", "{", "$", "msg", "=", "\\", "sprintf", "(", "'Multiple manual database files found: %s. Using %s'", ",", "\\", "implode", "(", "$", "files", ",", "', '", ")", ",", "$", "files", "[", "0", "]", ")", ";", "\\", "trigger_error", "(", "$", "msg", ",", "E_USER_NOTICE", ")", ";", "}", "return", "$", "this", "->", "manualDbFile", "=", "$", "files", "[", "0", "]", ";", "}", "}" ]
Get the current PHP manual database file. @return string Default: '~/.local/share/psysh/php_manual.sqlite'
[ "Get", "the", "current", "PHP", "manual", "database", "file", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1028-L1043
bobthecow/psysh
src/Configuration.php
Configuration.getManualDb
public function getManualDb() { if (!isset($this->manualDb)) { $dbFile = $this->getManualDbFile(); if (\is_file($dbFile)) { try { $this->manualDb = new \PDO('sqlite:' . $dbFile); } catch (\PDOException $e) { if ($e->getMessage() === 'could not find driver') { throw new RuntimeException('SQLite PDO driver not found', 0, $e); } else { throw $e; } } } } return $this->manualDb; }
php
public function getManualDb() { if (!isset($this->manualDb)) { $dbFile = $this->getManualDbFile(); if (\is_file($dbFile)) { try { $this->manualDb = new \PDO('sqlite:' . $dbFile); } catch (\PDOException $e) { if ($e->getMessage() === 'could not find driver') { throw new RuntimeException('SQLite PDO driver not found', 0, $e); } else { throw $e; } } } } return $this->manualDb; }
[ "public", "function", "getManualDb", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "manualDb", ")", ")", "{", "$", "dbFile", "=", "$", "this", "->", "getManualDbFile", "(", ")", ";", "if", "(", "\\", "is_file", "(", "$", "dbFile", ")", ")", "{", "try", "{", "$", "this", "->", "manualDb", "=", "new", "\\", "PDO", "(", "'sqlite:'", ".", "$", "dbFile", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "if", "(", "$", "e", "->", "getMessage", "(", ")", "===", "'could not find driver'", ")", "{", "throw", "new", "RuntimeException", "(", "'SQLite PDO driver not found'", ",", "0", ",", "$", "e", ")", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}", "}", "return", "$", "this", "->", "manualDb", ";", "}" ]
Get a PHP manual database connection. @return \PDO
[ "Get", "a", "PHP", "manual", "database", "connection", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1050-L1068
bobthecow/psysh
src/Configuration.php
Configuration.getPresenter
public function getPresenter() { if (!isset($this->presenter)) { $this->presenter = new Presenter($this->getOutput()->getFormatter(), $this->forceArrayIndexes()); } return $this->presenter; }
php
public function getPresenter() { if (!isset($this->presenter)) { $this->presenter = new Presenter($this->getOutput()->getFormatter(), $this->forceArrayIndexes()); } return $this->presenter; }
[ "public", "function", "getPresenter", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "presenter", ")", ")", "{", "$", "this", "->", "presenter", "=", "new", "Presenter", "(", "$", "this", "->", "getOutput", "(", ")", "->", "getFormatter", "(", ")", ",", "$", "this", "->", "forceArrayIndexes", "(", ")", ")", ";", "}", "return", "$", "this", "->", "presenter", ";", "}" ]
Get the Presenter service. @return Presenter
[ "Get", "the", "Presenter", "service", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1085-L1092
bobthecow/psysh
src/Configuration.php
Configuration.setColorMode
public function setColorMode($colorMode) { $validColorModes = [ self::COLOR_MODE_AUTO, self::COLOR_MODE_FORCED, self::COLOR_MODE_DISABLED, ]; if (\in_array($colorMode, $validColorModes)) { $this->colorMode = $colorMode; } else { throw new \InvalidArgumentException('invalid color mode: ' . $colorMode); } }
php
public function setColorMode($colorMode) { $validColorModes = [ self::COLOR_MODE_AUTO, self::COLOR_MODE_FORCED, self::COLOR_MODE_DISABLED, ]; if (\in_array($colorMode, $validColorModes)) { $this->colorMode = $colorMode; } else { throw new \InvalidArgumentException('invalid color mode: ' . $colorMode); } }
[ "public", "function", "setColorMode", "(", "$", "colorMode", ")", "{", "$", "validColorModes", "=", "[", "self", "::", "COLOR_MODE_AUTO", ",", "self", "::", "COLOR_MODE_FORCED", ",", "self", "::", "COLOR_MODE_DISABLED", ",", "]", ";", "if", "(", "\\", "in_array", "(", "$", "colorMode", ",", "$", "validColorModes", ")", ")", "{", "$", "this", "->", "colorMode", "=", "$", "colorMode", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'invalid color mode: '", ".", "$", "colorMode", ")", ";", "}", "}" ]
Set the current color mode. @param string $colorMode
[ "Set", "the", "current", "color", "mode", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1128-L1141
bobthecow/psysh
src/Configuration.php
Configuration.getChecker
public function getChecker() { if (!isset($this->checker)) { $interval = $this->getUpdateCheck(); switch ($interval) { case Checker::ALWAYS: $this->checker = new GitHubChecker(); break; case Checker::DAILY: case Checker::WEEKLY: case Checker::MONTHLY: $checkFile = $this->getUpdateCheckCacheFile(); if ($checkFile === false) { $this->checker = new NoopChecker(); } else { $this->checker = new IntervalChecker($checkFile, $interval); } break; case Checker::NEVER: $this->checker = new NoopChecker(); break; } } return $this->checker; }
php
public function getChecker() { if (!isset($this->checker)) { $interval = $this->getUpdateCheck(); switch ($interval) { case Checker::ALWAYS: $this->checker = new GitHubChecker(); break; case Checker::DAILY: case Checker::WEEKLY: case Checker::MONTHLY: $checkFile = $this->getUpdateCheckCacheFile(); if ($checkFile === false) { $this->checker = new NoopChecker(); } else { $this->checker = new IntervalChecker($checkFile, $interval); } break; case Checker::NEVER: $this->checker = new NoopChecker(); break; } } return $this->checker; }
[ "public", "function", "getChecker", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "checker", ")", ")", "{", "$", "interval", "=", "$", "this", "->", "getUpdateCheck", "(", ")", ";", "switch", "(", "$", "interval", ")", "{", "case", "Checker", "::", "ALWAYS", ":", "$", "this", "->", "checker", "=", "new", "GitHubChecker", "(", ")", ";", "break", ";", "case", "Checker", "::", "DAILY", ":", "case", "Checker", "::", "WEEKLY", ":", "case", "Checker", "::", "MONTHLY", ":", "$", "checkFile", "=", "$", "this", "->", "getUpdateCheckCacheFile", "(", ")", ";", "if", "(", "$", "checkFile", "===", "false", ")", "{", "$", "this", "->", "checker", "=", "new", "NoopChecker", "(", ")", ";", "}", "else", "{", "$", "this", "->", "checker", "=", "new", "IntervalChecker", "(", "$", "checkFile", ",", "$", "interval", ")", ";", "}", "break", ";", "case", "Checker", "::", "NEVER", ":", "$", "this", "->", "checker", "=", "new", "NoopChecker", "(", ")", ";", "break", ";", "}", "}", "return", "$", "this", "->", "checker", ";", "}" ]
Get an update checker service instance. If none has been explicitly defined, this will create a new instance. @return Checker
[ "Get", "an", "update", "checker", "service", "instance", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1170-L1197
bobthecow/psysh
src/Configuration.php
Configuration.setUpdateCheck
public function setUpdateCheck($interval) { $validIntervals = [ Checker::ALWAYS, Checker::DAILY, Checker::WEEKLY, Checker::MONTHLY, Checker::NEVER, ]; if (!\in_array($interval, $validIntervals)) { throw new \InvalidArgumentException('invalid update check interval: ' . $interval); } $this->updateCheck = $interval; }
php
public function setUpdateCheck($interval) { $validIntervals = [ Checker::ALWAYS, Checker::DAILY, Checker::WEEKLY, Checker::MONTHLY, Checker::NEVER, ]; if (!\in_array($interval, $validIntervals)) { throw new \InvalidArgumentException('invalid update check interval: ' . $interval); } $this->updateCheck = $interval; }
[ "public", "function", "setUpdateCheck", "(", "$", "interval", ")", "{", "$", "validIntervals", "=", "[", "Checker", "::", "ALWAYS", ",", "Checker", "::", "DAILY", ",", "Checker", "::", "WEEKLY", ",", "Checker", "::", "MONTHLY", ",", "Checker", "::", "NEVER", ",", "]", ";", "if", "(", "!", "\\", "in_array", "(", "$", "interval", ",", "$", "validIntervals", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'invalid update check interval: '", ".", "$", "interval", ")", ";", "}", "$", "this", "->", "updateCheck", "=", "$", "interval", ";", "}" ]
Set the update check interval. @throws \InvalidArgumentDescription if the update check interval is unknown @param string $interval
[ "Set", "the", "update", "check", "interval", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Configuration.php#L1219-L1234
bobthecow/psysh
src/Command/SudoCommand.php
SudoCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $code = $input->getArgument('code'); // special case for !! if ($code === '!!') { $history = $this->readline->listHistory(); if (\count($history) < 2) { throw new \InvalidArgumentException('No previous command to replay'); } $code = $history[\count($history) - 2]; } if (\strpos('<?', $code) === false) { $code = '<?php ' . $code; } $nodes = $this->traverser->traverse($this->parse($code)); $sudoCode = $this->printer->prettyPrint($nodes); $shell = $this->getApplication(); $shell->addCode($sudoCode, !$shell->hasCode()); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $code = $input->getArgument('code'); if ($code === '!!') { $history = $this->readline->listHistory(); if (\count($history) < 2) { throw new \InvalidArgumentException('No previous command to replay'); } $code = $history[\count($history) - 2]; } if (\strpos('<?', $code) === false) { $code = '<?php ' . $code; } $nodes = $this->traverser->traverse($this->parse($code)); $sudoCode = $this->printer->prettyPrint($nodes); $shell = $this->getApplication(); $shell->addCode($sudoCode, !$shell->hasCode()); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "code", "=", "$", "input", "->", "getArgument", "(", "'code'", ")", ";", "// special case for !!", "if", "(", "$", "code", "===", "'!!'", ")", "{", "$", "history", "=", "$", "this", "->", "readline", "->", "listHistory", "(", ")", ";", "if", "(", "\\", "count", "(", "$", "history", ")", "<", "2", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'No previous command to replay'", ")", ";", "}", "$", "code", "=", "$", "history", "[", "\\", "count", "(", "$", "history", ")", "-", "2", "]", ";", "}", "if", "(", "\\", "strpos", "(", "'<?'", ",", "$", "code", ")", "===", "false", ")", "{", "$", "code", "=", "'<?php '", ".", "$", "code", ";", "}", "$", "nodes", "=", "$", "this", "->", "traverser", "->", "traverse", "(", "$", "this", "->", "parse", "(", "$", "code", ")", ")", ";", "$", "sudoCode", "=", "$", "this", "->", "printer", "->", "prettyPrint", "(", "$", "nodes", ")", ";", "$", "shell", "=", "$", "this", "->", "getApplication", "(", ")", ";", "$", "shell", "->", "addCode", "(", "$", "sudoCode", ",", "!", "$", "shell", "->", "hasCode", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/SudoCommand.php#L99-L121
bobthecow/psysh
src/Command/SudoCommand.php
SudoCommand.parse
private function parse($code) { try { return $this->parser->parse($code); } catch (\PhpParser\Error $e) { if (\strpos($e->getMessage(), 'unexpected EOF') === false) { throw $e; } // If we got an unexpected EOF, let's try it again with a semicolon. return $this->parser->parse($code . ';'); } }
php
private function parse($code) { try { return $this->parser->parse($code); } catch (\PhpParser\Error $e) { if (\strpos($e->getMessage(), 'unexpected EOF') === false) { throw $e; } return $this->parser->parse($code . ';'); } }
[ "private", "function", "parse", "(", "$", "code", ")", "{", "try", "{", "return", "$", "this", "->", "parser", "->", "parse", "(", "$", "code", ")", ";", "}", "catch", "(", "\\", "PhpParser", "\\", "Error", "$", "e", ")", "{", "if", "(", "\\", "strpos", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'unexpected EOF'", ")", "===", "false", ")", "{", "throw", "$", "e", ";", "}", "// If we got an unexpected EOF, let's try it again with a semicolon.", "return", "$", "this", "->", "parser", "->", "parse", "(", "$", "code", ".", "';'", ")", ";", "}", "}" ]
Lex and parse a string of code into statements. @param string $code @return array Statements
[ "Lex", "and", "parse", "a", "string", "of", "code", "into", "statements", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/SudoCommand.php#L130-L142
bobthecow/psysh
src/Command/ShowCommand.php
ShowCommand.configure
protected function configure() { $this ->setName('show') ->setDefinition([ new CodeArgument('target', CodeArgument::OPTIONAL, 'Function, class, instance, constant, method or property to show.'), new InputOption('ex', null, InputOption::VALUE_OPTIONAL, 'Show last exception context. Optionally specify a stack index.', 1), ]) ->setDescription('Show the code for an object, class, constant, method or property.') ->setHelp( <<<HELP Show the code for an object, class, constant, method or property, or the context of the last exception. <return>cat --ex</return> defaults to showing the lines surrounding the location of the last exception. Invoking it more than once travels up the exception's stack trace, and providing a number shows the context of the given index of the trace. e.g. <return>>>> show \$myObject</return> <return>>>> show Psy\Shell::debug</return> <return>>>> show --ex</return> <return>>>> show --ex 3</return> HELP ); }
php
protected function configure() { $this ->setName('show') ->setDefinition([ new CodeArgument('target', CodeArgument::OPTIONAL, 'Function, class, instance, constant, method or property to show.'), new InputOption('ex', null, InputOption::VALUE_OPTIONAL, 'Show last exception context. Optionally specify a stack index.', 1), ]) ->setDescription('Show the code for an object, class, constant, method or property.') ->setHelp( <<<HELP Show the code for an object, class, constant, method or property, or the context of the last exception. <return>cat --ex</return> defaults to showing the lines surrounding the location of the last exception. Invoking it more than once travels up the exception's stack trace, and providing a number shows the context of the given index of the trace. e.g. <return>>>> show \$myObject</return> <return>>>> show Psy\Shell::debug</return> <return>>>> show --ex</return> <return>>>> show --ex 3</return> HELP ); }
[ "protected", "function", "configure", "(", ")", "{", "$", "this", "->", "setName", "(", "'show'", ")", "->", "setDefinition", "(", "[", "new", "CodeArgument", "(", "'target'", ",", "CodeArgument", "::", "OPTIONAL", ",", "'Function, class, instance, constant, method or property to show.'", ")", ",", "new", "InputOption", "(", "'ex'", ",", "null", ",", "InputOption", "::", "VALUE_OPTIONAL", ",", "'Show last exception context. Optionally specify a stack index.'", ",", "1", ")", ",", "]", ")", "->", "setDescription", "(", "'Show the code for an object, class, constant, method or property.'", ")", "->", "setHelp", "(", "\n <<<HELP\nShow the code for an object, class, constant, method or property, or the context\nof the last exception.\n\n<return>cat --ex</return> defaults to showing the lines surrounding the location of the last\nexception. Invoking it more than once travels up the exception's stack trace,\nand providing a number shows the context of the given index of the trace.\n\ne.g.\n<return>>>> show \\$myObject</return>\n<return>>>> show Psy\\Shell::debug</return>\n<return>>>> show --ex</return>\n<return>>>> show --ex 3</return>\nHELP", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ShowCommand.php#L50-L75
bobthecow/psysh
src/Command/ShowCommand.php
ShowCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { // n.b. As far as I can tell, InputInterface doesn't want to tell me // whether an option with an optional value was actually passed. If you // call `$input->getOption('ex')`, it will return the default, both when // `--ex` is specified with no value, and when `--ex` isn't specified at // all. // // So we're doing something sneaky here. If we call `getOptions`, it'll // return the default value when `--ex` is not present, and `null` if // `--ex` is passed with no value. /shrug $opts = $input->getOptions(); // Strict comparison to `1` (the default value) here, because `--ex 1` // will come in as `"1"`. Now we can tell the difference between // "no --ex present", because it's the integer 1, "--ex with no value", // because it's `null`, and "--ex 1", because it's the string "1". if ($opts['ex'] !== 1) { if ($input->getArgument('target')) { throw new \InvalidArgumentException('Too many arguments (supply either "target" or "--ex")'); } return $this->writeExceptionContext($input, $output); } if ($input->getArgument('target')) { return $this->writeCodeContext($input, $output); } throw new RuntimeException('Not enough arguments (missing: "target")'); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $opts = $input->getOptions(); if ($opts['ex'] !== 1) { if ($input->getArgument('target')) { throw new \InvalidArgumentException('Too many arguments (supply either "target" or "--ex")'); } return $this->writeExceptionContext($input, $output); } if ($input->getArgument('target')) { return $this->writeCodeContext($input, $output); } throw new RuntimeException('Not enough arguments (missing: "target")'); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "// n.b. As far as I can tell, InputInterface doesn't want to tell me", "// whether an option with an optional value was actually passed. If you", "// call `$input->getOption('ex')`, it will return the default, both when", "// `--ex` is specified with no value, and when `--ex` isn't specified at", "// all.", "//", "// So we're doing something sneaky here. If we call `getOptions`, it'll", "// return the default value when `--ex` is not present, and `null` if", "// `--ex` is passed with no value. /shrug", "$", "opts", "=", "$", "input", "->", "getOptions", "(", ")", ";", "// Strict comparison to `1` (the default value) here, because `--ex 1`", "// will come in as `\"1\"`. Now we can tell the difference between", "// \"no --ex present\", because it's the integer 1, \"--ex with no value\",", "// because it's `null`, and \"--ex 1\", because it's the string \"1\".", "if", "(", "$", "opts", "[", "'ex'", "]", "!==", "1", ")", "{", "if", "(", "$", "input", "->", "getArgument", "(", "'target'", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Too many arguments (supply either \"target\" or \"--ex\")'", ")", ";", "}", "return", "$", "this", "->", "writeExceptionContext", "(", "$", "input", ",", "$", "output", ")", ";", "}", "if", "(", "$", "input", "->", "getArgument", "(", "'target'", ")", ")", "{", "return", "$", "this", "->", "writeCodeContext", "(", "$", "input", ",", "$", "output", ")", ";", "}", "throw", "new", "RuntimeException", "(", "'Not enough arguments (missing: \"target\")'", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Command/ShowCommand.php#L80-L110
bobthecow/psysh
src/ExecutionLoop.php
ExecutionLoop.run
public function run(Shell $shell) { $this->loadIncludes($shell); $closure = new ExecutionLoopClosure($shell); $closure->execute(); }
php
public function run(Shell $shell) { $this->loadIncludes($shell); $closure = new ExecutionLoopClosure($shell); $closure->execute(); }
[ "public", "function", "run", "(", "Shell", "$", "shell", ")", "{", "$", "this", "->", "loadIncludes", "(", "$", "shell", ")", ";", "$", "closure", "=", "new", "ExecutionLoopClosure", "(", "$", "shell", ")", ";", "$", "closure", "->", "execute", "(", ")", ";", "}" ]
Run the execution loop. @throws ThrowUpException if thrown by the `throw-up` command @param Shell $shell
[ "Run", "the", "execution", "loop", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/ExecutionLoop.php#L28-L34
bobthecow/psysh
src/ExecutionLoop.php
ExecutionLoop.loadIncludes
protected function loadIncludes(Shell $shell) { // Load user-defined includes $load = function (Shell $__psysh__) { \set_error_handler([$__psysh__, 'handleError']); foreach ($__psysh__->getIncludes() as $__psysh_include__) { try { include $__psysh_include__; } catch (\Error $_e) { $__psysh__->writeException(ErrorException::fromError($_e)); } catch (\Exception $_e) { $__psysh__->writeException($_e); } } \restore_error_handler(); unset($__psysh_include__); // Override any new local variables with pre-defined scope variables \extract($__psysh__->getScopeVariables(false)); // ... then add the whole mess of variables back. $__psysh__->setScopeVariables(\get_defined_vars()); }; $load($shell); }
php
protected function loadIncludes(Shell $shell) { $load = function (Shell $__psysh__) { \set_error_handler([$__psysh__, 'handleError']); foreach ($__psysh__->getIncludes() as $__psysh_include__) { try { include $__psysh_include__; } catch (\Error $_e) { $__psysh__->writeException(ErrorException::fromError($_e)); } catch (\Exception $_e) { $__psysh__->writeException($_e); } } \restore_error_handler(); unset($__psysh_include__); \extract($__psysh__->getScopeVariables(false)); $__psysh__->setScopeVariables(\get_defined_vars()); }; $load($shell); }
[ "protected", "function", "loadIncludes", "(", "Shell", "$", "shell", ")", "{", "// Load user-defined includes", "$", "load", "=", "function", "(", "Shell", "$", "__psysh__", ")", "{", "\\", "set_error_handler", "(", "[", "$", "__psysh__", ",", "'handleError'", "]", ")", ";", "foreach", "(", "$", "__psysh__", "->", "getIncludes", "(", ")", "as", "$", "__psysh_include__", ")", "{", "try", "{", "include", "$", "__psysh_include__", ";", "}", "catch", "(", "\\", "Error", "$", "_e", ")", "{", "$", "__psysh__", "->", "writeException", "(", "ErrorException", "::", "fromError", "(", "$", "_e", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "_e", ")", "{", "$", "__psysh__", "->", "writeException", "(", "$", "_e", ")", ";", "}", "}", "\\", "restore_error_handler", "(", ")", ";", "unset", "(", "$", "__psysh_include__", ")", ";", "// Override any new local variables with pre-defined scope variables", "\\", "extract", "(", "$", "__psysh__", "->", "getScopeVariables", "(", "false", ")", ")", ";", "// ... then add the whole mess of variables back.", "$", "__psysh__", "->", "setScopeVariables", "(", "\\", "get_defined_vars", "(", ")", ")", ";", "}", ";", "$", "load", "(", "$", "shell", ")", ";", "}" ]
Load user-defined includes. @param Shell $shell
[ "Load", "user", "-", "defined", "includes", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/ExecutionLoop.php#L41-L66
bobthecow/psysh
src/CodeCleaner/StrictTypesPass.php
StrictTypesPass.beforeTraverse
public function beforeTraverse(array $nodes) { if (!$this->atLeastPhp7) { return; // @codeCoverageIgnore } $prependStrictTypes = $this->strictTypes; foreach ($nodes as $key => $node) { if ($node instanceof Declare_) { foreach ($node->declares as $declare) { // For PHP Parser 4.x $declareKey = $declare->key instanceof Identifier ? $declare->key->toString() : $declare->key; if ($declareKey === 'strict_types') { $value = $declare->value; if (!$value instanceof LNumber || ($value->value !== 0 && $value->value !== 1)) { throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine()); } $this->strictTypes = $value->value === 1; } } } } if ($prependStrictTypes) { $first = \reset($nodes); if (!$first instanceof Declare_) { $declare = new Declare_([new DeclareDeclare('strict_types', new LNumber(1))]); \array_unshift($nodes, $declare); } } return $nodes; }
php
public function beforeTraverse(array $nodes) { if (!$this->atLeastPhp7) { return; } $prependStrictTypes = $this->strictTypes; foreach ($nodes as $key => $node) { if ($node instanceof Declare_) { foreach ($node->declares as $declare) { $declareKey = $declare->key instanceof Identifier ? $declare->key->toString() : $declare->key; if ($declareKey === 'strict_types') { $value = $declare->value; if (!$value instanceof LNumber || ($value->value !== 0 && $value->value !== 1)) { throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine()); } $this->strictTypes = $value->value === 1; } } } } if ($prependStrictTypes) { $first = \reset($nodes); if (!$first instanceof Declare_) { $declare = new Declare_([new DeclareDeclare('strict_types', new LNumber(1))]); \array_unshift($nodes, $declare); } } return $nodes; }
[ "public", "function", "beforeTraverse", "(", "array", "$", "nodes", ")", "{", "if", "(", "!", "$", "this", "->", "atLeastPhp7", ")", "{", "return", ";", "// @codeCoverageIgnore", "}", "$", "prependStrictTypes", "=", "$", "this", "->", "strictTypes", ";", "foreach", "(", "$", "nodes", "as", "$", "key", "=>", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "Declare_", ")", "{", "foreach", "(", "$", "node", "->", "declares", "as", "$", "declare", ")", "{", "// For PHP Parser 4.x", "$", "declareKey", "=", "$", "declare", "->", "key", "instanceof", "Identifier", "?", "$", "declare", "->", "key", "->", "toString", "(", ")", ":", "$", "declare", "->", "key", ";", "if", "(", "$", "declareKey", "===", "'strict_types'", ")", "{", "$", "value", "=", "$", "declare", "->", "value", ";", "if", "(", "!", "$", "value", "instanceof", "LNumber", "||", "(", "$", "value", "->", "value", "!==", "0", "&&", "$", "value", "->", "value", "!==", "1", ")", ")", "{", "throw", "new", "FatalErrorException", "(", "self", "::", "EXCEPTION_MESSAGE", ",", "0", ",", "E_ERROR", ",", "null", ",", "$", "node", "->", "getLine", "(", ")", ")", ";", "}", "$", "this", "->", "strictTypes", "=", "$", "value", "->", "value", "===", "1", ";", "}", "}", "}", "}", "if", "(", "$", "prependStrictTypes", ")", "{", "$", "first", "=", "\\", "reset", "(", "$", "nodes", ")", ";", "if", "(", "!", "$", "first", "instanceof", "Declare_", ")", "{", "$", "declare", "=", "new", "Declare_", "(", "[", "new", "DeclareDeclare", "(", "'strict_types'", ",", "new", "LNumber", "(", "1", ")", ")", "]", ")", ";", "\\", "array_unshift", "(", "$", "nodes", ",", "$", "declare", ")", ";", "}", "}", "return", "$", "nodes", ";", "}" ]
If this is a standalone strict types declaration, remember it for later. Otherwise, apply remembered strict types declaration to to the code until a new declaration is encountered. @throws FatalErrorException if an invalid `strict_types` declaration is found @param array $nodes
[ "If", "this", "is", "a", "standalone", "strict", "types", "declaration", "remember", "it", "for", "later", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/CodeCleaner/StrictTypesPass.php#L52-L86
bobthecow/psysh
src/Util/Mirror.php
Mirror.get
public static function get($value, $member = null, $filter = 15) { if ($member === null && \is_string($value)) { if (\function_exists($value)) { return new \ReflectionFunction($value); } elseif (\defined($value) || ReflectionConstant_::isMagicConstant($value)) { return new ReflectionConstant_($value); } } $class = self::getClass($value); if ($member === null) { return $class; } elseif ($filter & self::CONSTANT && $class->hasConstant($member)) { return ReflectionClassConstant::create($value, $member); } elseif ($filter & self::METHOD && $class->hasMethod($member)) { return $class->getMethod($member); } elseif ($filter & self::PROPERTY && $class->hasProperty($member)) { return $class->getProperty($member); } elseif ($filter & self::STATIC_PROPERTY && $class->hasProperty($member) && $class->getProperty($member)->isStatic()) { return $class->getProperty($member); } else { throw new RuntimeException(\sprintf( 'Unknown member %s on class %s', $member, \is_object($value) ? \get_class($value) : $value )); } }
php
public static function get($value, $member = null, $filter = 15) { if ($member === null && \is_string($value)) { if (\function_exists($value)) { return new \ReflectionFunction($value); } elseif (\defined($value) || ReflectionConstant_::isMagicConstant($value)) { return new ReflectionConstant_($value); } } $class = self::getClass($value); if ($member === null) { return $class; } elseif ($filter & self::CONSTANT && $class->hasConstant($member)) { return ReflectionClassConstant::create($value, $member); } elseif ($filter & self::METHOD && $class->hasMethod($member)) { return $class->getMethod($member); } elseif ($filter & self::PROPERTY && $class->hasProperty($member)) { return $class->getProperty($member); } elseif ($filter & self::STATIC_PROPERTY && $class->hasProperty($member) && $class->getProperty($member)->isStatic()) { return $class->getProperty($member); } else { throw new RuntimeException(\sprintf( 'Unknown member %s on class %s', $member, \is_object($value) ? \get_class($value) : $value )); } }
[ "public", "static", "function", "get", "(", "$", "value", ",", "$", "member", "=", "null", ",", "$", "filter", "=", "15", ")", "{", "if", "(", "$", "member", "===", "null", "&&", "\\", "is_string", "(", "$", "value", ")", ")", "{", "if", "(", "\\", "function_exists", "(", "$", "value", ")", ")", "{", "return", "new", "\\", "ReflectionFunction", "(", "$", "value", ")", ";", "}", "elseif", "(", "\\", "defined", "(", "$", "value", ")", "||", "ReflectionConstant_", "::", "isMagicConstant", "(", "$", "value", ")", ")", "{", "return", "new", "ReflectionConstant_", "(", "$", "value", ")", ";", "}", "}", "$", "class", "=", "self", "::", "getClass", "(", "$", "value", ")", ";", "if", "(", "$", "member", "===", "null", ")", "{", "return", "$", "class", ";", "}", "elseif", "(", "$", "filter", "&", "self", "::", "CONSTANT", "&&", "$", "class", "->", "hasConstant", "(", "$", "member", ")", ")", "{", "return", "ReflectionClassConstant", "::", "create", "(", "$", "value", ",", "$", "member", ")", ";", "}", "elseif", "(", "$", "filter", "&", "self", "::", "METHOD", "&&", "$", "class", "->", "hasMethod", "(", "$", "member", ")", ")", "{", "return", "$", "class", "->", "getMethod", "(", "$", "member", ")", ";", "}", "elseif", "(", "$", "filter", "&", "self", "::", "PROPERTY", "&&", "$", "class", "->", "hasProperty", "(", "$", "member", ")", ")", "{", "return", "$", "class", "->", "getProperty", "(", "$", "member", ")", ";", "}", "elseif", "(", "$", "filter", "&", "self", "::", "STATIC_PROPERTY", "&&", "$", "class", "->", "hasProperty", "(", "$", "member", ")", "&&", "$", "class", "->", "getProperty", "(", "$", "member", ")", "->", "isStatic", "(", ")", ")", "{", "return", "$", "class", "->", "getProperty", "(", "$", "member", ")", ";", "}", "else", "{", "throw", "new", "RuntimeException", "(", "\\", "sprintf", "(", "'Unknown member %s on class %s'", ",", "$", "member", ",", "\\", "is_object", "(", "$", "value", ")", "?", "\\", "get_class", "(", "$", "value", ")", ":", "$", "value", ")", ")", ";", "}", "}" ]
Get a Reflector for a function, class or instance, constant, method or property. Optionally, pass a $filter param to restrict the types of members checked. For example, to only Reflectors for static properties and constants, pass: $filter = Mirror::CONSTANT | Mirror::STATIC_PROPERTY @throws \Psy\Exception\RuntimeException when a $member specified but not present on $value @throws \InvalidArgumentException if $value is something other than an object or class/function name @param mixed $value Class or function name, or variable instance @param string $member Optional: property, constant or method name (default: null) @param int $filter (default: CONSTANT | METHOD | PROPERTY | STATIC_PROPERTY) @return \Reflector
[ "Get", "a", "Reflector", "for", "a", "function", "class", "or", "instance", "constant", "method", "or", "property", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Util/Mirror.php#L45-L74
bobthecow/psysh
src/Util/Mirror.php
Mirror.getClass
private static function getClass($value) { if (\is_object($value)) { return new \ReflectionObject($value); } if (!\is_string($value)) { throw new \InvalidArgumentException('Mirror expects an object or class'); } elseif (!\class_exists($value) && !\interface_exists($value) && !\trait_exists($value)) { throw new \InvalidArgumentException('Unknown class or function: ' . $value); } return new \ReflectionClass($value); }
php
private static function getClass($value) { if (\is_object($value)) { return new \ReflectionObject($value); } if (!\is_string($value)) { throw new \InvalidArgumentException('Mirror expects an object or class'); } elseif (!\class_exists($value) && !\interface_exists($value) && !\trait_exists($value)) { throw new \InvalidArgumentException('Unknown class or function: ' . $value); } return new \ReflectionClass($value); }
[ "private", "static", "function", "getClass", "(", "$", "value", ")", "{", "if", "(", "\\", "is_object", "(", "$", "value", ")", ")", "{", "return", "new", "\\", "ReflectionObject", "(", "$", "value", ")", ";", "}", "if", "(", "!", "\\", "is_string", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Mirror expects an object or class'", ")", ";", "}", "elseif", "(", "!", "\\", "class_exists", "(", "$", "value", ")", "&&", "!", "\\", "interface_exists", "(", "$", "value", ")", "&&", "!", "\\", "trait_exists", "(", "$", "value", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Unknown class or function: '", ".", "$", "value", ")", ";", "}", "return", "new", "\\", "ReflectionClass", "(", "$", "value", ")", ";", "}" ]
Get a ReflectionClass (or ReflectionObject) if possible. @throws \InvalidArgumentException if $value is not a class name or instance @param mixed $value @return \ReflectionClass
[ "Get", "a", "ReflectionClass", "(", "or", "ReflectionObject", ")", "if", "possible", "." ]
train
https://github.com/bobthecow/psysh/blob/9aaf29575bb8293206bb0420c1e1c87ff2ffa94e/src/Util/Mirror.php#L85-L98