Primo Committ
This commit is contained in:
124
vendor/psy/psysh/src/Command/ListCommand/ClassConstantEnumerator.php
vendored
Normal file
124
vendor/psy/psysh/src/Command/ListCommand/ClassConstantEnumerator.php
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Reflection\ReflectionClassConstant;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Class Constant Enumerator class.
|
||||
*/
|
||||
class ClassConstantEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list constants when a Reflector is present.
|
||||
if ($reflector === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We can only list constants on actual class (or object) reflectors.
|
||||
if (!$reflector instanceof \ReflectionClass) {
|
||||
// @todo handle ReflectionExtension as well
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list constants if we are specifically asked
|
||||
if (!$input->getOption('constants')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$noInherit = $input->getOption('no-inherit');
|
||||
$constants = $this->prepareConstants($this->getConstants($reflector, $noInherit));
|
||||
|
||||
if (empty($constants)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$ret[$this->getKindLabel($reflector)] = $constants;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined constants for the given class or object Reflector.
|
||||
*
|
||||
* @param \Reflector $reflector
|
||||
* @param bool $noInherit Exclude inherited constants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConstants(\Reflector $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
$constants = [];
|
||||
foreach ($reflector->getConstants() as $name => $constant) {
|
||||
$constReflector = ReflectionClassConstant::create($reflector->name, $name);
|
||||
|
||||
if ($noInherit && $constReflector->getDeclaringClass()->getName() !== $className) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$constants[$name] = $constReflector;
|
||||
}
|
||||
|
||||
\ksort($constants, \SORT_NATURAL | \SORT_FLAG_CASE);
|
||||
|
||||
return $constants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted constant array.
|
||||
*
|
||||
* @param array $constants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareConstants(array $constants): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($constants as $name => $constant) {
|
||||
if ($this->showItem($name)) {
|
||||
$ret[$name] = [
|
||||
'name' => $name,
|
||||
'style' => self::IS_CONSTANT,
|
||||
'value' => $this->presentRef($constant->getValue()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
if ($reflector->isInterface()) {
|
||||
return 'Interface Constants';
|
||||
} else {
|
||||
return 'Class Constants';
|
||||
}
|
||||
}
|
||||
}
|
||||
132
vendor/psy/psysh/src/Command/ListCommand/ClassEnumerator.php
vendored
Normal file
132
vendor/psy/psysh/src/Command/ListCommand/ClassEnumerator.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Reflection\ReflectionNamespace;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Class Enumerator class.
|
||||
*/
|
||||
class ClassEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$internal = $input->getOption('internal');
|
||||
$user = $input->getOption('user');
|
||||
$prefix = $reflector === null ? null : \strtolower($reflector->getName()).'\\';
|
||||
|
||||
$ret = [];
|
||||
|
||||
// only list classes, interfaces and traits if we are specifically asked
|
||||
|
||||
if ($input->getOption('classes')) {
|
||||
$ret = \array_merge($ret, $this->filterClasses('Classes', \get_declared_classes(), $internal, $user, $prefix));
|
||||
}
|
||||
|
||||
if ($input->getOption('interfaces')) {
|
||||
$ret = \array_merge($ret, $this->filterClasses('Interfaces', \get_declared_interfaces(), $internal, $user, $prefix));
|
||||
}
|
||||
|
||||
if ($input->getOption('traits')) {
|
||||
$ret = \array_merge($ret, $this->filterClasses('Traits', \get_declared_traits(), $internal, $user, $prefix));
|
||||
}
|
||||
|
||||
return \array_map([$this, 'prepareClasses'], \array_filter($ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of classes, interfaces or traits.
|
||||
*
|
||||
* If $internal or $user is defined, results will be limited to internal or
|
||||
* user-defined classes as appropriate.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $classes
|
||||
* @param bool $internal
|
||||
* @param bool $user
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function filterClasses(string $key, array $classes, bool $internal, bool $user, string $prefix = null): array
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
if ($internal) {
|
||||
$ret['Internal '.$key] = \array_filter($classes, function ($class) use ($prefix) {
|
||||
if ($prefix !== null && \strpos(\strtolower($class), $prefix) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$refl = new \ReflectionClass($class);
|
||||
|
||||
return $refl->isInternal();
|
||||
});
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$ret['User '.$key] = \array_filter($classes, function ($class) use ($prefix) {
|
||||
if ($prefix !== null && \strpos(\strtolower($class), $prefix) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$refl = new \ReflectionClass($class);
|
||||
|
||||
return !$refl->isInternal();
|
||||
});
|
||||
}
|
||||
|
||||
if (!$user && !$internal) {
|
||||
$ret[$key] = \array_filter($classes, function ($class) use ($prefix) {
|
||||
return $prefix === null || \strpos(\strtolower($class), $prefix) === 0;
|
||||
});
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted class array.
|
||||
*
|
||||
* @param array $classes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareClasses(array $classes): array
|
||||
{
|
||||
\natcasesort($classes);
|
||||
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($classes as $name) {
|
||||
if ($this->showItem($name)) {
|
||||
$ret[$name] = [
|
||||
'name' => $name,
|
||||
'style' => self::IS_CLASS,
|
||||
'value' => $this->presentSignature($name),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
175
vendor/psy/psysh/src/Command/ListCommand/ConstantEnumerator.php
vendored
Normal file
175
vendor/psy/psysh/src/Command/ListCommand/ConstantEnumerator.php
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Reflection\ReflectionNamespace;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Constant Enumerator class.
|
||||
*/
|
||||
class ConstantEnumerator extends Enumerator
|
||||
{
|
||||
// Because `Json` is ugly.
|
||||
private static $categoryLabels = [
|
||||
'libxml' => 'libxml',
|
||||
'openssl' => 'OpenSSL',
|
||||
'pcre' => 'PCRE',
|
||||
'sqlite3' => 'SQLite3',
|
||||
'curl' => 'cURL',
|
||||
'dom' => 'DOM',
|
||||
'ftp' => 'FTP',
|
||||
'gd' => 'GD',
|
||||
'gmp' => 'GMP',
|
||||
'iconv' => 'iconv',
|
||||
'json' => 'JSON',
|
||||
'ldap' => 'LDAP',
|
||||
'mbstring' => 'mbstring',
|
||||
'odbc' => 'ODBC',
|
||||
'pcntl' => 'PCNTL',
|
||||
'pgsql' => 'pgsql',
|
||||
'posix' => 'POSIX',
|
||||
'mysqli' => 'mysqli',
|
||||
'soap' => 'SOAP',
|
||||
'exif' => 'EXIF',
|
||||
'sysvmsg' => 'sysvmsg',
|
||||
'xml' => 'XML',
|
||||
'xsl' => 'XSL',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list constants if we are specifically asked
|
||||
if (!$input->getOption('constants')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$user = $input->getOption('user');
|
||||
$internal = $input->getOption('internal');
|
||||
$category = $input->getOption('category');
|
||||
|
||||
if ($category) {
|
||||
$category = \strtolower($category);
|
||||
|
||||
if ($category === 'internal') {
|
||||
$internal = true;
|
||||
$category = null;
|
||||
} elseif ($category === 'user') {
|
||||
$user = true;
|
||||
$category = null;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
|
||||
if ($user) {
|
||||
$ret['User Constants'] = $this->getConstants('user');
|
||||
}
|
||||
|
||||
if ($internal) {
|
||||
$ret['Internal Constants'] = $this->getConstants('internal');
|
||||
}
|
||||
|
||||
if ($category) {
|
||||
$caseCategory = \array_key_exists($category, self::$categoryLabels) ? self::$categoryLabels[$category] : \ucfirst($category);
|
||||
$label = $caseCategory.' Constants';
|
||||
$ret[$label] = $this->getConstants($category);
|
||||
}
|
||||
|
||||
if (!$user && !$internal && !$category) {
|
||||
$ret['Constants'] = $this->getConstants();
|
||||
}
|
||||
|
||||
if ($reflector !== null) {
|
||||
$prefix = \strtolower($reflector->getName()).'\\';
|
||||
|
||||
foreach ($ret as $key => $names) {
|
||||
foreach (\array_keys($names) as $name) {
|
||||
if (\strpos(\strtolower($name), $prefix) !== 0) {
|
||||
unset($ret[$key][$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return \array_map([$this, 'prepareConstants'], \array_filter($ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined constants.
|
||||
*
|
||||
* Optionally restrict constants to a given category, e.g. "date". If the
|
||||
* category is "internal", include all non-user-defined constants.
|
||||
*
|
||||
* @param string $category
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConstants(string $category = null): array
|
||||
{
|
||||
if (!$category) {
|
||||
return \get_defined_constants();
|
||||
}
|
||||
|
||||
$consts = \get_defined_constants(true);
|
||||
|
||||
if ($category === 'internal') {
|
||||
unset($consts['user']);
|
||||
|
||||
return \call_user_func_array('array_merge', \array_values($consts));
|
||||
}
|
||||
|
||||
foreach ($consts as $key => $value) {
|
||||
if (\strtolower($key) === $category) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted constant array.
|
||||
*
|
||||
* @param array $constants
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareConstants(array $constants): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
$names = \array_keys($constants);
|
||||
\natcasesort($names);
|
||||
|
||||
foreach ($names as $name) {
|
||||
if ($this->showItem($name)) {
|
||||
$ret[$name] = [
|
||||
'name' => $name,
|
||||
'style' => self::IS_CONSTANT,
|
||||
'value' => $this->presentRef($constants[$name]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
106
vendor/psy/psysh/src/Command/ListCommand/Enumerator.php
vendored
Normal file
106
vendor/psy/psysh/src/Command/ListCommand/Enumerator.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Formatter\SignatureFormatter;
|
||||
use Psy\Input\FilterOptions;
|
||||
use Psy\Util\Mirror;
|
||||
use Psy\VarDumper\Presenter;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Abstract Enumerator class.
|
||||
*/
|
||||
abstract class Enumerator
|
||||
{
|
||||
// Output styles
|
||||
const IS_PUBLIC = 'public';
|
||||
const IS_PROTECTED = 'protected';
|
||||
const IS_PRIVATE = 'private';
|
||||
const IS_GLOBAL = 'global';
|
||||
const IS_CONSTANT = 'const';
|
||||
const IS_CLASS = 'class';
|
||||
const IS_FUNCTION = 'function';
|
||||
|
||||
private $filter;
|
||||
private $presenter;
|
||||
|
||||
/**
|
||||
* Enumerator constructor.
|
||||
*
|
||||
* @param Presenter $presenter
|
||||
*/
|
||||
public function __construct(Presenter $presenter)
|
||||
{
|
||||
$this->filter = new FilterOptions();
|
||||
$this->presenter = $presenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of categorized things with the given input options and target.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param \Reflector|null $reflector
|
||||
* @param mixed $target
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
$this->filter->bind($input);
|
||||
|
||||
return $this->listItems($input, $reflector, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerate specific items with the given input options and target.
|
||||
*
|
||||
* Implementing classes should return an array of arrays:
|
||||
*
|
||||
* [
|
||||
* 'Constants' => [
|
||||
* 'FOO' => [
|
||||
* 'name' => 'FOO',
|
||||
* 'style' => 'public',
|
||||
* 'value' => '123',
|
||||
* ],
|
||||
* ],
|
||||
* ]
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param \Reflector|null $reflector
|
||||
* @param mixed $target
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array;
|
||||
|
||||
protected function showItem($name)
|
||||
{
|
||||
return $this->filter->match($name);
|
||||
}
|
||||
|
||||
protected function presentRef($value)
|
||||
{
|
||||
return $this->presenter->presentRef($value);
|
||||
}
|
||||
|
||||
protected function presentSignature($target)
|
||||
{
|
||||
// This might get weird if the signature is actually for a reflector. Hrm.
|
||||
if (!$target instanceof \Reflector) {
|
||||
$target = Mirror::get($target);
|
||||
}
|
||||
|
||||
return SignatureFormatter::format($target);
|
||||
}
|
||||
}
|
||||
116
vendor/psy/psysh/src/Command/ListCommand/FunctionEnumerator.php
vendored
Normal file
116
vendor/psy/psysh/src/Command/ListCommand/FunctionEnumerator.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Reflection\ReflectionNamespace;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Function Enumerator class.
|
||||
*/
|
||||
class FunctionEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list functions if we are specifically asked
|
||||
if (!$input->getOption('functions')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($input->getOption('user')) {
|
||||
$label = 'User Functions';
|
||||
$functions = $this->getFunctions('user');
|
||||
} elseif ($input->getOption('internal')) {
|
||||
$label = 'Internal Functions';
|
||||
$functions = $this->getFunctions('internal');
|
||||
} else {
|
||||
$label = 'Functions';
|
||||
$functions = $this->getFunctions();
|
||||
}
|
||||
|
||||
$prefix = $reflector === null ? null : \strtolower($reflector->getName()).'\\';
|
||||
$functions = $this->prepareFunctions($functions, $prefix);
|
||||
|
||||
if (empty($functions)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$ret[$label] = $functions;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined functions.
|
||||
*
|
||||
* Optionally limit functions to "user" or "internal" functions.
|
||||
*
|
||||
* @param string|null $type "user" or "internal" (default: both)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFunctions(string $type = null): array
|
||||
{
|
||||
$funcs = \get_defined_functions();
|
||||
|
||||
if ($type) {
|
||||
return $funcs[$type];
|
||||
} else {
|
||||
return \array_merge($funcs['internal'], $funcs['user']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted function array.
|
||||
*
|
||||
* @param array $functions
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareFunctions(array $functions, string $prefix = null): array
|
||||
{
|
||||
\natcasesort($functions);
|
||||
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($functions as $name) {
|
||||
if ($prefix !== null && \strpos(\strtolower($name), $prefix) !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->showItem($name)) {
|
||||
try {
|
||||
$ret[$name] = [
|
||||
'name' => $name,
|
||||
'style' => self::IS_FUNCTION,
|
||||
'value' => $this->presentSignature($name),
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
// Ignore failures.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
92
vendor/psy/psysh/src/Command/ListCommand/GlobalVariableEnumerator.php
vendored
Normal file
92
vendor/psy/psysh/src/Command/ListCommand/GlobalVariableEnumerator.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Global Variable Enumerator class.
|
||||
*/
|
||||
class GlobalVariableEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list globals when no Reflector is present.
|
||||
if ($reflector !== null || $target !== null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list globals if we are specifically asked
|
||||
if (!$input->getOption('globals')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$globals = $this->prepareGlobals($this->getGlobals());
|
||||
|
||||
if (empty($globals)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'Global Variables' => $globals,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined global variables.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGlobals(): array
|
||||
{
|
||||
global $GLOBALS;
|
||||
|
||||
$names = \array_keys($GLOBALS);
|
||||
\natcasesort($names);
|
||||
|
||||
$ret = [];
|
||||
foreach ($names as $name) {
|
||||
$ret[$name] = $GLOBALS[$name];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted global variable array.
|
||||
*
|
||||
* @param array $globals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareGlobals(array $globals): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($globals as $name => $value) {
|
||||
if ($this->showItem($name)) {
|
||||
$fname = '$'.$name;
|
||||
$ret[$fname] = [
|
||||
'name' => $fname,
|
||||
'style' => self::IS_GLOBAL,
|
||||
'value' => $this->presentRef($value),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
146
vendor/psy/psysh/src/Command/ListCommand/MethodEnumerator.php
vendored
Normal file
146
vendor/psy/psysh/src/Command/ListCommand/MethodEnumerator.php
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Method Enumerator class.
|
||||
*/
|
||||
class MethodEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list methods when a Reflector is present.
|
||||
if ($reflector === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We can only list methods on actual class (or object) reflectors.
|
||||
if (!$reflector instanceof \ReflectionClass) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list methods if we are specifically asked
|
||||
if (!$input->getOption('methods')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$showAll = $input->getOption('all');
|
||||
$noInherit = $input->getOption('no-inherit');
|
||||
$methods = $this->prepareMethods($this->getMethods($showAll, $reflector, $noInherit));
|
||||
|
||||
if (empty($methods)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$ret[$this->getKindLabel($reflector)] = $methods;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getMethods(bool $showAll, \Reflector $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
$methods = [];
|
||||
foreach ($reflector->getMethods() as $name => $method) {
|
||||
// For some reason PHP reflection shows private methods from the parent class, even
|
||||
// though they're effectively worthless. Let's suppress them here, like --no-inherit
|
||||
if (($noInherit || $method->isPrivate()) && $method->getDeclaringClass()->getName() !== $className) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($showAll || $method->isPublic()) {
|
||||
$methods[$method->getName()] = $method;
|
||||
}
|
||||
}
|
||||
|
||||
\ksort($methods, \SORT_NATURAL | \SORT_FLAG_CASE);
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted method array.
|
||||
*
|
||||
* @param array $methods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareMethods(array $methods): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($methods as $name => $method) {
|
||||
if ($this->showItem($name)) {
|
||||
$ret[$name] = [
|
||||
'name' => $name,
|
||||
'style' => $this->getVisibilityStyle($method),
|
||||
'value' => $this->presentSignature($method),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
if ($reflector->isInterface()) {
|
||||
return 'Interface Methods';
|
||||
} elseif (\method_exists($reflector, 'isTrait') && $reflector->isTrait()) {
|
||||
return 'Trait Methods';
|
||||
} else {
|
||||
return 'Class Methods';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output style for the given method's visibility.
|
||||
*
|
||||
* @param \ReflectionMethod $method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getVisibilityStyle(\ReflectionMethod $method): string
|
||||
{
|
||||
if ($method->isPublic()) {
|
||||
return self::IS_PUBLIC;
|
||||
} elseif ($method->isProtected()) {
|
||||
return self::IS_PROTECTED;
|
||||
} else {
|
||||
return self::IS_PRIVATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
182
vendor/psy/psysh/src/Command/ListCommand/PropertyEnumerator.php
vendored
Normal file
182
vendor/psy/psysh/src/Command/ListCommand/PropertyEnumerator.php
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Property Enumerator class.
|
||||
*/
|
||||
class PropertyEnumerator extends Enumerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list properties when a Reflector is present.
|
||||
|
||||
if ($reflector === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We can only list properties on actual class (or object) reflectors.
|
||||
if (!$reflector instanceof \ReflectionClass) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list properties if we are specifically asked
|
||||
if (!$input->getOption('properties')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$showAll = $input->getOption('all');
|
||||
$noInherit = $input->getOption('no-inherit');
|
||||
$properties = $this->prepareProperties($this->getProperties($showAll, $reflector, $noInherit), $target);
|
||||
|
||||
if (empty($properties)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
$ret[$this->getKindLabel($reflector)] = $properties;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getProperties(bool $showAll, \Reflector $reflector, bool $noInherit = false): array
|
||||
{
|
||||
$className = $reflector->getName();
|
||||
|
||||
$properties = [];
|
||||
foreach ($reflector->getProperties() as $property) {
|
||||
if ($noInherit && $property->getDeclaringClass()->getName() !== $className) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($showAll || $property->isPublic()) {
|
||||
$properties[$property->getName()] = $property;
|
||||
}
|
||||
}
|
||||
|
||||
\ksort($properties, \SORT_NATURAL | \SORT_FLAG_CASE);
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted property array.
|
||||
*
|
||||
* @param array $properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareProperties(array $properties, $target = null): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
|
||||
foreach ($properties as $name => $property) {
|
||||
if ($this->showItem($name)) {
|
||||
$fname = '$'.$name;
|
||||
$ret[$fname] = [
|
||||
'name' => $fname,
|
||||
'style' => $this->getVisibilityStyle($property),
|
||||
'value' => $this->presentValue($property, $target),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a label for the particular kind of "class" represented.
|
||||
*
|
||||
* @param \ReflectionClass $reflector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getKindLabel(\ReflectionClass $reflector): string
|
||||
{
|
||||
if (\method_exists($reflector, 'isTrait') && $reflector->isTrait()) {
|
||||
return 'Trait Properties';
|
||||
} else {
|
||||
return 'Class Properties';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output style for the given property's visibility.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getVisibilityStyle(\ReflectionProperty $property): string
|
||||
{
|
||||
if ($property->isPublic()) {
|
||||
return self::IS_PUBLIC;
|
||||
} elseif ($property->isProtected()) {
|
||||
return self::IS_PROTECTED;
|
||||
} else {
|
||||
return self::IS_PRIVATE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the $target's current value for a reflection property.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
* @param mixed $target
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function presentValue(\ReflectionProperty $property, $target): string
|
||||
{
|
||||
if (!$target) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// If $target is a class or trait (try to) get the default
|
||||
// value for the property.
|
||||
if (!\is_object($target)) {
|
||||
try {
|
||||
$refl = new \ReflectionClass($target);
|
||||
$props = $refl->getDefaultProperties();
|
||||
if (\array_key_exists($property->name, $props)) {
|
||||
$suffix = $property->isStatic() ? '' : ' <aside>(default)</aside>';
|
||||
|
||||
return $this->presentRef($props[$property->name]).$suffix;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Well, we gave it a shot.
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
$value = $property->getValue($target);
|
||||
|
||||
return $this->presentRef($value);
|
||||
}
|
||||
}
|
||||
137
vendor/psy/psysh/src/Command/ListCommand/VariableEnumerator.php
vendored
Normal file
137
vendor/psy/psysh/src/Command/ListCommand/VariableEnumerator.php
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Psy\Command\ListCommand;
|
||||
|
||||
use Psy\Context;
|
||||
use Psy\VarDumper\Presenter;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
||||
/**
|
||||
* Variable Enumerator class.
|
||||
*/
|
||||
class VariableEnumerator extends Enumerator
|
||||
{
|
||||
// n.b. this array is the order in which special variables will be listed
|
||||
private static $specialNames = [
|
||||
'_', '_e', '__out', '__function', '__method', '__class', '__namespace', '__file', '__line', '__dir',
|
||||
];
|
||||
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Variable Enumerator constructor.
|
||||
*
|
||||
* Unlike most other enumerators, the Variable Enumerator needs access to
|
||||
* the current scope variables, so we need to pass it a Context instance.
|
||||
*
|
||||
* @param Presenter $presenter
|
||||
* @param Context $context
|
||||
*/
|
||||
public function __construct(Presenter $presenter, Context $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
parent::__construct($presenter);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
|
||||
{
|
||||
// only list variables when no Reflector is present.
|
||||
if ($reflector !== null || $target !== null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// only list variables if we are specifically asked
|
||||
if (!$input->getOption('vars')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$showAll = $input->getOption('all');
|
||||
$variables = $this->prepareVariables($this->getVariables($showAll));
|
||||
|
||||
if (empty($variables)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'Variables' => $variables,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scope variables.
|
||||
*
|
||||
* @param bool $showAll Include special variables (e.g. $_)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getVariables(bool $showAll): array
|
||||
{
|
||||
$scopeVars = $this->context->getAll();
|
||||
\uksort($scopeVars, function ($a, $b) {
|
||||
$aIndex = \array_search($a, self::$specialNames);
|
||||
$bIndex = \array_search($b, self::$specialNames);
|
||||
|
||||
if ($aIndex !== false) {
|
||||
if ($bIndex !== false) {
|
||||
return $aIndex - $bIndex;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($bIndex !== false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return \strnatcasecmp($a, $b);
|
||||
});
|
||||
|
||||
$ret = [];
|
||||
foreach ($scopeVars as $name => $val) {
|
||||
if (!$showAll && \in_array($name, self::$specialNames)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$ret[$name] = $val;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare formatted variable array.
|
||||
*
|
||||
* @param array $variables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareVariables(array $variables): array
|
||||
{
|
||||
// My kingdom for a generator.
|
||||
$ret = [];
|
||||
foreach ($variables as $name => $val) {
|
||||
if ($this->showItem($name)) {
|
||||
$fname = '$'.$name;
|
||||
$ret[$fname] = [
|
||||
'name' => $fname,
|
||||
'style' => \in_array($name, self::$specialNames) ? self::IS_PRIVATE : self::IS_PUBLIC,
|
||||
'value' => $this->presentRef($val),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user