code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function __construct($name, $field, $missing = null, $mode = null)
{
parent::__construct($name);
$this->setField($field);
$this->setMode($mode);
$this->missing = $missing;
} | Inner aggregations container init.
@param string $name
@param string|array $field Fields list to aggregate.
@param array $missing
@param string $mode | __construct | php | ongr-io/ElasticsearchDSL | src/Aggregation/Matrix/MatrixStatsAggregation.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/src/Aggregation/Matrix/MatrixStatsAggregation.php | MIT |
private function order(array $data)
{
$filteredData = $this->filterOrderable($data);
if (!empty($filteredData)) {
uasort(
$filteredData,
function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) {
return $a->getOrder() > $b->getOrder();
}
);
return array_merge($filteredData, array_diff_key($data, $filteredData));
}
return $data;
} | Orders objects if can be done.
@param array $data Data to order.
@return array | order | php | ongr-io/ElasticsearchDSL | src/Serializer/OrderedSerializer.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/src/Serializer/OrderedSerializer.php | MIT |
private function filterOrderable($array)
{
return array_filter(
$array,
function ($value) {
return $value instanceof OrderedNormalizerInterface;
}
);
} | Filters out data which can be ordered.
@param array $array Data to filter out.
@return array | filterOrderable | php | ongr-io/ElasticsearchDSL | src/Serializer/OrderedSerializer.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/src/Serializer/OrderedSerializer.php | MIT |
public function setTags(array $preTags, array $postTags)
{
$this->tags['pre_tags'] = $preTags;
$this->tags['post_tags'] = $postTags;
return $this;
} | Sets html tag and its class used in highlighting.
@param array $preTags
@param array $postTags
@return $this | setTags | php | ongr-io/ElasticsearchDSL | src/Highlight/Highlight.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/src/Highlight/Highlight.php | MIT |
public function getTestToArrayData()
{
$out = [];
$matchQuery = new MatchQuery('foo.bar.aux', 'foo');
$nestedQuery = new NestedQuery('foo.bar', $matchQuery);
$searchQuery = new Search();
$searchQuery->addQuery($nestedQuery);
$matchSearch = new Search();
$matchSearch->addQuery($matchQuery);
$innerHit = new NestedInnerHit('acme', 'foo', $searchQuery);
$emptyInnerHit = new NestedInnerHit('acme', 'foo');
$nestedInnerHit1 = new NestedInnerHit('aux', 'foo.bar.aux', $matchSearch);
$nestedInnerHit2 = new NestedInnerHit('lux', 'foo.bar.aux', $matchSearch);
$searchQuery->addInnerHit($nestedInnerHit1);
$searchQuery->addInnerHit($nestedInnerHit2);
$out[] = [
$emptyInnerHit,
[
'path' => [
'foo' => new \stdClass(),
],
],
];
$out[] = [
$nestedInnerHit1,
[
'path' => [
'foo.bar.aux' => [
'query' => $matchQuery->toArray(),
],
],
],
];
$out[] = [
$innerHit,
[
'path' => [
'foo' => [
'query' => $nestedQuery->toArray(),
'inner_hits' => [
'aux' => [
'path' => [
'foo.bar.aux' => [
'query' => $matchQuery->toArray(),
],
],
],
'lux' => [
'path' => [
'foo.bar.aux' => [
'query' => $matchQuery->toArray(),
],
],
]
],
],
],
],
];
return $out;
} | Data provider for testToArray().
@return array | getTestToArrayData | php | ongr-io/ElasticsearchDSL | tests/Unit/InnerHit/NestedInnerHitTest.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Unit/InnerHit/NestedInnerHitTest.php | MIT |
public function getArrayDataProvider()
{
$out = [];
$filterData = [
'field' => 'location',
'precision' => 3,
'size' => 10,
'shard_size' => 10,
];
$expectedResults = [
'field' => 'location',
'precision' => 3,
'size' => 10,
'shard_size' => 10,
];
$out[] = [$filterData, $expectedResults];
return $out;
} | Data provider for testGeoHashGridAggregationGetArray().
@return array | getArrayDataProvider | php | ongr-io/ElasticsearchDSL | tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php | MIT |
public function getToArrayData()
{
$out = [];
// Case #0 filter aggregation.
$aggregation = new FilterAggregation('test_agg');
$filter = new MatchAllQuery();
$aggregation->setFilter($filter);
$result = [
'filter' => $filter->toArray(),
];
$out[] = [
$aggregation,
$result,
];
// Case #1 nested filter aggregation.
$aggregation = new FilterAggregation('test_agg');
$aggregation->setFilter($filter);
$histogramAgg = new HistogramAggregation('acme', 'bar', 10);
$aggregation->addAggregation($histogramAgg);
$result = [
'filter' => $filter->toArray(),
'aggregations' => [
$histogramAgg->getName() => $histogramAgg->toArray(),
],
];
$out[] = [
$aggregation,
$result,
];
// Case #2 testing bool filter.
$aggregation = new FilterAggregation('test_agg');
$matchAllFilter = new MatchAllQuery();
$termFilter = new TermQuery('acme', 'foo');
$boolFilter = new BoolQuery();
$boolFilter->add($matchAllFilter);
$boolFilter->add($termFilter);
$aggregation->setFilter($boolFilter);
$result = [
'filter' => $boolFilter->toArray(),
];
$out[] = [
$aggregation,
$result,
];
return $out;
} | Data provider for testToArray.
@return array | getToArrayData | php | ongr-io/ElasticsearchDSL | tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php | MIT |
protected function getMapping()
{
return [];
} | Defines index mapping for test index.
Override this function in your test case and return array with mapping body.
More info check here: https://goo.gl/zWBree
@return array Mapping body | getMapping | php | ongr-io/ElasticsearchDSL | tests/Functional/AbstractElasticsearchTestCase.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Functional/AbstractElasticsearchTestCase.php | MIT |
protected function getDataArray()
{
return [];
} | Can be overwritten in child class to populate elasticsearch index with the data.
Example:
[
'type_name' => [
'custom_id' => [
'title' => 'foo',
],
3 => [
'_id' => 2,
'title' => 'bar',
]
]
]
Document _id can be set as it's id.
@return array | getDataArray | php | ongr-io/ElasticsearchDSL | tests/Functional/AbstractElasticsearchTestCase.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Functional/AbstractElasticsearchTestCase.php | MIT |
protected function executeSearch(Search $search, $type = null, $returnRaw = false)
{
$response = $this->client->search(
array_filter([
'index' => self::INDEX_NAME,
'type' => $type,
'body' => $search->toArray(),
])
);
if ($returnRaw) {
return $response;
}
$documents = [];
try {
foreach ($response['hits']['hits'] as $document) {
$documents[$document['_id']] = $document['_source'];
}
} catch (\Exception $e) {
return $documents;
}
return $documents;
} | Execute search to the elasticsearch and handle results.
@param Search $search Search object.
@param null $type Types to search. Can be several types split by comma.
@param bool $returnRaw Return raw response from the client.
@return array | executeSearch | php | ongr-io/ElasticsearchDSL | tests/Functional/AbstractElasticsearchTestCase.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Functional/AbstractElasticsearchTestCase.php | MIT |
private function deleteIndex()
{
try {
$this->client->indices()->delete(['index' => self::INDEX_NAME]);
} catch (\Exception $e) {
// Do nothing.
}
} | Deletes index from elasticsearch. | deleteIndex | php | ongr-io/ElasticsearchDSL | tests/Functional/AbstractElasticsearchTestCase.php | https://github.com/ongr-io/ElasticsearchDSL/blob/master/tests/Functional/AbstractElasticsearchTestCase.php | MIT |
public function getInput(bool $interactive = true)
{
$this->codeBufferOpen = false;
do {
// reset output verbosity (in case it was altered by a subcommand)
$this->output->setVerbosity($this->originalVerbosity);
$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
* 3) When non-interactive, return, because that's the end of stdin
*/
if ($input === false) {
if (!$interactive) {
return;
}
$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 (!$interactive || !$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
@param bool $interactive | getInput | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function setScopeVariables(array $vars)
{
$this->context->setAll($vars);
} | Set the variables currently in scope.
@param array $vars | setScopeVariables | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function getScopeVariable(string $name)
{
return $this->context->get($name);
} | Get a scope variable value by name.
@param string $name
@return mixed | getScopeVariable | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function setBoundObject($boundObject)
{
$this->context->setBoundObject($boundObject);
} | Set the bound object ($this variable) for the interactive shell.
@param object|null $boundObject | setBoundObject | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function getBoundObject()
{
return $this->context->getBoundObject();
} | Get the bound object ($this variable) for the interactive shell.
@return object|null | getBoundObject | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function setBoundClass($boundClass)
{
$this->context->setBoundClass($boundClass);
} | Set the bound class (self) for the interactive shell.
@param string|null $boundClass | setBoundClass | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function getBoundClass()
{
return $this->context->getBoundClass();
} | Get the bound class (self) for the interactive shell.
@return string|null | getBoundClass | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function setIncludes(array $includes = [])
{
$this->includes = $includes;
} | Add includes, to be parsed and executed before running the interactive shell.
@param array $includes | setIncludes | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
private function setCode(string $code, bool $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;
}
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 | setCode | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
protected function runCommand(string $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'])) {
try {
return $command->run($input, $this->output);
} catch (\Exception $e) {
if (!self::needsInputHelp($e)) {
throw $e;
}
$this->writeException($e);
$this->output->writeln('--');
if (!$this->config->theme()->compact()) {
$this->output->writeln('');
}
}
}
$helpCommand = $this->get('help');
if (!$helpCommand instanceof Command\HelpCommand) {
throw new RuntimeException('Invalid help command instance');
}
$helpCommand->setCommand($command);
return $helpCommand->run(new StringInput(''), $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? | runCommand | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function resetCodeBuffer()
{
$this->codeBuffer = [];
$this->code = false;
} | Reset the current code buffer.
This should be run after evaluating user input, catching exceptions, or
on demand by commands such as BufferCommand. | resetCodeBuffer | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
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|null PHP code buffer contents | flushCode | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
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. | popCodeStack | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
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 | addHistory | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
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. | addCodeBufferToHistory | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function getNamespace()
{
if ($namespace = $this->cleaner->getNamespace()) {
return \implode('\\', $namespace);
}
} | Get the current evaluation scope namespace.
@see CodeCleaner::getNamespace
@return string|null Current code namespace | getNamespace | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function writeStdout(string $out, int $phase = \PHP_OUTPUT_HANDLER_END)
{
if ($phase & \PHP_OUTPUT_HANDLER_START) {
if ($this->output instanceof ShellOutput) {
$this->output->startPaging();
}
}
$isCleaning = $phase & \PHP_OUTPUT_HANDLER_CLEAN;
// Incremental flush
if ($out !== '' && !$isCleaning) {
$this->output->write($out, false, OutputInterface::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) {
if (!$this->config->rawOutput() && !$this->config->outputIsPiped()) {
$this->output->writeln(\sprintf('<whisper>%s</whisper>', $this->config->useUnicode() ? '⏎' : '\\n'));
} else {
$this->output->writeln('');
}
$this->outputWantsNewline = false;
}
// Save the stdout buffer as $__out
if ($this->stdoutBuffer !== '') {
$this->context->setLastStdout($this->stdoutBuffer);
$this->stdoutBuffer = '';
}
if ($this->output instanceof ShellOutput) {
$this->output->stopPaging();
}
}
} | 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 | writeStdout | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function writeReturnValue($ret, bool $rawOutput = false)
{
$this->lastExecSuccess = true;
if ($ret instanceof NoReturnValue) {
return;
}
$this->context->setReturnValue($ret);
if ($rawOutput) {
$formatted = \var_export($ret, true);
} else {
$prompt = $this->config->theme()->returnValue();
$indent = \str_repeat(' ', \strlen($prompt));
$formatted = $this->presentValue($ret);
$formattedRetValue = \sprintf('<whisper>%s</whisper>', $prompt);
$formatted = $formattedRetValue.\str_replace(\PHP_EOL, \PHP_EOL.$indent, $formatted);
}
if ($this->output instanceof ShellOutput) {
$this->output->page($formatted.\PHP_EOL);
} else {
$this->output->writeln($formatted);
}
} | 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
@param bool $rawOutput Write raw var_export-style values | writeReturnValue | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function writeException(\Throwable $e)
{
// No need to write the break exception during a non-interactive run.
if ($e instanceof BreakException && $this->nonInteractive) {
$this->resetCodeBuffer();
return;
}
// Break exceptions don't count :)
if (!$e instanceof BreakException) {
$this->lastExecSuccess = false;
$this->context->setLastException($e);
}
$output = $this->output;
if ($output instanceof ConsoleOutput) {
$output = $output->getErrorOutput();
}
if (!$this->config->theme()->compact()) {
$output->writeln('');
}
$output->writeln($this->formatException($e));
if (!$this->config->theme()->compact()) {
$output->writeln('');
}
// Include an exception trace (as long as this isn't a BreakException).
if (!$e instanceof BreakException && $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$trace = TraceFormatter::formatTrace($e);
if (\count($trace) !== 0) {
$output->writeln('--');
$output->write($trace, true);
$output->writeln('');
}
}
$this->resetCodeBuffer();
} | Renders a caught Exception or Error.
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 \Throwable $e An exception or error instance | writeException | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function execute(string $code, bool $throwExceptions = false)
{
$this->setCode($code, true);
$closure = new ExecutionClosure($this);
if ($throwExceptions) {
return $closure->execute();
}
try {
return $closure->execute();
} catch (\Throwable $_e) {
$this->writeException($_e);
}
} | Execute code in the shell execution context.
@param string $code
@param bool $throwExceptions
@return mixed | execute | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
protected function getCommand(string $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 BaseCommand|null | getCommand | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
protected function readline(bool $interactive = true)
{
$prompt = $this->config->theme()->replayPrompt();
if (!empty($this->inputBuffer)) {
$line = \array_shift($this->inputBuffer);
if (!$line instanceof SilentInput) {
$this->output->writeln(\sprintf('<whisper>%s</whisper><aside>%s</aside>', $prompt, OutputFormatter::escape($line)));
}
return $line;
}
$bracketedPaste = $interactive && $this->config->useBracketedPaste();
if ($bracketedPaste) {
\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.
@param bool $interactive
@return string|false One line of user input | readline | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function getManualDb()
{
return $this->config->getManualDb();
} | Get a PHP manual database instance.
@return \PDO|null | getManualDb | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
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. | initializeTabCompletion | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
protected function writeStartupMessage()
{
$message = $this->config->getStartupMessage();
if ($message !== null && $message !== '') {
$this->output->writeln($message);
}
} | Write a startup message if set. | writeStartupMessage | php | bobthecow/psysh | src/Shell.php | https://github.com/bobthecow/psysh/blob/master/src/Shell.php | MIT |
public function get(string $key)
{
if (isset($_SERVER[$key]) && $_SERVER[$key]) {
return $_SERVER[$key];
}
$result = \getenv($key);
return $result === false ? null : $result;
} | Get an environment variable by name.
@return string|null | get | php | bobthecow/psysh | src/SystemEnv.php | https://github.com/bobthecow/psysh/blob/master/src/SystemEnv.php | MIT |
public function setReturnValue($value)
{
$this->returnValue = $value;
} | Set the most recent return value.
@param mixed $value | setReturnValue | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function getReturnValue()
{
return $this->returnValue;
} | Get the most recent return value.
@return mixed | getReturnValue | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function setLastException(\Throwable $e)
{
$this->lastException = $e;
} | Set the most recent Exception or Error.
@param \Throwable $e | setLastException | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function getLastException()
{
if (!isset($this->lastException)) {
throw new \InvalidArgumentException('No most-recent exception');
}
return $this->lastException;
} | Get the most recent Exception or Error.
@throws \InvalidArgumentException If no Exception has been caught
@return \Throwable|null | getLastException | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function setLastStdout(string $lastStdout)
{
$this->lastStdout = $lastStdout;
} | Set the most recent output from evaluated code. | setLastStdout | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function getLastStdout()
{
if (!isset($this->lastStdout)) {
throw new \InvalidArgumentException('No most-recent output');
}
return $this->lastStdout;
} | Get the most recent output from evaluated code.
@throws \InvalidArgumentException If no output has happened yet
@return string|null | getLastStdout | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
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 | setBoundObject | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
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 | setBoundClass | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public function setCommandScopeVariables(array $commandScopeVariables)
{
$vars = [];
foreach ($commandScopeVariables as $key => $value) {
// kind of type check
if (\is_scalar($value) && \in_array($key, self::COMMAND_SCOPE_NAMES)) {
$vars[$key] = $value;
}
}
$this->commandScopeVariables = $vars;
} | Set command-scope magic variables: $__class, $__file, etc. | setCommandScopeVariables | php | bobthecow/psysh | src/Context.php | https://github.com/bobthecow/psysh/blob/master/src/Context.php | MIT |
public static function fetchProperty($object, string $property)
{
$prop = self::getProperty(new \ReflectionObject($object), $property);
return $prop->getValue($object);
} | Fetch a property of an object, bypassing visibility restrictions.
@param object $object
@param string $property property name
@return mixed Value of $object->property | fetchProperty | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function assignProperty($object, string $property, $value)
{
$prop = self::getProperty(new \ReflectionObject($object), $property);
$prop->setValue($object, $value);
return $value;
} | Assign the value of a property of an object, bypassing visibility restrictions.
@param object $object
@param string $property property name
@param mixed $value
@return mixed Value of $object->property | assignProperty | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function callMethod($object, string $method, ...$args)
{
$refl = new \ReflectionObject($object);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs($object, $args);
} | Call a method on an object, bypassing visibility restrictions.
@param object $object
@param string $method method name
@param mixed $args...
@return mixed | callMethod | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function fetchStaticProperty($class, string $property)
{
$prop = self::getProperty(new \ReflectionClass($class), $property);
$prop->setAccessible(true);
return $prop->getValue();
} | Fetch a property of a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $property property name
@return mixed Value of $class::$property | fetchStaticProperty | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function assignStaticProperty($class, string $property, $value)
{
$prop = self::getProperty(new \ReflectionClass($class), $property);
$refl = $prop->getDeclaringClass();
if (\method_exists($refl, 'setStaticPropertyValue')) {
$refl->setStaticPropertyValue($property, $value);
} else {
$prop->setValue($value);
}
return $value;
} | Assign the value of a static property of a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $property property name
@param mixed $value
@return mixed Value of $class::$property | assignStaticProperty | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function callStatic($class, string $method, ...$args)
{
$refl = new \ReflectionClass($class);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
return $reflMethod->invokeArgs(null, $args);
} | Call a static method on a class, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $method method name
@param mixed $args...
@return mixed | callStatic | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function fetchClassConst($class, string $const)
{
$refl = new \ReflectionClass($class);
// Special case the ::class magic constant, because `getConstant` does the wrong thing here.
if ($const === 'class') {
return $refl->getName();
}
do {
if ($refl->hasConstant($const)) {
return $refl->getConstant($const);
}
$refl = $refl->getParentClass();
} while ($refl !== false);
return false;
} | Fetch a class constant, bypassing visibility restrictions.
@param string|object $class class name or instance
@param string $const constant name
@return mixed | fetchClassConst | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public static function newInstance(string $class, ...$args)
{
$refl = new \ReflectionClass($class);
$instance = $refl->newInstanceWithoutConstructor();
$constructor = $refl->getConstructor();
$constructor->setAccessible(true);
$constructor->invokeArgs($instance, $args);
return $instance;
} | Construct an instance of a class, bypassing private constructors.
@param string $class class name
@param mixed $args... | newInstance | php | bobthecow/psysh | src/Sudo.php | https://github.com/bobthecow/psysh/blob/master/src/Sudo.php | MIT |
public function __construct(array $overrides = [], ?EnvInterface $env = null)
{
$this->overrideDirs($overrides);
$this->env = $env ?: (\PHP_SAPI === 'cli-server' ? new SystemEnv() : new SuperglobalsEnv());
} | ConfigPaths constructor.
Optionally provide `configDir`, `dataDir` and `runtimeDir` overrides.
@see self::overrideDirs
@param string[] $overrides Directory overrides
@param EnvInterface $env | __construct | php | bobthecow/psysh | src/ConfigPaths.php | https://github.com/bobthecow/psysh/blob/master/src/ConfigPaths.php | MIT |
public function overrideDirs(array $overrides)
{
if (\array_key_exists('configDir', $overrides)) {
$this->configDir = $overrides['configDir'] ?: null;
}
if (\array_key_exists('dataDir', $overrides)) {
$this->dataDir = $overrides['dataDir'] ?: null;
}
if (\array_key_exists('runtimeDir', $overrides)) {
$this->runtimeDir = $overrides['runtimeDir'] ?: null;
}
} | Provide `configDir`, `dataDir` and `runtimeDir` overrides.
If a key is set but empty, the override will be removed. If it is not set
at all, any existing override will persist.
@param string[] $overrides Directory overrides | overrideDirs | php | bobthecow/psysh | src/ConfigPaths.php | https://github.com/bobthecow/psysh/blob/master/src/ConfigPaths.php | MIT |
public static function touchFileWithMkdir(string $file)
{
if (\file_exists($file)) {
if (\is_writable($file)) {
return $file;
}
\trigger_error(\sprintf('Writing to %s is not allowed.', $file), \E_USER_NOTICE);
return false;
}
if (!self::ensureDir(\dirname($file))) {
return false;
}
\touch($file);
return $file;
} | Ensure that $file exists and is writable, make the parent directory if necessary.
Generates E_USER_NOTICE error if either $file or its directory is not writable.
@param string $file
@return string|false Full path to $file, or false if file is not writable | touchFileWithMkdir | php | bobthecow/psysh | src/ConfigPaths.php | https://github.com/bobthecow/psysh/blob/master/src/ConfigPaths.php | MIT |
public function __construct(array $config = [])
{
$this->configPaths = new ConfigPaths();
// explicit configFile option
if (isset($config['configFile'])) {
$this->configFile = $config['configFile'];
} elseif (isset($_SERVER['PSYSH_CONFIG']) && $_SERVER['PSYSH_CONFIG']) {
$this->configFile = $_SERVER['PSYSH_CONFIG'];
} elseif (\PHP_SAPI === 'cli-server' && ($configFile = \getenv('PSYSH_CONFIG'))) {
$this->configFile = $configFile;
}
// legacy baseDir option
if (isset($config['baseDir'])) {
$msg = "The 'baseDir' configuration option is deprecated; ".
"please specify 'configDir' and 'dataDir' options instead";
throw new DeprecatedException($msg);
}
unset($config['configFile'], $config['baseDir']);
// go go gadget, config!
$this->loadConfig($config);
$this->init();
} | Construct a Configuration instance.
Optionally, supply an array of configuration values to load.
@param array $config Optional array of configuration values | __construct | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
private static function getConfigFileFromInput(InputInterface $input)
{
// Best case, input is properly bound and validated.
if ($input->hasOption('config')) {
return $input->getOption('config');
}
return $input->getParameterOption('--config', null, true) ?: $input->getParameterOption('-c', null, true);
} | Get the desired config file from the given input.
@return string|null config file path, or null if none is specified | getConfigFileFromInput | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
private static function getVerbosityFromInput(InputInterface $input)
{
// --quiet wins!
if (self::getOptionFromInput($input, ['quiet'], ['-q'])) {
return self::VERBOSITY_QUIET;
}
// Best case, input is properly bound and validated.
//
// Note that if the `--verbose` option is incorrectly defined as `VALUE_NONE` rather than
// `VALUE_OPTIONAL` (as it is in Symfony Console by default) it doesn't actually work with
// multiple verbosity levels as it claims.
//
// We can detect this by checking whether the the value === true, and fall back to unbound
// parsing for this option.
if ($input->hasOption('verbose') && $input->getOption('verbose') !== true) {
switch ($input->getOption('verbose')) {
case '-1':
return self::VERBOSITY_QUIET;
case '0': // explicitly normal, overrides config file default
return self::VERBOSITY_NORMAL;
case '1':
case null: // `--verbose` and `-v`
return self::VERBOSITY_VERBOSE;
case '2':
case 'v': // `-vv`
return self::VERBOSITY_VERY_VERBOSE;
case '3':
case 'vv': // `-vvv`
case 'vvv':
case 'vvvv':
case 'vvvvv':
case 'vvvvvv':
case 'vvvvvvv':
return self::VERBOSITY_DEBUG;
default: // implicitly normal, config file default wins
return;
}
}
// quiet and normal have to come before verbose, because it eats everything else.
if ($input->hasParameterOption('--verbose=-1', true) || $input->getParameterOption('--verbose', false, true) === '-1') {
return self::VERBOSITY_QUIET;
}
if ($input->hasParameterOption('--verbose=0', true) || $input->getParameterOption('--verbose', false, true) === '0') {
return self::VERBOSITY_NORMAL;
}
// `-vvv`, `-vv` and `-v` have to come in descending length order, because `hasParameterOption` matches prefixes.
if ($input->hasParameterOption('-vvv', true) || $input->hasParameterOption('--verbose=3', true) || $input->getParameterOption('--verbose', false, true) === '3') {
return self::VERBOSITY_DEBUG;
}
if ($input->hasParameterOption('-vv', true) || $input->hasParameterOption('--verbose=2', true) || $input->getParameterOption('--verbose', false, true) === '2') {
return self::VERBOSITY_VERY_VERBOSE;
}
if ($input->hasParameterOption('-v', true) || $input->hasParameterOption('--verbose=1', true) || $input->hasParameterOption('--verbose', true)) {
return self::VERBOSITY_VERBOSE;
}
} | Get the desired verbosity from the given input.
This is a bit more complext than the other options parsers. It handles `--quiet` and
`--verbose`, along with their short aliases, and fancy things like `-vvv`.
@return string|null configuration constant, or null if no verbosity option is specified | getVerbosityFromInput | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function init()
{
// feature detection
$this->hasReadline = \function_exists('readline');
$this->hasPcntl = ProcessForker::isSupported();
if ($configFile = $this->getConfigFile()) {
$this->loadConfigFile($configFile);
}
if (!$this->configFile && $localConfig = $this->getLocalConfigFile()) {
$this->loadConfigFile($localConfig);
}
$this->configPaths->overrideDirs([
'configDir' => $this->configDir,
'dataDir' => $this->dataDir,
'runtimeDir' => $this->runtimeDir,
]);
} | 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. | init | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getConfigFile()
{
if (isset($this->configFile)) {
return $this->configFile;
}
$files = $this->configPaths->configFiles(['config.php', 'rc.php']);
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|null | getConfigFile | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getLocalConfigFile()
{
$localConfig = \getcwd().'/.psysh.php';
if (@\is_file($localConfig)) {
return $localConfig;
}
} | Get the local PsySH config file.
Searches for a project specific config file `.psysh.php` in the current
working directory.
@return string|null | getLocalConfigFile | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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 | loadConfig | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setDefaultIncludes(array $includes = [])
{
$this->defaultIncludes = $includes;
} | Set files to be included by default at the start of each shell session.
@param array $includes | setDefaultIncludes | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setConfigDir(string $dir)
{
$this->configDir = (string) $dir;
$this->configPaths->overrideDirs([
'configDir' => $this->configDir,
'dataDir' => $this->dataDir,
'runtimeDir' => $this->runtimeDir,
]);
} | Set the shell's config directory location.
@param string $dir | setConfigDir | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getConfigDir()
{
return $this->configDir;
} | Get the current configuration directory, if any is explicitly set.
@return string|null | getConfigDir | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setDataDir(string $dir)
{
$this->dataDir = (string) $dir;
$this->configPaths->overrideDirs([
'configDir' => $this->configDir,
'dataDir' => $this->dataDir,
'runtimeDir' => $this->runtimeDir,
]);
} | Set the shell's data directory location.
@param string $dir | setDataDir | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getDataDir()
{
return $this->dataDir;
} | Get the current data directory, if any is explicitly set.
@return string|null | getDataDir | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setRuntimeDir(string $dir)
{
$this->runtimeDir = (string) $dir;
$this->configPaths->overrideDirs([
'configDir' => $this->configDir,
'dataDir' => $this->dataDir,
'runtimeDir' => $this->runtimeDir,
]);
} | Set the shell's temporary directory location.
@param string $dir | setRuntimeDir | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setHistoryFile(string $file)
{
$this->historyFile = ConfigPaths::touchFileWithMkdir($file);
} | Set the readline history file path.
@param string $file | setHistoryFile | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setHistorySize(int $value)
{
$this->historySize = (int) $value;
} | Set the readline max history size.
@param int $value | setHistorySize | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getHistorySize()
{
return $this->historySize;
} | Get the readline max history size.
@return int | getHistorySize | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setEraseDuplicates(bool $value)
{
$this->eraseDuplicates = $value;
} | Sets whether readline erases old duplicate history entries.
@param bool $value | setEraseDuplicates | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getEraseDuplicates()
{
return $this->eraseDuplicates;
} | Get whether readline erases old duplicate history entries.
@return bool|null | getEraseDuplicates | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setUseReadline(bool $useReadline)
{
$this->useReadline = (bool) $useReadline;
} | Enable or disable Readline usage.
@param bool $useReadline | setUseReadline | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setReadline(Readline\Readline $readline)
{
$this->readline = $readline;
} | Set the Psy Shell readline service.
@param Readline\Readline $readline | setReadline | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setUseBracketedPaste(bool $useBracketedPaste)
{
$this->useBracketedPaste = (bool) $useBracketedPaste;
} | Enable or disable bracketed paste.
Note that this only works with readline (not libedit) integration for now.
@param bool $useBracketedPaste | setUseBracketedPaste | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setUsePcntl(bool $usePcntl)
{
$this->usePcntl = (bool) $usePcntl;
} | Enable or disable Pcntl usage.
@param bool $usePcntl | setUsePcntl | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setRequireSemicolons(bool $requireSemicolons)
{
$this->requireSemicolons = (bool) $requireSemicolons;
} | Enable or disable strict requirement of semicolons.
@see self::requireSemicolons()
@param bool $requireSemicolons | setRequireSemicolons | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setStrictTypes($strictTypes)
{
$this->strictTypes = (bool) $strictTypes;
} | Enable or disable strict types enforcement. | setStrictTypes | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setUseUnicode(bool $useUnicode)
{
$this->useUnicode = (bool) $useUnicode;
} | Enable or disable Unicode in PsySH specific output.
Note that this does not disable Unicode output in general, it just makes
it so PsySH won't output any itself.
@param bool $useUnicode | setUseUnicode | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setCodeCleaner(CodeCleaner $cleaner)
{
$this->cleaner = $cleaner;
} | Set a CodeCleaner service instance.
@param CodeCleaner $cleaner | setCodeCleaner | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setYolo($yolo)
{
$this->yolo = (bool) $yolo;
} | Enable or disable running PsySH without input validation.
You don't want this. | setYolo | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setUseTabCompletion(bool $useTabCompletion)
{
$this->useTabCompletion = (bool) $useTabCompletion;
} | Enable or disable tab completion.
@param bool $useTabCompletion | setUseTabCompletion | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getOutputDecorated()
{
switch ($this->colorMode()) {
case self::COLOR_MODE_FORCED:
return true;
case self::COLOR_MODE_DISABLED:
return false;
case self::COLOR_MODE_AUTO:
default:
return $this->outputIsPiped() ? false : null;
}
} | Get the decoration (i.e. color) setting for the Shell Output service.
@return bool|null 3-state boolean corresponding to the current color mode | getOutputDecorated | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setPager($pager)
{
if ($pager === null || $pager === false || $pager === 'cat') {
$pager = false;
}
if ($pager !== false && !\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.
`cat` is special-cased to use the PassthruPager directly.
@throws \InvalidArgumentException if $pager is not a string or OutputPager instance
@param string|OutputPager|false $pager | setPager | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getPager()
{
if (!isset($this->pager) && $this->usePcntl()) {
if (\getenv('TERM') === 'dumb') {
return false;
}
if ($pager = \ini_get('cli.pager')) {
// use the default pager
$this->pager = $pager;
} elseif ($less = $this->configPaths->which('less')) {
// check for the presence of less...
// n.b. The busybox less implementation is a bit broken, so
// let's not use it by default.
//
// See https://github.com/bobthecow/psysh/issues/778
if (@\is_link($less)) {
$link = @\readlink($less);
if ($link !== false && \strpos($link, 'busybox') !== false) {
return false;
}
}
$this->pager = $less.' -R -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|false | getPager | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setAutoCompleter(AutoCompleter $autoCompleter)
{
$this->autoCompleter = $autoCompleter;
} | Set the Shell AutoCompleter service.
@param AutoCompleter $autoCompleter | setAutoCompleter | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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 | addMatchers | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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. | doAddMatchers | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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 | addCommands | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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. | doAddCommands | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
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 | setShell | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setManualDbFile(string $filename)
{
$this->manualDbFile = (string) $filename;
} | Set the PHP manual database file.
This file should be an SQLite database generated from the phpdoc source
with the `bin/build_manual` script.
@param string $filename | setManualDbFile | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getManualDbFile()
{
if (isset($this->manualDbFile)) {
return $this->manualDbFile;
}
$files = $this->configPaths->dataFiles(['php_manual.sqlite']);
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|null Default: '~/.local/share/psysh/php_manual.sqlite' | getManualDbFile | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function getManualDb()
{
if (!isset($this->manualDb)) {
$dbFile = $this->getManualDbFile();
if ($dbFile !== null && \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|null | getManualDb | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function addCasters(array $casters)
{
$this->getPresenter()->addCasters($casters);
} | Add an array of casters definitions.
@param array $casters | addCasters | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setWarnOnMultipleConfigs(bool $warnOnMultipleConfigs)
{
$this->warnOnMultipleConfigs = (bool) $warnOnMultipleConfigs;
} | Enable or disable warnings on multiple configuration or data files.
@see self::warnOnMultipleConfigs()
@param bool $warnOnMultipleConfigs | setWarnOnMultipleConfigs | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
public function setInteractiveMode(string $interactiveMode)
{
$validInteractiveModes = [
self::INTERACTIVE_MODE_AUTO,
self::INTERACTIVE_MODE_FORCED,
self::INTERACTIVE_MODE_DISABLED,
];
if (!\in_array($interactiveMode, $validInteractiveModes)) {
throw new \InvalidArgumentException('Invalid interactive mode: '.$interactiveMode);
}
$this->interactiveMode = $interactiveMode;
} | Set the shell's interactive mode.
@throws \InvalidArgumentException if interactive mode isn't disabled, forced, or auto
@param string $interactiveMode | setInteractiveMode | php | bobthecow/psysh | src/Configuration.php | https://github.com/bobthecow/psysh/blob/master/src/Configuration.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.