Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

249
vendor/psy/psysh/src/Util/Docblock.php vendored Normal file
View File

@@ -0,0 +1,249 @@
<?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\Util;
/**
* A docblock representation.
*
* Based on PHP-DocBlock-Parser by Paul Scott:
*
* {@link http://www.github.com/icio/PHP-DocBlock-Parser}
*
* @author Paul Scott <paul@duedil.com>
* @author Justin Hileman <justin@justinhileman.info>
*/
class Docblock
{
/**
* Tags in the docblock that have a whitespace-delimited number of parameters
* (such as `@param type var desc` and `@return type desc`) and the names of
* those parameters.
*
* @var array
*/
public static $vectors = [
'throws' => ['type', 'desc'],
'param' => ['type', 'var', 'desc'],
'return' => ['type', 'desc'],
];
protected $reflector;
/**
* The description of the symbol.
*
* @var string
*/
public $desc;
/**
* The tags defined in the docblock.
*
* The array has keys which are the tag names (excluding the @) and values
* that are arrays, each of which is an entry for the tag.
*
* In the case where the tag name is defined in {@see DocBlock::$vectors} the
* value within the tag-value array is an array in itself with keys as
* described by {@see DocBlock::$vectors}.
*
* @var array
*/
public $tags;
/**
* The entire DocBlock comment that was parsed.
*
* @var string
*/
public $comment;
/**
* Docblock constructor.
*
* @param \Reflector $reflector
*/
public function __construct(\Reflector $reflector)
{
$this->reflector = $reflector;
if ($reflector instanceof \ReflectionClass || $reflector instanceof \ReflectionClassConstant || $reflector instanceof \ReflectionFunctionAbstract || $reflector instanceof \ReflectionProperty) {
$this->setComment($reflector->getDocComment());
}
}
/**
* Set and parse the docblock comment.
*
* @param string $comment The docblock
*/
protected function setComment(string $comment)
{
$this->desc = '';
$this->tags = [];
$this->comment = $comment;
$this->parseComment($comment);
}
/**
* Find the length of the docblock prefix.
*
* @param array $lines
*
* @return int Prefix length
*/
protected static function prefixLength(array $lines): int
{
// find only lines with interesting things
$lines = \array_filter($lines, function ($line) {
return \substr($line, \strspn($line, "* \t\n\r\0\x0B"));
});
// if we sort the lines, we only have to compare two items
\sort($lines);
$first = \reset($lines);
$last = \end($lines);
// Special case for single-line comments
if (\count($lines) === 1) {
return \strspn($first, "* \t\n\r\0\x0B");
}
// find the longest common substring
$count = \min(\strlen($first), \strlen($last));
for ($i = 0; $i < $count; $i++) {
if ($first[$i] !== $last[$i]) {
return $i;
}
}
return $count;
}
/**
* Parse the comment into the component parts and set the state of the object.
*
* @param string $comment The docblock
*/
protected function parseComment(string $comment)
{
// Strip the opening and closing tags of the docblock
$comment = \substr($comment, 3, -2);
// Split into arrays of lines
$comment = \array_filter(\preg_split('/\r?\n\r?/', $comment));
// Trim asterisks and whitespace from the beginning and whitespace from the end of lines
$prefixLength = self::prefixLength($comment);
$comment = \array_map(function ($line) use ($prefixLength) {
return \rtrim(\substr($line, $prefixLength));
}, $comment);
// Group the lines together by @tags
$blocks = [];
$b = -1;
foreach ($comment as $line) {
if (self::isTagged($line)) {
$b++;
$blocks[] = [];
} elseif ($b === -1) {
$b = 0;
$blocks[] = [];
}
$blocks[$b][] = $line;
}
// Parse the blocks
foreach ($blocks as $block => $body) {
$body = \trim(\implode("\n", $body));
if ($block === 0 && !self::isTagged($body)) {
// This is the description block
$this->desc = $body;
} else {
// This block is tagged
$tag = \substr(self::strTag($body), 1);
$body = \ltrim(\substr($body, \strlen($tag) + 2));
if (isset(self::$vectors[$tag])) {
// The tagged block is a vector
$count = \count(self::$vectors[$tag]);
if ($body) {
$parts = \preg_split('/\s+/', $body, $count);
} else {
$parts = [];
}
// Default the trailing values
$parts = \array_pad($parts, $count, null);
// Store as a mapped array
$this->tags[$tag][] = \array_combine(self::$vectors[$tag], $parts);
} else {
// The tagged block is only text
$this->tags[$tag][] = $body;
}
}
}
}
/**
* Whether or not a docblock contains a given @tag.
*
* @param string $tag The name of the @tag to check for
*
* @return bool
*/
public function hasTag(string $tag): bool
{
return \is_array($this->tags) && \array_key_exists($tag, $this->tags);
}
/**
* The value of a tag.
*
* @param string $tag
*
* @return array
*/
public function tag(string $tag): array
{
return $this->hasTag($tag) ? $this->tags[$tag] : null;
}
/**
* Whether or not a string begins with a @tag.
*
* @param string $str
*
* @return bool
*/
public static function isTagged(string $str): bool
{
return isset($str[1]) && $str[0] === '@' && !\preg_match('/[^A-Za-z]/', $str[1]);
}
/**
* The tag at the beginning of a string.
*
* @param string $str
*
* @return string|null
*/
public static function strTag(string $str)
{
if (\preg_match('/^@[a-z0-9_]+/', $str, $matches)) {
return $matches[0];
}
}
}

33
vendor/psy/psysh/src/Util/Json.php vendored Normal file
View File

@@ -0,0 +1,33 @@
<?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\Util;
/**
* A static class to wrap JSON encoding/decoding with PsySH's default options.
*/
class Json
{
/**
* Encode a value as JSON.
*
* @param mixed $val
* @param int $opt
*
* @return string
*/
public static function encode($val, int $opt = 0): string
{
$opt |= \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE;
return \json_encode($val, $opt);
}
}

150
vendor/psy/psysh/src/Util/Mirror.php vendored Normal file
View File

@@ -0,0 +1,150 @@
<?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\Util;
use Psy\Exception\RuntimeException;
use Psy\Reflection\ReflectionClassConstant;
use Psy\Reflection\ReflectionConstant_;
use Psy\Reflection\ReflectionNamespace;
/**
* A utility class for getting Reflectors.
*/
class Mirror
{
const CONSTANT = 1;
const METHOD = 2;
const STATIC_PROPERTY = 4;
const PROPERTY = 8;
/**
* Get a Reflector for a function, class or instance, constant, method or property.
*
* Optionally, pass a $filter param to restrict the types of members checked. For example, to only Reflectors for
* static properties and constants, pass:
*
* $filter = Mirror::CONSTANT | Mirror::STATIC_PROPERTY
*
* @throws \Psy\Exception\RuntimeException when a $member specified but not present on $value
* @throws \InvalidArgumentException if $value is something other than an object or class/function name
*
* @param mixed $value Class or function name, or variable instance
* @param string $member Optional: property, constant or method name (default: null)
* @param int $filter (default: CONSTANT | METHOD | PROPERTY | STATIC_PROPERTY)
*
* @return \Reflector
*/
public static function get($value, string $member = null, int $filter = 15): \Reflector
{
if ($member === null && \is_string($value)) {
if (\function_exists($value)) {
return new \ReflectionFunction($value);
} elseif (\defined($value) || ReflectionConstant_::isMagicConstant($value)) {
return new ReflectionConstant_($value);
}
}
$class = self::getClass($value);
if ($member === null) {
return $class;
} elseif ($filter & self::CONSTANT && $class->hasConstant($member)) {
return ReflectionClassConstant::create($value, $member);
} elseif ($filter & self::METHOD && $class->hasMethod($member)) {
return $class->getMethod($member);
} elseif ($filter & self::PROPERTY && $class->hasProperty($member)) {
return $class->getProperty($member);
} elseif ($filter & self::STATIC_PROPERTY && $class->hasProperty($member) && $class->getProperty($member)->isStatic()) {
return $class->getProperty($member);
} else {
throw new RuntimeException(\sprintf('Unknown member %s on class %s', $member, \is_object($value) ? \get_class($value) : $value));
}
}
/**
* Get a ReflectionClass (or ReflectionObject, or ReflectionNamespace) if possible.
*
* @throws \InvalidArgumentException if $value is not a namespace or class name or instance
*
* @param mixed $value
*
* @return \ReflectionClass|ReflectionNamespace
*/
private static function getClass($value)
{
if (\is_object($value)) {
return new \ReflectionObject($value);
}
if (!\is_string($value)) {
throw new \InvalidArgumentException('Mirror expects an object or class');
}
if (\class_exists($value) || \interface_exists($value) || \trait_exists($value)) {
return new \ReflectionClass($value);
}
$namespace = \preg_replace('/(^\\\\|\\\\$)/', '', $value);
if (self::namespaceExists($namespace)) {
return new ReflectionNamespace($namespace);
}
throw new \InvalidArgumentException('Unknown namespace, class or function: '.$value);
}
/**
* Check declared namespaces for a given namespace.
*/
private static function namespaceExists(string $value): bool
{
return \in_array(\strtolower($value), self::getDeclaredNamespaces());
}
/**
* Get an array of all currently declared namespaces.
*
* Note that this relies on at least one function, class, interface, trait
* or constant to have been declared in that namespace.
*/
private static function getDeclaredNamespaces(): array
{
$functions = \get_defined_functions();
$allNames = \array_merge(
$functions['internal'],
$functions['user'],
\get_declared_classes(),
\get_declared_interfaces(),
\get_declared_traits(),
\array_keys(\get_defined_constants())
);
$namespaces = [];
foreach ($allNames as $name) {
$chunks = \explode('\\', \strtolower($name));
// the last one is the function or class or whatever...
\array_pop($chunks);
while (!empty($chunks)) {
$namespaces[\implode('\\', $chunks)] = true;
\array_pop($chunks);
}
}
$namespaceNames = \array_keys($namespaces);
\sort($namespaceNames);
return $namespaceNames;
}
}

114
vendor/psy/psysh/src/Util/Str.php vendored Normal file
View File

@@ -0,0 +1,114 @@
<?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\Util;
/**
* String utility methods.
*
* @author ju1ius
*/
class Str
{
const UNVIS_RX = <<<'EOS'
/
\\(?:
((?:040)|s)
| (240)
| (?: M-(.) )
| (?: M\^(.) )
| (?: \^(.) )
)
/xS
EOS;
/**
* Decodes a string encoded by libsd's strvis.
*
* From `man 3 vis`:
*
* Use an M to represent meta characters (characters with the 8th bit set),
* and use a caret ^ to represent control characters (see iscntrl(3)).
* The following formats are used:
*
* \040 Represents ASCII space.
*
* \240 Represents Meta-space (&nbsp in HTML).
*
* \M-C Represents character C with the 8th bit set.
* Spans characters \241 through \376.
*
* \M^C Represents control character C with the 8th bit set.
* Spans characters \200 through \237, and \377 (as \M^?).
*
* \^C Represents the control character C.
* Spans characters \000 through \037, and \177 (as \^?).
*
* The other formats are supported by PHP's stripcslashes,
* except for the \s sequence (ASCII space).
*
* @param string $input The string to decode
*
* @return string
*/
public static function unvis(string $input): string
{
$output = \preg_replace_callback(self::UNVIS_RX, 'self::unvisReplace', $input);
// other escapes & octal are handled by stripcslashes
return \stripcslashes($output);
}
/**
* Callback for Str::unvis.
*
* @param array $match The matches passed by preg_replace_callback
*
* @return string
*/
protected static function unvisReplace(array $match): string
{
// \040, \s
if (!empty($match[1])) {
return "\x20";
}
// \240
if (!empty($match[2])) {
return "\xa0";
}
// \M-(.)
if (isset($match[3]) && $match[3] !== '') {
$chr = $match[3];
// unvis S_META1
$cp = 0200;
$cp |= \ord($chr);
return \chr($cp);
}
// \M^(.)
if (isset($match[4]) && $match[4] !== '') {
$chr = $match[4];
// unvis S_META | S_CTRL
$cp = 0200;
$cp |= ($chr === '?') ? 0177 : \ord($chr) & 037;
return \chr($cp);
}
// \^(.)
if (isset($match[5]) && $match[5] !== '') {
$chr = $match[5];
// unvis S_CTRL
$cp = 0;
$cp |= ($chr === '?') ? 0177 : \ord($chr) & 037;
return \chr($cp);
}
}
}