Aggiornato Composer
This commit is contained in:
16
vendor/psy/psysh/src/Command/BufferCommand.php
vendored
16
vendor/psy/psysh/src/Command/BufferCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Psy\Command;
|
||||
|
||||
use Psy\Exception\RuntimeException;
|
||||
use Psy\Output\ShellOutput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -46,12 +47,19 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$buf = $this->getApplication()->getCodeBuffer();
|
||||
$app = $this->getApplication();
|
||||
if (!$app instanceof \Psy\Shell) {
|
||||
throw new RuntimeException('Buffer command requires a \Psy\Shell application');
|
||||
}
|
||||
|
||||
$buf = $app->getCodeBuffer();
|
||||
if ($input->getOption('clear')) {
|
||||
$this->getApplication()->resetCodeBuffer();
|
||||
$app->resetCodeBuffer();
|
||||
$output->writeln($this->formatLines($buf, 'urgent'), ShellOutput::NUMBER_LINES);
|
||||
} else {
|
||||
$output->writeln($this->formatLines($buf), ShellOutput::NUMBER_LINES);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -41,8 +41,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$output->write(\sprintf('%c[2J%c[0;0f', 27, 27));
|
||||
|
||||
|
||||
49
vendor/psy/psysh/src/Command/Command.php
vendored
49
vendor/psy/psysh/src/Command/Command.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -15,7 +15,6 @@ use Psy\Shell;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command as BaseCommand;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableHelper;
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -31,13 +30,13 @@ abstract class Command extends BaseCommand
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setApplication(Application $application = null)
|
||||
public function setApplication(?Application $application = null): void
|
||||
{
|
||||
if ($application !== null && !$application instanceof Shell) {
|
||||
throw new \InvalidArgumentException('PsySH Commands require an instance of Psy\Shell');
|
||||
}
|
||||
|
||||
return parent::setApplication($application);
|
||||
parent::setApplication($application);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +85,7 @@ abstract class Command extends BaseCommand
|
||||
/**
|
||||
* These arguments will be excluded from help output.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getHiddenArguments(): array
|
||||
{
|
||||
@@ -108,7 +107,7 @@ abstract class Command extends BaseCommand
|
||||
/**
|
||||
* These options will be excluded from help output.
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getHiddenOptions(): array
|
||||
{
|
||||
@@ -117,8 +116,6 @@ abstract class Command extends BaseCommand
|
||||
|
||||
/**
|
||||
* Format command aliases as text..
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function aliasesAsText(): string
|
||||
{
|
||||
@@ -127,8 +124,6 @@ abstract class Command extends BaseCommand
|
||||
|
||||
/**
|
||||
* Format command arguments as text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function argumentsAsText(): string
|
||||
{
|
||||
@@ -147,7 +142,7 @@ abstract class Command extends BaseCommand
|
||||
|
||||
$description = \str_replace("\n", "\n".\str_pad('', $max + 2, ' '), $argument->getDescription());
|
||||
|
||||
$messages[] = \sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $description, $default);
|
||||
$messages[] = \sprintf(" <info>%-{$max}s</info> %s%s", $argument->getName(), $description, $default);
|
||||
}
|
||||
|
||||
$messages[] = '';
|
||||
@@ -158,8 +153,6 @@ abstract class Command extends BaseCommand
|
||||
|
||||
/**
|
||||
* Format options as text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function optionsAsText(): string
|
||||
{
|
||||
@@ -182,7 +175,7 @@ abstract class Command extends BaseCommand
|
||||
|
||||
$optionMax = $max - \strlen($option->getName()) - 2;
|
||||
$messages[] = \sprintf(
|
||||
" <info>%s</info> %-${optionMax}s%s%s%s",
|
||||
" <info>%s</info> %-{$optionMax}s%s%s%s",
|
||||
'--'.$option->getName(),
|
||||
$option->getShortcut() ? \sprintf('(-%s) ', $option->getShortcut()) : '',
|
||||
$description,
|
||||
@@ -199,8 +192,6 @@ abstract class Command extends BaseCommand
|
||||
|
||||
/**
|
||||
* Calculate the maximum padding width for a set of lines.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getMaxWidth(): int
|
||||
{
|
||||
@@ -226,8 +217,6 @@ abstract class Command extends BaseCommand
|
||||
* Format an option default as text.
|
||||
*
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatDefaultValue($default): string
|
||||
{
|
||||
@@ -241,16 +230,10 @@ abstract class Command extends BaseCommand
|
||||
/**
|
||||
* Get a Table instance.
|
||||
*
|
||||
* Falls back to legacy TableHelper.
|
||||
*
|
||||
* @return Table|TableHelper
|
||||
* @return Table
|
||||
*/
|
||||
protected function getTable(OutputInterface $output)
|
||||
{
|
||||
if (!\class_exists(Table::class)) {
|
||||
return $this->getTableHelper();
|
||||
}
|
||||
|
||||
$style = new TableStyle();
|
||||
|
||||
// Symfony 4.1 deprecated single-argument style setters.
|
||||
@@ -270,20 +253,4 @@ abstract class Command extends BaseCommand
|
||||
->setRows([])
|
||||
->setStyle($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy fallback for getTable.
|
||||
*
|
||||
* @return TableHelper
|
||||
*/
|
||||
protected function getTableHelper(): TableHelper
|
||||
{
|
||||
$table = $this->getApplication()->getHelperSet()->get('table');
|
||||
|
||||
return $table
|
||||
->setRows([])
|
||||
->setLayout(TableHelper::LAYOUT_BORDERLESS)
|
||||
->setHorizontalBorderChar('')
|
||||
->setCrossingChar('');
|
||||
}
|
||||
}
|
||||
|
||||
20
vendor/psy/psysh/src/Command/DocCommand.php
vendored
20
vendor/psy/psysh/src/Command/DocCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -14,8 +14,8 @@ namespace Psy\Command;
|
||||
use Psy\Formatter\DocblockFormatter;
|
||||
use Psy\Formatter\SignatureFormatter;
|
||||
use Psy\Input\CodeArgument;
|
||||
use Psy\Reflection\ReflectionClassConstant;
|
||||
use Psy\Reflection\ReflectionConstant_;
|
||||
use Psy\Output\ShellOutput;
|
||||
use Psy\Reflection\ReflectionConstant;
|
||||
use Psy\Reflection\ReflectionLanguageConstruct;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -59,8 +59,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$value = $input->getArgument('target');
|
||||
if (ReflectionLanguageConstruct::isLanguageConstruct($value)) {
|
||||
@@ -143,14 +145,13 @@ HELP
|
||||
break;
|
||||
|
||||
case \ReflectionClassConstant::class:
|
||||
case ReflectionClassConstant::class:
|
||||
// @todo this is going to collide with ReflectionMethod ids
|
||||
// someday... start running the query by id + type if the DB
|
||||
// supports it.
|
||||
$id = $reflector->class.'::'.$reflector->name;
|
||||
break;
|
||||
|
||||
case ReflectionConstant_::class:
|
||||
case ReflectionConstant::class:
|
||||
$id = $reflector->name;
|
||||
break;
|
||||
|
||||
@@ -242,9 +243,10 @@ HELP
|
||||
private function getManualDocById($id)
|
||||
{
|
||||
if ($db = $this->getApplication()->getManualDb()) {
|
||||
return $db
|
||||
->query(\sprintf('SELECT doc FROM php_manual WHERE id = %s', $db->quote($id)))
|
||||
->fetchColumn(0);
|
||||
$result = $db->query(\sprintf('SELECT doc FROM php_manual WHERE id = %s', $db->quote($id)));
|
||||
if ($result !== false) {
|
||||
return $result->fetchColumn(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
vendor/psy/psysh/src/Command/DumpCommand.php
vendored
20
vendor/psy/psysh/src/Command/DumpCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -66,8 +66,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$depth = $input->getOption('depth');
|
||||
$target = $this->resolveCode($input->getArgument('target'));
|
||||
@@ -79,18 +81,4 @@ HELP
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `resolveCode` instead
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resolveTarget(string $name)
|
||||
{
|
||||
@\trigger_error('`resolveTarget` is deprecated; use `resolveCode` instead.', \E_USER_DEPRECATED);
|
||||
|
||||
return $this->resolveCode($name);
|
||||
}
|
||||
}
|
||||
|
||||
14
vendor/psy/psysh/src/Command/EditCommand.php
vendored
14
vendor/psy/psysh/src/Command/EditCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -74,10 +74,12 @@ class EditCommand extends Command implements ContextAware
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if ($input->getOption('exec') &&
|
||||
$input->getOption('no-exec')) {
|
||||
@@ -112,10 +114,8 @@ class EditCommand extends Command implements ContextAware
|
||||
* @param bool $execOption
|
||||
* @param bool $noExecOption
|
||||
* @param string|null $filePath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldExecuteFile(bool $execOption, bool $noExecOption, string $filePath = null): bool
|
||||
private function shouldExecuteFile(bool $execOption, bool $noExecOption, ?string $filePath = null): bool
|
||||
{
|
||||
if ($execOption) {
|
||||
return true;
|
||||
@@ -136,7 +136,7 @@ class EditCommand extends Command implements ContextAware
|
||||
*
|
||||
* @throws \InvalidArgumentException If the variable is not found in the current context
|
||||
*/
|
||||
private function extractFilePath(string $fileArgument = null)
|
||||
private function extractFilePath(?string $fileArgument = null)
|
||||
{
|
||||
// If the file argument was a variable, get it from the context
|
||||
if ($fileArgument !== null &&
|
||||
@@ -152,8 +152,6 @@ class EditCommand extends Command implements ContextAware
|
||||
* @param string $filePath
|
||||
* @param bool $shouldRemoveFile
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \UnexpectedValueException if file_get_contents on $filePath returns false instead of a string
|
||||
*/
|
||||
private function editFile(string $filePath, bool $shouldRemoveFile): string
|
||||
|
||||
6
vendor/psy/psysh/src/Command/ExitCommand.php
vendored
6
vendor/psy/psysh/src/Command/ExitCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -44,8 +44,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
throw new BreakException('Goodbye');
|
||||
}
|
||||
|
||||
13
vendor/psy/psysh/src/Command/HelpCommand.php
vendored
13
vendor/psy/psysh/src/Command/HelpCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace Psy\Command;
|
||||
|
||||
use Psy\Output\ShellOutput;
|
||||
use Symfony\Component\Console\Helper\TableHelper;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -53,8 +52,10 @@ class HelpCommand extends Command
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
if ($this->command !== null) {
|
||||
// help for an individual command
|
||||
@@ -91,11 +92,7 @@ class HelpCommand extends Command
|
||||
$output->startPaging();
|
||||
}
|
||||
|
||||
if ($table instanceof TableHelper) {
|
||||
$table->render($output);
|
||||
} else {
|
||||
$table->render();
|
||||
}
|
||||
$table->render();
|
||||
|
||||
if ($output instanceof ShellOutput) {
|
||||
$output->stopPaging();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -90,8 +90,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->validateOnlyOne($input, ['show', 'head', 'tail']);
|
||||
$this->validateOnlyOne($input, ['save', 'replay', 'clear']);
|
||||
|
||||
15
vendor/psy/psysh/src/Command/ListCommand.php
vendored
15
vendor/psy/psysh/src/Command/ListCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -26,7 +26,6 @@ use Psy\Output\ShellOutput;
|
||||
use Psy\VarDumper\Presenter;
|
||||
use Psy\VarDumper\PresenterAware;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\TableHelper;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -112,8 +111,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->validateInput($input);
|
||||
$this->initEnumerators();
|
||||
@@ -211,11 +212,7 @@ HELP
|
||||
$table->addRow([$this->formatItemName($item), $item['value']]);
|
||||
}
|
||||
|
||||
if ($table instanceof TableHelper) {
|
||||
$table->render($output);
|
||||
} else {
|
||||
$table->render();
|
||||
}
|
||||
$table->render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +220,6 @@ HELP
|
||||
* Format an item name given its visibility.
|
||||
*
|
||||
* @param array $item
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatItemName(array $item): string
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Reflection\ReflectionClassConstant;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
@@ -22,7 +21,7 @@ class ClassConstantEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list constants when a Reflector is present.
|
||||
if ($reflector === null) {
|
||||
@@ -56,18 +55,18 @@ class ClassConstantEnumerator extends Enumerator
|
||||
/**
|
||||
* Get defined constants for the given class or object Reflector.
|
||||
*
|
||||
* @param \Reflector $reflector
|
||||
* @param bool $noInherit Exclude inherited constants
|
||||
* @param \ReflectionClass $reflector
|
||||
* @param bool $noInherit Exclude inherited constants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConstants(\Reflector $reflector, bool $noInherit = false): array
|
||||
protected function getConstants(\ReflectionClass $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
$constants = [];
|
||||
foreach ($reflector->getConstants() as $name => $constant) {
|
||||
$constReflector = ReflectionClassConstant::create($reflector->name, $name);
|
||||
$constReflector = new \ReflectionClassConstant($reflector->name, $name);
|
||||
|
||||
if ($noInherit && $constReflector->getDeclaringClass()->getName() !== $className) {
|
||||
continue;
|
||||
@@ -110,8 +109,6 @@ class ClassConstantEnumerator extends Enumerator
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -22,7 +22,7 @@ class ClassEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// if we have a reflector, ensure that it's a namespace reflector
|
||||
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
|
||||
@@ -66,7 +66,7 @@ class ClassEnumerator extends Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function filterClasses(string $key, array $classes, bool $internal, bool $user, string $prefix = null): array
|
||||
protected function filterClasses(string $key, array $classes, bool $internal, bool $user, ?string $prefix = null): array
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -49,7 +49,7 @@ class ConstantEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// if we have a reflector, ensure that it's a namespace reflector
|
||||
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
|
||||
@@ -122,7 +122,7 @@ class ConstantEnumerator extends Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConstants(string $category = null): array
|
||||
protected function getConstants(?string $category = null): array
|
||||
{
|
||||
if (!$category) {
|
||||
return \get_defined_constants();
|
||||
@@ -133,7 +133,7 @@ class ConstantEnumerator extends Enumerator
|
||||
if ($category === 'internal') {
|
||||
unset($consts['user']);
|
||||
|
||||
return \call_user_func_array('array_merge', \array_values($consts));
|
||||
return \array_merge(...\array_values($consts));
|
||||
}
|
||||
|
||||
foreach ($consts as $key => $value) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -54,7 +54,7 @@ abstract class Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
public function enumerate(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
$this->filter->bind($input);
|
||||
|
||||
@@ -82,7 +82,7 @@ abstract class Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array;
|
||||
abstract protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array;
|
||||
|
||||
protected function showItem($name)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -22,7 +22,7 @@ class FunctionEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// if we have a reflector, ensure that it's a namespace reflector
|
||||
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
|
||||
@@ -67,7 +67,7 @@ class FunctionEnumerator extends Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFunctions(string $type = null): array
|
||||
protected function getFunctions(?string $type = null): array
|
||||
{
|
||||
$funcs = \get_defined_functions();
|
||||
|
||||
@@ -86,7 +86,7 @@ class FunctionEnumerator extends Enumerator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareFunctions(array $functions, string $prefix = null): array
|
||||
protected function prepareFunctions(array $functions, ?string $prefix = null): array
|
||||
{
|
||||
\natcasesort($functions);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -21,7 +21,7 @@ class GlobalVariableEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list globals when no Reflector is present.
|
||||
if ($reflector !== null || $target !== null) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -21,7 +21,7 @@ class MethodEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list methods when a Reflector is present.
|
||||
if ($reflector === null) {
|
||||
@@ -55,13 +55,13 @@ class MethodEnumerator extends Enumerator
|
||||
/**
|
||||
* Get defined methods for the given class or object Reflector.
|
||||
*
|
||||
* @param bool $showAll Include private and protected methods
|
||||
* @param \Reflector $reflector
|
||||
* @param bool $noInherit Exclude inherited methods
|
||||
* @param bool $showAll Include private and protected methods
|
||||
* @param \ReflectionClass $reflector
|
||||
* @param bool $noInherit Exclude inherited methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getMethods(bool $showAll, \Reflector $reflector, bool $noInherit = false): array
|
||||
protected function getMethods(bool $showAll, \ReflectionClass $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
@@ -112,8 +112,6 @@ class MethodEnumerator extends Enumerator
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
@@ -130,8 +128,6 @@ class MethodEnumerator extends Enumerator
|
||||
* Get output style for the given method's visibility.
|
||||
*
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getVisibilityStyle(\ReflectionMethod $method): string
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -21,7 +21,7 @@ class PropertyEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list properties when a Reflector is present.
|
||||
|
||||
@@ -56,13 +56,13 @@ class PropertyEnumerator extends Enumerator
|
||||
/**
|
||||
* Get defined properties for the given class or object Reflector.
|
||||
*
|
||||
* @param bool $showAll Include private and protected properties
|
||||
* @param \Reflector $reflector
|
||||
* @param bool $noInherit Exclude inherited properties
|
||||
* @param bool $showAll Include private and protected properties
|
||||
* @param \ReflectionClass $reflector
|
||||
* @param bool $noInherit Exclude inherited properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getProperties(bool $showAll, \Reflector $reflector, bool $noInherit = false): array
|
||||
protected function getProperties(bool $showAll, \ReflectionClass $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
@@ -112,8 +112,6 @@ class PropertyEnumerator extends Enumerator
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
@@ -128,8 +126,6 @@ class PropertyEnumerator extends Enumerator
|
||||
* Get output style for the given property's visibility.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getVisibilityStyle(\ReflectionProperty $property): string
|
||||
{
|
||||
@@ -147,8 +143,6 @@ class PropertyEnumerator extends Enumerator
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
* @param mixed $target
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function presentValue(\ReflectionProperty $property, $target): string
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -45,7 +45,7 @@ class VariableEnumerator extends Enumerator
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list variables when no Reflector is present.
|
||||
if ($reflector !== null || $target !== null) {
|
||||
|
||||
61
vendor/psy/psysh/src/Command/ParseCommand.php
vendored
61
vendor/psy/psysh/src/Command/ParseCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace Psy\Command;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Parser;
|
||||
use Psy\Context;
|
||||
use Psy\ContextAware;
|
||||
use Psy\Input\CodeArgument;
|
||||
@@ -37,16 +36,14 @@ class ParseCommand extends Command implements ContextAware, PresenterAware
|
||||
protected $context;
|
||||
|
||||
private $presenter;
|
||||
private $parserFactory;
|
||||
private $parsers;
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->parserFactory = new ParserFactory();
|
||||
$this->parsers = [];
|
||||
$this->parser = (new ParserFactory())->createParser();
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@@ -90,16 +87,11 @@ class ParseCommand extends Command implements ContextAware, PresenterAware
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$kindMsg = 'One of PhpParser\\ParserFactory constants: '
|
||||
.\implode(', ', ParserFactory::getPossibleKinds())
|
||||
." (default is based on current interpreter's version).";
|
||||
|
||||
$this
|
||||
->setName('parse')
|
||||
->setDefinition([
|
||||
new CodeArgument('code', CodeArgument::REQUIRED, 'PHP code to parse.'),
|
||||
new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse.', 10),
|
||||
new InputOption('kind', '', InputOption::VALUE_REQUIRED, $kindMsg, $this->parserFactory->getDefaultKind()),
|
||||
])
|
||||
->setDescription('Parse PHP code and show the abstract syntax tree.')
|
||||
->setHelp(
|
||||
@@ -119,58 +111,17 @@ HELP
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$code = $input->getArgument('code');
|
||||
if (\strpos($code, '<?') === false) {
|
||||
$code = '<?php '.$code;
|
||||
}
|
||||
|
||||
$parserKind = $input->getOption('kind');
|
||||
$depth = $input->getOption('depth');
|
||||
$nodes = $this->parse($this->getParser($parserKind), $code);
|
||||
|
||||
$nodes = $this->parser->parse($code);
|
||||
$output->page($this->presenter->present($nodes, $depth));
|
||||
|
||||
$this->context->setReturnValue($nodes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lex and parse a string of code into statements.
|
||||
*
|
||||
* @param Parser $parser
|
||||
* @param string $code
|
||||
*
|
||||
* @return array Statements
|
||||
*/
|
||||
private function parse(Parser $parser, string $code): array
|
||||
{
|
||||
try {
|
||||
return $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 $parser->parse($code.';');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (or create) the Parser instance.
|
||||
*
|
||||
* @param string|null $kind One of Psy\ParserFactory constants (only for PHP parser 2.0 and above)
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
private function getParser(string $kind = null): Parser
|
||||
{
|
||||
if (!\array_key_exists($kind, $this->parsers)) {
|
||||
$this->parsers[$kind] = $this->parserFactory->createParser($kind);
|
||||
}
|
||||
|
||||
return $this->parsers[$kind];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -34,7 +34,7 @@ class PsyVersionCommand extends Command
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$output->writeln($this->getApplication()->getVersion());
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -11,14 +11,16 @@
|
||||
|
||||
namespace Psy\Command;
|
||||
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\PrettyPrinter\Standard as Printer;
|
||||
use Psy\CodeCleaner\NoReturnValue;
|
||||
use Psy\Context;
|
||||
use Psy\ContextAware;
|
||||
use Psy\Exception\ErrorException;
|
||||
use Psy\Exception\RuntimeException;
|
||||
use Psy\Exception\UnexpectedTargetException;
|
||||
use Psy\Reflection\ReflectionClassConstant;
|
||||
use Psy\Reflection\ReflectionConstant_;
|
||||
use Psy\Reflection\ReflectionConstant;
|
||||
use Psy\Sudo\SudoVisitor;
|
||||
use Psy\Util\Mirror;
|
||||
|
||||
/**
|
||||
@@ -38,6 +40,26 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
private $parser;
|
||||
private $traverser;
|
||||
private $printer;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->parser = new CodeArgumentParser();
|
||||
|
||||
// @todo Pass visitor directly to once we drop support for PHP-Parser 4.x
|
||||
$this->traverser = new NodeTraverser();
|
||||
$this->traverser->addVisitor(new SudoVisitor());
|
||||
|
||||
$this->printer = new Printer();
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* ContextAware interface.
|
||||
*
|
||||
@@ -92,8 +114,6 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
*
|
||||
* @param string $name
|
||||
* @param bool $includeFunctions (default: false)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveName(string $name, bool $includeFunctions = false): string
|
||||
{
|
||||
@@ -172,7 +192,10 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
protected function resolveCode(string $code)
|
||||
{
|
||||
try {
|
||||
$value = $this->getApplication()->execute($code, true);
|
||||
// Add an implicit `sudo` to target resolution.
|
||||
$nodes = $this->traverser->traverse($this->parser->parse($code));
|
||||
$sudoCode = $this->printer->prettyPrint($nodes);
|
||||
$value = $this->getApplication()->execute($sudoCode, true);
|
||||
} catch (\Throwable $e) {
|
||||
// Swallow all exceptions?
|
||||
}
|
||||
@@ -204,20 +227,6 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `resolveCode` instead
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed Variable instance
|
||||
*/
|
||||
protected function resolveInstance(string $name)
|
||||
{
|
||||
@\trigger_error('`resolveInstance` is deprecated; use `resolveCode` instead.', \E_USER_DEPRECATED);
|
||||
|
||||
return $this->resolveCode($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a variable from the current shell scope.
|
||||
*
|
||||
@@ -291,7 +300,6 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
|
||||
case \ReflectionProperty::class:
|
||||
case \ReflectionClassConstant::class:
|
||||
case ReflectionClassConstant::class:
|
||||
$classReflector = $reflector->getDeclaringClass();
|
||||
$vars['__class'] = $classReflector->name;
|
||||
if ($classReflector->inNamespace()) {
|
||||
@@ -304,7 +312,7 @@ abstract class ReflectingCommand extends Command implements ContextAware
|
||||
}
|
||||
break;
|
||||
|
||||
case ReflectionConstant_::class:
|
||||
case ReflectionConstant::class:
|
||||
if ($reflector->inNamespace()) {
|
||||
$vars['__namespace'] = $reflector->getNamespaceName();
|
||||
}
|
||||
|
||||
14
vendor/psy/psysh/src/Command/ShowCommand.php
vendored
14
vendor/psy/psysh/src/Command/ShowCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -29,14 +29,6 @@ class ShowCommand extends ReflectingCommand
|
||||
private $lastException;
|
||||
private $lastExceptionIndex;
|
||||
|
||||
/**
|
||||
* @param string|null $colorMode (deprecated and ignored)
|
||||
*/
|
||||
public function __construct($colorMode = null)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -69,8 +61,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// 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
|
||||
|
||||
38
vendor/psy/psysh/src/Command/SudoCommand.php
vendored
38
vendor/psy/psysh/src/Command/SudoCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -14,7 +14,6 @@ namespace Psy\Command;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\PrettyPrinter\Standard as Printer;
|
||||
use Psy\Input\CodeArgument;
|
||||
use Psy\ParserFactory;
|
||||
use Psy\Readline\Readline;
|
||||
use Psy\Sudo\SudoVisitor;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -35,9 +34,9 @@ class SudoCommand extends Command
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$parserFactory = new ParserFactory();
|
||||
$this->parser = $parserFactory->createParser();
|
||||
$this->parser = new CodeArgumentParser();
|
||||
|
||||
// @todo Pass visitor directly to once we drop support for PHP-Parser 4.x
|
||||
$this->traverser = new NodeTraverser();
|
||||
$this->traverser->addVisitor(new SudoVisitor());
|
||||
|
||||
@@ -95,8 +94,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$code = $input->getArgument('code');
|
||||
|
||||
@@ -109,11 +110,7 @@ HELP
|
||||
$code = $history[\count($history) - 2];
|
||||
}
|
||||
|
||||
if (\strpos($code, '<?') === false) {
|
||||
$code = '<?php '.$code;
|
||||
}
|
||||
|
||||
$nodes = $this->traverser->traverse($this->parse($code));
|
||||
$nodes = $this->traverser->traverse($this->parser->parse($code));
|
||||
|
||||
$sudoCode = $this->printer->prettyPrint($nodes);
|
||||
$shell = $this->getApplication();
|
||||
@@ -121,25 +118,4 @@ HELP
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lex and parse a string of code into statements.
|
||||
*
|
||||
* @param string $code
|
||||
*
|
||||
* @return array Statements
|
||||
*/
|
||||
private function parse(string $code): array
|
||||
{
|
||||
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.';');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
64
vendor/psy/psysh/src/Command/ThrowUpCommand.php
vendored
64
vendor/psy/psysh/src/Command/ThrowUpCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -13,24 +13,21 @@ namespace Psy\Command;
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Throw_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified as FullyQualifiedName;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Throw_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\PrettyPrinter\Standard as Printer;
|
||||
use Psy\Context;
|
||||
use Psy\ContextAware;
|
||||
use Psy\Exception\ThrowUpException;
|
||||
use Psy\Input\CodeArgument;
|
||||
use Psy\ParserFactory;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Throw an exception or error out of the Psy Shell.
|
||||
*/
|
||||
class ThrowUpCommand extends Command implements ContextAware
|
||||
class ThrowUpCommand extends Command
|
||||
{
|
||||
private $parser;
|
||||
private $printer;
|
||||
@@ -40,24 +37,12 @@ class ThrowUpCommand extends Command implements ContextAware
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$parserFactory = new ParserFactory();
|
||||
|
||||
$this->parser = $parserFactory->createParser();
|
||||
$this->parser = new CodeArgumentParser();
|
||||
$this->printer = new Printer();
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated throwUp no longer needs to be ContextAware
|
||||
*
|
||||
* @param Context $context
|
||||
*/
|
||||
public function setContext(Context $context)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -87,12 +72,14 @@ HELP
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*
|
||||
* @throws \InvalidArgumentException if there is no exception to throw
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$args = $this->prepareArgs($input->getArgument('exception'));
|
||||
$throwStmt = new Throw_(new StaticCall(new FullyQualifiedName(ThrowUpException::class), 'fromThrowable', $args));
|
||||
$throwStmt = new Expression(new Throw_(new New_(new FullyQualifiedName(ThrowUpException::class), $args)));
|
||||
$throwCode = $this->printer->prettyPrint([$throwStmt]);
|
||||
|
||||
$shell = $this->getApplication();
|
||||
@@ -112,26 +99,20 @@ HELP
|
||||
*
|
||||
* @return Arg[]
|
||||
*/
|
||||
private function prepareArgs(string $code = null): array
|
||||
private function prepareArgs(?string $code = null): array
|
||||
{
|
||||
if (!$code) {
|
||||
// Default to last exception if nothing else was supplied
|
||||
return [new Arg(new Variable('_e'))];
|
||||
}
|
||||
|
||||
if (\strpos($code, '<?') === false) {
|
||||
$code = '<?php '.$code;
|
||||
}
|
||||
|
||||
$nodes = $this->parse($code);
|
||||
$nodes = $this->parser->parse($code);
|
||||
if (\count($nodes) !== 1) {
|
||||
throw new \InvalidArgumentException('No idea how to throw this');
|
||||
}
|
||||
|
||||
$node = $nodes[0];
|
||||
|
||||
// Make this work for PHP Parser v3.x
|
||||
$expr = isset($node->expr) ? $node->expr : $node;
|
||||
$expr = $node->expr;
|
||||
|
||||
$args = [new Arg($expr, false, false, $node->getAttributes())];
|
||||
|
||||
@@ -142,25 +123,4 @@ HELP
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lex and parse a string of code into statements.
|
||||
*
|
||||
* @param string $code
|
||||
*
|
||||
* @return array Statements
|
||||
*/
|
||||
private function parse(string $code): array
|
||||
{
|
||||
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.';');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
vendor/psy/psysh/src/Command/TimeitCommand.php
vendored
55
vendor/psy/psysh/src/Command/TimeitCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -15,7 +15,6 @@ use PhpParser\NodeTraverser;
|
||||
use PhpParser\PrettyPrinter\Standard as Printer;
|
||||
use Psy\Command\TimeitCommand\TimeitVisitor;
|
||||
use Psy\Input\CodeArgument;
|
||||
use Psy\ParserFactory;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -28,6 +27,7 @@ class TimeitCommand extends Command
|
||||
const RESULT_MSG = '<info>Command took %.6f seconds to complete.</info>';
|
||||
const AVG_RESULT_MSG = '<info>Command took %.6f seconds on average (%.6f median; %.6f total) to complete.</info>';
|
||||
|
||||
// All times stored as nanoseconds!
|
||||
private static $start = null;
|
||||
private static $times = [];
|
||||
|
||||
@@ -40,9 +40,9 @@ class TimeitCommand extends Command
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$parserFactory = new ParserFactory();
|
||||
$this->parser = $parserFactory->createParser();
|
||||
$this->parser = new CodeArgumentParser();
|
||||
|
||||
// @todo Pass visitor directly to once we drop support for PHP-Parser 4.x
|
||||
$this->traverser = new NodeTraverser();
|
||||
$this->traverser->addVisitor(new TimeitVisitor());
|
||||
|
||||
@@ -76,21 +76,23 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$code = $input->getArgument('code');
|
||||
$num = $input->getOption('num') ?: 1;
|
||||
$num = (int) ($input->getOption('num') ?: 1);
|
||||
$shell = $this->getApplication();
|
||||
|
||||
$instrumentedCode = $this->instrumentCode($code);
|
||||
|
||||
self::$times = [];
|
||||
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
do {
|
||||
$_ = $shell->execute($instrumentedCode);
|
||||
$this->ensureEndMarked();
|
||||
}
|
||||
} while (\count(self::$times) < $num);
|
||||
|
||||
$shell->writeReturnValue($_);
|
||||
|
||||
@@ -98,13 +100,13 @@ HELP
|
||||
self::$times = [];
|
||||
|
||||
if ($num === 1) {
|
||||
$output->writeln(\sprintf(self::RESULT_MSG, $times[0]));
|
||||
$output->writeln(\sprintf(self::RESULT_MSG, $times[0] / 1e+9));
|
||||
} else {
|
||||
$total = \array_sum($times);
|
||||
\rsort($times);
|
||||
$median = $times[\round($num / 2)];
|
||||
|
||||
$output->writeln(\sprintf(self::AVG_RESULT_MSG, $total / $num, $median, $total));
|
||||
$output->writeln(\sprintf(self::AVG_RESULT_MSG, ($total / $num) / 1e+9, $median / 1e+9, $total / 1e+9));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -119,7 +121,7 @@ HELP
|
||||
*/
|
||||
public static function markStart()
|
||||
{
|
||||
self::$start = \microtime(true);
|
||||
self::$start = \hrtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +140,7 @@ HELP
|
||||
*/
|
||||
public static function markEnd($ret = null)
|
||||
{
|
||||
self::$times[] = \microtime(true) - self::$start;
|
||||
self::$times[] = \hrtime(true) - self::$start;
|
||||
self::$start = null;
|
||||
|
||||
return $ret;
|
||||
@@ -162,36 +164,9 @@ HELP
|
||||
*
|
||||
* This inserts `markStart` and `markEnd` calls to ensure that (reasonably)
|
||||
* accurate times are recorded for just the code being executed.
|
||||
*
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function instrumentCode(string $code): string
|
||||
{
|
||||
return $this->printer->prettyPrint($this->traverser->traverse($this->parse($code)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lex and parse a string of code into statements.
|
||||
*
|
||||
* @param string $code
|
||||
*
|
||||
* @return array Statements
|
||||
*/
|
||||
private function parse(string $code): array
|
||||
{
|
||||
$code = '<?php '.$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.';');
|
||||
}
|
||||
return $this->printer->prettyPrint($this->traverser->traverse($this->parser->parse($code)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -35,6 +35,8 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return Node[]|null Array of nodes
|
||||
*/
|
||||
public function beforeTraverse(array $nodes)
|
||||
{
|
||||
@@ -43,6 +45,8 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int|Node|null Replacement node (or special return value)
|
||||
*/
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
@@ -62,6 +66,8 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int|Node|Node[]|null Replacement node (or special return value)
|
||||
*/
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
@@ -72,11 +78,13 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return Node[]|null Array of nodes
|
||||
*/
|
||||
public function afterTraverse(array $nodes)
|
||||
{
|
||||
// prepend a `markStart` call
|
||||
\array_unshift($nodes, $this->maybeExpression($this->getStartCall()));
|
||||
\array_unshift($nodes, new Expression($this->getStartCall(), []));
|
||||
|
||||
// append a `markEnd` call (wrapping the final node, if it's an expression)
|
||||
$last = $nodes[\count($nodes) - 1];
|
||||
@@ -89,7 +97,7 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
} elseif ($last instanceof Return_) {
|
||||
// nothing to do here, we're already ending with a return call
|
||||
} else {
|
||||
$nodes[] = $this->maybeExpression($this->getEndCall());
|
||||
$nodes[] = new Expression($this->getEndCall(), []);
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
@@ -111,10 +119,8 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
* Optionally pass in a return value.
|
||||
*
|
||||
* @param Expr|null $arg
|
||||
*
|
||||
* @return \PhpParser\Node\Expr\StaticCall
|
||||
*/
|
||||
private function getEndCall(Expr $arg = null): StaticCall
|
||||
private function getEndCall(?Expr $arg = null): StaticCall
|
||||
{
|
||||
if ($arg === null) {
|
||||
$arg = NoReturnValue::create();
|
||||
@@ -122,19 +128,4 @@ class TimeitVisitor extends NodeVisitorAbstract
|
||||
|
||||
return new StaticCall(new FullyQualifiedName(TimeitCommand::class), 'markEnd', [new Arg($arg)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compatibility shim for PHP Parser 3.x.
|
||||
*
|
||||
* Wrap $expr in a PhpParser\Node\Stmt\Expression if the class exists.
|
||||
*
|
||||
* @param \PhpParser\Node $expr
|
||||
* @param array $attrs
|
||||
*
|
||||
* @return \PhpParser\Node\Expr|\PhpParser\Node\Stmt\Expression
|
||||
*/
|
||||
private function maybeExpression(Node $expr, array $attrs = [])
|
||||
{
|
||||
return \class_exists(Expression::class) ? new Expression($expr, $attrs) : $expr;
|
||||
}
|
||||
}
|
||||
|
||||
12
vendor/psy/psysh/src/Command/TraceCommand.php
vendored
12
vendor/psy/psysh/src/Command/TraceCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -68,8 +68,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->filter->bind($input);
|
||||
$trace = $this->getBacktrace(new \Exception(), $input->getOption('num'), $input->getOption('include-psy'));
|
||||
@@ -79,18 +81,18 @@ HELP
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a backtrace for an exception.
|
||||
* Get a backtrace for an exception or error.
|
||||
*
|
||||
* Optionally limit the number of rows to include with $count, and exclude
|
||||
* Psy from the trace.
|
||||
*
|
||||
* @param \Exception $e The exception with a backtrace
|
||||
* @param \Throwable $e The exception or error with a backtrace
|
||||
* @param int $count (default: PHP_INT_MAX)
|
||||
* @param bool $includePsy (default: true)
|
||||
*
|
||||
* @return array Formatted stacktrace lines
|
||||
*/
|
||||
protected function getBacktrace(\Exception $e, int $count = null, bool $includePsy = true): array
|
||||
protected function getBacktrace(\Throwable $e, ?int $count = null, bool $includePsy = true): array
|
||||
{
|
||||
return TraceFormatter::formatTrace($e, $this->filter, $count, $includePsy);
|
||||
}
|
||||
|
||||
13
vendor/psy/psysh/src/Command/WhereamiCommand.php
vendored
13
vendor/psy/psysh/src/Command/WhereamiCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -25,10 +25,7 @@ class WhereamiCommand extends Command
|
||||
{
|
||||
private $backtrace;
|
||||
|
||||
/**
|
||||
* @param string|null $colorMode (deprecated and ignored)
|
||||
*/
|
||||
public function __construct($colorMode = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
|
||||
@@ -109,8 +106,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$info = $this->fileInfo();
|
||||
$num = $input->getOption('num');
|
||||
@@ -142,8 +141,6 @@ HELP
|
||||
* Replace the given directory from the start of a filepath.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function replaceCwd(string $file): string
|
||||
{
|
||||
|
||||
6
vendor/psy/psysh/src/Command/WtfCommand.php
vendored
6
vendor/psy/psysh/src/Command/WtfCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
* (c) 2012-2023 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -81,8 +81,10 @@ HELP
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int 0 if everything went fine, or an exit code
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->filter->bind($input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user