Update v1.0.6
This commit is contained in:
241
vendor/psy/psysh/src/Psy/Util/Docblock.php
vendored
241
vendor/psy/psysh/src/Psy/Util/Docblock.php
vendored
@@ -1,241 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell
|
||||
*
|
||||
* (c) 2012-2014 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 = array(
|
||||
'throws' => array('type', 'desc'),
|
||||
'param' => array('type', 'var', 'desc'),
|
||||
'return' => array('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;
|
||||
$this->setComment($reflector->getDocComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and parse the docblock comment.
|
||||
*
|
||||
* @param string $comment The docblock
|
||||
*/
|
||||
protected function setComment($comment)
|
||||
{
|
||||
$this->desc = '';
|
||||
$this->tags = array();
|
||||
$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)
|
||||
{
|
||||
// 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);
|
||||
|
||||
// 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($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 = array();
|
||||
$b = -1;
|
||||
foreach ($comment as $line) {
|
||||
if (self::isTagged($line)) {
|
||||
$b++;
|
||||
$blocks[] = array();
|
||||
} elseif ($b === -1) {
|
||||
$b = 0;
|
||||
$blocks[] = array();
|
||||
}
|
||||
$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 = array();
|
||||
}
|
||||
|
||||
// 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($tag)
|
||||
{
|
||||
return is_array($this->tags) && array_key_exists($tag, $this->tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of a tag.
|
||||
*
|
||||
* @param string $tag
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tag($tag)
|
||||
{
|
||||
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($str)
|
||||
{
|
||||
return isset($str[1]) && $str[0] === '@' && ctype_alpha($str[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tag at the beginning of a string.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function strTag($str)
|
||||
{
|
||||
if (preg_match('/^@[a-z0-9_]+/', $str, $matches)) {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
35
vendor/psy/psysh/src/Psy/Util/Json.php
vendored
35
vendor/psy/psysh/src/Psy/Util/Json.php
vendored
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell
|
||||
*
|
||||
* (c) 2012-2014 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 integer $opt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode($val, $opt = 0)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.4', '>=')) {
|
||||
$opt |= JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
|
||||
}
|
||||
|
||||
return json_encode($val, $opt);
|
||||
}
|
||||
}
|
||||
94
vendor/psy/psysh/src/Psy/Util/Mirror.php
vendored
94
vendor/psy/psysh/src/Psy/Util/Mirror.php
vendored
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell
|
||||
*
|
||||
* (c) 2012-2014 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\ReflectionConstant;
|
||||
|
||||
/**
|
||||
* 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, $member = null, $filter = 15)
|
||||
{
|
||||
if ($member === null && is_string($value) && function_exists($value)) {
|
||||
return new \ReflectionFunction($value);
|
||||
}
|
||||
|
||||
$class = self::getClass($value);
|
||||
|
||||
if ($member === null) {
|
||||
return $class;
|
||||
} elseif ($filter & self::CONSTANT && $class->hasConstant($member)) {
|
||||
return new ReflectionConstant($class, $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) if possible.
|
||||
*
|
||||
* @throws \InvalidArgumentException if $value is not a class name or instance.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \ReflectionClass
|
||||
*/
|
||||
private static function getClass($value)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return new \ReflectionObject($value);
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
throw new \InvalidArgumentException('Mirror expects an object or class');
|
||||
} elseif (!class_exists($value) && !interface_exists($value) && !(function_exists('trait_exists') && trait_exists($value))) {
|
||||
throw new \InvalidArgumentException('Unknown class or function: ' . $value);
|
||||
}
|
||||
|
||||
return new \ReflectionClass($value);
|
||||
}
|
||||
}
|
||||
114
vendor/psy/psysh/src/Psy/Util/String.php
vendored
114
vendor/psy/psysh/src/Psy/Util/String.php
vendored
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell
|
||||
*
|
||||
* (c) 2012-2014 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 String
|
||||
{
|
||||
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 (  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($input)
|
||||
{
|
||||
$output = preg_replace_callback(self::UNVIS_RX, 'self::unvisReplace', $input);
|
||||
// other escapes & octal are handled by stripcslashes
|
||||
return stripcslashes($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for String::unvis.
|
||||
*
|
||||
* @param array $match The matches passed by preg_replace_callback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function unvisReplace($match)
|
||||
{
|
||||
// \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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user