update v 1.0.7.5
This commit is contained in:
@@ -15,8 +15,8 @@ class DNumber extends Scalar
|
||||
* @param float $value Value of the number
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = 0.0, array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
public function __construct($value, array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,8 @@ class Encapsed extends Scalar
|
||||
* @param array $parts Encaps list
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $parts = array(), array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
public function __construct(array $parts, array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
|
26
vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php
vendored
Normal file
26
vendor/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
class EncapsedStringPart extends Scalar
|
||||
{
|
||||
/** @var string String value */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs a node representing a string part of an encapsed string.
|
||||
*
|
||||
* @param string $value String value
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value, array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('value');
|
||||
}
|
||||
}
|
@@ -2,10 +2,17 @@
|
||||
|
||||
namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Error;
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
class LNumber extends Scalar
|
||||
{
|
||||
/* For use in "kind" attribute */
|
||||
const KIND_BIN = 2;
|
||||
const KIND_OCT = 8;
|
||||
const KIND_DEC = 10;
|
||||
const KIND_HEX = 16;
|
||||
|
||||
/** @var int Number value */
|
||||
public $value;
|
||||
|
||||
@@ -15,8 +22,8 @@ class LNumber extends Scalar
|
||||
* @param int $value Value of the number
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = 0, array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
public function __construct($value, array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
@@ -25,37 +32,36 @@ class LNumber extends Scalar
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Constructs an LNumber node from a string number literal.
|
||||
*
|
||||
* Parses an LNUMBER token (dec, hex, oct and bin notations) like PHP would.
|
||||
* @param string $str String number literal (decimal, octal, hex or binary)
|
||||
* @param array $attributes Additional attributes
|
||||
* @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5)
|
||||
*
|
||||
* @param string $str A string number
|
||||
*
|
||||
* @return int The parsed number
|
||||
* @return LNumber The constructed LNumber, including kind attribute
|
||||
*/
|
||||
public static function parse($str) {
|
||||
// handle plain 0 specially
|
||||
if ('0' === $str) {
|
||||
return 0;
|
||||
public static function fromString($str, array $attributes = array(), $allowInvalidOctal = false) {
|
||||
if ('0' !== $str[0] || '0' === $str) {
|
||||
$attributes['kind'] = LNumber::KIND_DEC;
|
||||
return new LNumber((int) $str, $attributes);
|
||||
}
|
||||
|
||||
// if first char is 0 (and number isn't 0) it's a special syntax
|
||||
if ('0' === $str[0]) {
|
||||
// hex
|
||||
if ('x' === $str[1] || 'X' === $str[1]) {
|
||||
return hexdec($str);
|
||||
}
|
||||
|
||||
// bin
|
||||
if ('b' === $str[1] || 'B' === $str[1]) {
|
||||
return bindec($str);
|
||||
}
|
||||
|
||||
// oct (intval instead of octdec to get proper cutting behavior with malformed numbers)
|
||||
return intval($str, 8);
|
||||
if ('x' === $str[1] || 'X' === $str[1]) {
|
||||
$attributes['kind'] = LNumber::KIND_HEX;
|
||||
return new LNumber(hexdec($str), $attributes);
|
||||
}
|
||||
|
||||
// dec
|
||||
return (int) $str;
|
||||
if ('b' === $str[1] || 'B' === $str[1]) {
|
||||
$attributes['kind'] = LNumber::KIND_BIN;
|
||||
return new LNumber(bindec($str), $attributes);
|
||||
}
|
||||
|
||||
if (!$allowInvalidOctal && strpbrk($str, '89')) {
|
||||
throw new Error('Invalid numeric literal', $attributes);
|
||||
}
|
||||
|
||||
// use intval instead of octdec to get proper cutting behavior with malformed numbers
|
||||
$attributes['kind'] = LNumber::KIND_OCT;
|
||||
return new LNumber(intval($str, 8), $attributes);
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ abstract class MagicConst extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
|
@@ -2,10 +2,17 @@
|
||||
|
||||
namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Error;
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
class String_ extends Scalar
|
||||
{
|
||||
/* For use in "kind" attribute */
|
||||
const KIND_SINGLE_QUOTED = 1;
|
||||
const KIND_DOUBLE_QUOTED = 2;
|
||||
const KIND_HEREDOC = 3;
|
||||
const KIND_NOWDOC = 4;
|
||||
|
||||
/** @var string String value */
|
||||
public $value;
|
||||
|
||||
@@ -26,8 +33,8 @@ class String_ extends Scalar
|
||||
* @param string $value Value of the string
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = '', array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
public function __construct($value, array $attributes = array()) {
|
||||
parent::__construct($attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
@@ -41,12 +48,13 @@ class String_ extends Scalar
|
||||
* Parses a string token.
|
||||
*
|
||||
* @param string $str String token content
|
||||
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
|
||||
*
|
||||
* @return string The parsed string
|
||||
*/
|
||||
public static function parse($str) {
|
||||
public static function parse($str, $parseUnicodeEscape = true) {
|
||||
$bLength = 0;
|
||||
if ('b' === $str[0]) {
|
||||
if ('b' === $str[0] || 'B' === $str[0]) {
|
||||
$bLength = 1;
|
||||
}
|
||||
|
||||
@@ -57,7 +65,9 @@ class String_ extends Scalar
|
||||
substr($str, $bLength + 1, -1)
|
||||
);
|
||||
} else {
|
||||
return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
|
||||
return self::parseEscapeSequences(
|
||||
substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,31 +78,54 @@ class String_ extends Scalar
|
||||
*
|
||||
* @param string $str String without quotes
|
||||
* @param null|string $quote Quote type
|
||||
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
|
||||
*
|
||||
* @return string String with escape sequences parsed
|
||||
*/
|
||||
public static function parseEscapeSequences($str, $quote) {
|
||||
public static function parseEscapeSequences($str, $quote, $parseUnicodeEscape = true) {
|
||||
if (null !== $quote) {
|
||||
$str = str_replace('\\' . $quote, $quote, $str);
|
||||
}
|
||||
|
||||
$extra = '';
|
||||
if ($parseUnicodeEscape) {
|
||||
$extra = '|u\{([0-9a-fA-F]+)\}';
|
||||
}
|
||||
|
||||
return preg_replace_callback(
|
||||
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~',
|
||||
array(__CLASS__, 'parseCallback'),
|
||||
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~',
|
||||
function($matches) {
|
||||
$str = $matches[1];
|
||||
|
||||
if (isset(self::$replacements[$str])) {
|
||||
return self::$replacements[$str];
|
||||
} elseif ('x' === $str[0] || 'X' === $str[0]) {
|
||||
return chr(hexdec($str));
|
||||
} elseif ('u' === $str[0]) {
|
||||
return self::codePointToUtf8(hexdec($matches[2]));
|
||||
} else {
|
||||
return chr(octdec($str));
|
||||
}
|
||||
},
|
||||
$str
|
||||
);
|
||||
}
|
||||
|
||||
private static function parseCallback($matches) {
|
||||
$str = $matches[1];
|
||||
|
||||
if (isset(self::$replacements[$str])) {
|
||||
return self::$replacements[$str];
|
||||
} elseif ('x' === $str[0] || 'X' === $str[0]) {
|
||||
return chr(hexdec($str));
|
||||
} else {
|
||||
return chr(octdec($str));
|
||||
private static function codePointToUtf8($num) {
|
||||
if ($num <= 0x7F) {
|
||||
return chr($num);
|
||||
}
|
||||
if ($num <= 0x7FF) {
|
||||
return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80);
|
||||
}
|
||||
if ($num <= 0xFFFF) {
|
||||
return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80);
|
||||
}
|
||||
if ($num <= 0x1FFFFF) {
|
||||
return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80)
|
||||
. chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80);
|
||||
}
|
||||
throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +135,11 @@ class String_ extends Scalar
|
||||
*
|
||||
* @param string $startToken Doc string start token content (<<<SMTHG)
|
||||
* @param string $str String token content
|
||||
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
|
||||
*
|
||||
* @return string Parsed string
|
||||
*/
|
||||
public static function parseDocString($startToken, $str) {
|
||||
public static function parseDocString($startToken, $str, $parseUnicodeEscape = true) {
|
||||
// strip last newline (thanks tokenizer for sticking it into the string!)
|
||||
$str = preg_replace('~(\r\n|\n|\r)\z~', '', $str);
|
||||
|
||||
@@ -114,6 +148,6 @@ class String_ extends Scalar
|
||||
return $str;
|
||||
}
|
||||
|
||||
return self::parseEscapeSequences($str, null);
|
||||
return self::parseEscapeSequences($str, null, $parseUnicodeEscape);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user