update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -22,7 +22,7 @@ class Arg extends NodeAbstract
* @param array $attributes Additional attributes
*/
public function __construct(Expr $value, $byRef = false, $unpack = false, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->value = $value;
$this->byRef = $byRef;
$this->unpack = $unpack;

View File

@@ -19,7 +19,7 @@ class Const_ extends NodeAbstract
* @param array $attributes Additional attributes
*/
public function __construct($name, Expr $value, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->value = $value;
}

View File

@@ -19,7 +19,7 @@ class ArrayDimFetch extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, Expr $dim = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->dim = $dim;
}

View File

@@ -22,7 +22,7 @@ class ArrayItem extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $value, Expr $key = null, $byRef = false, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->key = $key;
$this->value = $value;
$this->byRef = $byRef;

View File

@@ -6,6 +6,10 @@ use PhpParser\Node\Expr;
class Array_ extends Expr
{
// For use in "kind" attribute
const KIND_LONG = 1; // array() syntax
const KIND_SHORT = 2; // [] syntax
/** @var ArrayItem[] Items */
public $items;
@@ -16,7 +20,7 @@ class Array_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(array $items = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->items = $items;
}

View File

@@ -19,7 +19,7 @@ class Assign extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->expr = $expr;
}

View File

@@ -4,10 +4,6 @@ namespace PhpParser\Node\Expr;
use PhpParser\Node\Expr;
/**
* @property Expr $var Variable
* @property Expr $expr Expression
*/
abstract class AssignOp extends Expr
{
/** @var Expr Variable */
@@ -23,7 +19,7 @@ abstract class AssignOp extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->expr = $expr;
}

View File

@@ -4,10 +4,6 @@ namespace PhpParser\Node\Expr;
use PhpParser\Node\Expr;
/**
* @property Expr $var Variable reference is assigned to
* @property Expr $expr Variable which is referenced
*/
class AssignRef extends Expr
{
/** @var Expr Variable reference is assigned to */
@@ -23,7 +19,7 @@ class AssignRef extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->expr = $expr;
}

View File

@@ -19,7 +19,7 @@ abstract class BinaryOp extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $left, Expr $right, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->left = $left;
$this->right = $right;
}

View File

@@ -16,7 +16,7 @@ class BitwiseNot extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ class BooleanNot extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ abstract class Cast extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -20,7 +20,7 @@ class ClassConstFetch extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($class, $name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->class = $class;
$this->name = $name;
}

View File

@@ -16,7 +16,7 @@ class Clone_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -34,7 +34,7 @@ class Closure extends Expr implements FunctionLike
* @param array $attributes Additional attributes
*/
public function __construct(array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->static = isset($subNodes['static']) ? $subNodes['static'] : false;
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();

View File

@@ -19,7 +19,7 @@ class ClosureUse extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($var, $byRef = false, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->byRef = $byRef;
}

View File

@@ -17,7 +17,7 @@ class ConstFetch extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Name $name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
}

View File

@@ -16,7 +16,7 @@ class Empty_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ class ErrorSuppress extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ class Eval_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -6,6 +6,10 @@ use PhpParser\Node\Expr;
class Exit_ extends Expr
{
/* For use in "kind" attribute */
const KIND_EXIT = 1;
const KIND_DIE = 2;
/** @var null|Expr Expression */
public $expr;
@@ -16,7 +20,7 @@ class Exit_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -20,7 +20,7 @@ class FuncCall extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($name, array $args = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->args = $args;
}

View File

@@ -24,7 +24,7 @@ class Include_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, $type, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
$this->type = $type;
}

View File

@@ -20,7 +20,7 @@ class Instanceof_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, $class, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
$this->class = $class;
}

View File

@@ -16,7 +16,7 @@ class Isset_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->vars = $vars;
}

View File

@@ -16,7 +16,7 @@ class List_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->vars = $vars;
}

View File

@@ -23,7 +23,7 @@ class MethodCall extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, $name, array $args = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->name = $name;
$this->args = $args;

View File

@@ -20,7 +20,7 @@ class New_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($class, array $args = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->class = $class;
$this->args = $args;
}

View File

@@ -16,7 +16,7 @@ class PostDec extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
}

View File

@@ -16,7 +16,7 @@ class PostInc extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
}

View File

@@ -16,7 +16,7 @@ class PreDec extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
}

View File

@@ -16,7 +16,7 @@ class PreInc extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
}

View File

@@ -16,7 +16,7 @@ class Print_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -19,7 +19,7 @@ class PropertyFetch extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, $name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->var = $var;
$this->name = $name;
}

View File

@@ -16,7 +16,7 @@ class ShellExec extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(array $parts, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->parts = $parts;
}

View File

@@ -23,7 +23,7 @@ class StaticCall extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($class, $name, array $args = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->class = $class;
$this->name = $name;
$this->args = $args;

View File

@@ -20,7 +20,7 @@ class StaticPropertyFetch extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($class, $name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->class = $class;
$this->name = $name;
}

View File

@@ -22,7 +22,7 @@ class Ternary extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $cond, $if, Expr $else, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->if = $if;
$this->else = $else;

View File

@@ -16,7 +16,7 @@ class UnaryMinus extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ class UnaryPlus extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -16,7 +16,7 @@ class Variable extends Expr
* @param array $attributes Additional attributes
*/
public function __construct($name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
}

View File

@@ -16,7 +16,7 @@ class YieldFrom extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -19,7 +19,7 @@ class Yield_ extends Expr
* @param array $attributes Additional attributes
*/
public function __construct(Expr $value = null, Expr $key = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->key = $key;
$this->value = $value;
}

View File

@@ -20,7 +20,7 @@ class Name extends NodeAbstract
$parts = explode('\\', $parts);
}
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->parts = $parts;
}
@@ -106,37 +106,45 @@ class Name extends NodeAbstract
/**
* Sets the whole name.
*
* @deprecated Create a new Name instead, or manually modify the $parts property
*
* @param string|array|self $name The name to set the whole name to
*/
public function set($name) {
$this->parts = $this->prepareName($name);
$this->parts = self::prepareName($name);
}
/**
* Prepends a name to this name.
*
* @deprecated Use Name::concat($name1, $name2) instead
*
* @param string|array|self $name Name to prepend
*/
public function prepend($name) {
$this->parts = array_merge($this->prepareName($name), $this->parts);
$this->parts = array_merge(self::prepareName($name), $this->parts);
}
/**
* Appends a name to this name.
*
* @deprecated Use Name::concat($name1, $name2) instead
*
* @param string|array|self $name Name to append
*/
public function append($name) {
$this->parts = array_merge($this->parts, $this->prepareName($name));
$this->parts = array_merge($this->parts, self::prepareName($name));
}
/**
* Sets the first part of the name.
*
* @deprecated Use concat($first, $name->slice(1)) instead
*
* @param string|array|self $name The name to set the first part to
*/
public function setFirst($name) {
array_splice($this->parts, 0, 1, $this->prepareName($name));
array_splice($this->parts, 0, 1, self::prepareName($name));
}
/**
@@ -145,7 +153,47 @@ class Name extends NodeAbstract
* @param string|array|self $name The name to set the last part to
*/
public function setLast($name) {
array_splice($this->parts, -1, 1, $this->prepareName($name));
array_splice($this->parts, -1, 1, self::prepareName($name));
}
/**
* Gets a slice of a name (similar to array_slice).
*
* This method returns a new instance of the same type as the original and with the same
* attributes.
*
* If the slice is empty, a Name with an empty parts array is returned. While this is
* meaningless in itself, it works correctly in conjunction with concat().
*
* @param int $offset Offset to start the slice at
*
* @return static Sliced name
*/
public function slice($offset) {
// TODO negative offset and length
if ($offset < 0 || $offset > count($this->parts)) {
throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset));
}
return new static(array_slice($this->parts, $offset), $this->attributes);
}
/**
* Concatenate two names, yielding a new Name instance.
*
* The type of the generated instance depends on which class this method is called on, for
* example Name\FullyQualified::concat() will yield a Name\FullyQualified instance.
*
* @param string|array|self $name1 The first name
* @param string|array|self $name2 The second name
* @param array $attributes Attributes to assign to concatenated name
*
* @return static Concatenated name
*/
public static function concat($name1, $name2, array $attributes = []) {
return new static(
array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes
);
}
/**
@@ -156,7 +204,7 @@ class Name extends NodeAbstract
*
* @return array Prepared name
*/
protected function prepareName($name) {
private static function prepareName($name) {
if (is_string($name)) {
return explode('\\', $name);
} elseif (is_array($name)) {

View File

@@ -29,7 +29,7 @@ class Param extends NodeAbstract
* @param array $attributes Additional attributes
*/
public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = $type;
$this->byRef = $byRef;
$this->variadic = $variadic;

View File

@@ -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;
}

View File

@@ -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;
}

View 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');
}
}

View File

@@ -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);
}
}

View File

@@ -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() {

View File

@@ -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);
}
}

View File

@@ -16,7 +16,7 @@ class Break_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $num = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->num = $num;
}

View File

@@ -19,7 +19,7 @@ class Case_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct($cond, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}

View File

@@ -22,7 +22,7 @@ class Catch_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $type, $var, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = $type;
$this->var = $var;
$this->stmts = $stmts;

View File

@@ -16,7 +16,7 @@ class ClassConst extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $consts, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->consts = $consts;
}

View File

@@ -34,7 +34,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->name = $name;

View File

@@ -41,7 +41,7 @@ class Class_ extends ClassLike
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
$this->name = $name;
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;

View File

@@ -16,7 +16,7 @@ class Const_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $consts, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->consts = $consts;
}

View File

@@ -16,7 +16,7 @@ class Continue_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $num = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->num = $num;
}

View File

@@ -19,7 +19,7 @@ class DeclareDeclare extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct($key, Node\Expr $value, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->key = $key;
$this->value = $value;
}

View File

@@ -14,11 +14,11 @@ class Declare_ extends Node\Stmt
* Constructs a declare node.
*
* @param DeclareDeclare[] $declares List of declares
* @param Node[] $stmts Statements
* @param Node[]|null $stmts Statements
* @param array $attributes Additional attributes
*/
public function __construct(array $declares, array $stmts, array $attributes = array()) {
parent::__construct(null, $attributes);
public function __construct(array $declares, array $stmts = null, array $attributes = array()) {
parent::__construct($attributes);
$this->declares = $declares;
$this->stmts = $stmts;
}

View File

@@ -19,7 +19,7 @@ class Do_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}

View File

@@ -16,7 +16,7 @@ class Echo_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $exprs, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->exprs = $exprs;
}

View File

@@ -19,7 +19,7 @@ class ElseIf_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}

View File

@@ -16,7 +16,7 @@ class Else_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->stmts = $stmts;
}

View File

@@ -26,7 +26,7 @@ class For_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->init = isset($subNodes['init']) ? $subNodes['init'] : array();
$this->cond = isset($subNodes['cond']) ? $subNodes['cond'] : array();
$this->loop = isset($subNodes['loop']) ? $subNodes['loop'] : array();

View File

@@ -29,7 +29,7 @@ class Foreach_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
$this->keyVar = isset($subNodes['keyVar']) ? $subNodes['keyVar'] : null;
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;

View File

@@ -30,7 +30,7 @@ class Function_ extends Node\Stmt implements FunctionLike
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
$this->name = $name;
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();

View File

@@ -16,7 +16,7 @@ class Global_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->vars = $vars;
}

View File

@@ -16,7 +16,7 @@ class Goto_ extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct($name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
}

View File

@@ -0,0 +1,35 @@
<?php
namespace PhpParser\Node\Stmt;
use PhpParser\Node\Stmt;
use PhpParser\Node\Name;
class GroupUse extends Stmt
{
/** @var int Type of group use */
public $type;
/** @var Name Prefix for uses */
public $prefix;
/** @var UseUse[] Uses */
public $uses;
/**
* Constructs a group use node.
*
* @param Name $prefix Prefix for uses
* @param UseUse[] $uses Uses
* @param int $type Type of group use
* @param array $attributes Additional attributes
*/
public function __construct(Name $prefix, array $uses, $type = Use_::TYPE_NORMAL, array $attributes = array()) {
parent::__construct($attributes);
$this->type = $type;
$this->prefix = $prefix;
$this->uses = $uses;
}
public function getSubNodeNames() {
return array('type', 'prefix', 'uses');
}
}

View File

@@ -16,7 +16,7 @@ class HaltCompiler extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct($remaining, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->remaining = $remaining;
}

View File

@@ -26,7 +26,7 @@ class If_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
$this->elseifs = isset($subNodes['elseifs']) ? $subNodes['elseifs'] : array();

View File

@@ -16,7 +16,7 @@ class InlineHTML extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->value = $value;
}

View File

@@ -26,7 +26,7 @@ class Interface_ extends ClassLike
* @param array $attributes Additional attributes
*/
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : array();
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();

View File

@@ -16,7 +16,7 @@ class Label extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct($name, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
}

View File

@@ -26,7 +26,7 @@ class Namespace_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->stmts = $stmts;

View File

@@ -0,0 +1,13 @@
<?php
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
/** Nop/empty statement (;). */
class Nop extends Node\Stmt
{
public function getSubNodeNames() {
return array();
}
}

View File

@@ -28,7 +28,7 @@ class Property extends Node\Stmt
throw new Error('Properties cannot be declared final');
}
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = $type;
$this->props = $props;
}

View File

@@ -19,7 +19,7 @@ class PropertyProperty extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct($name, Node\Expr $default = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->default = $default;
}

View File

@@ -16,7 +16,7 @@ class Return_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -19,7 +19,7 @@ class StaticVar extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct($name, Node\Expr $default = null, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->default = $default;
}

View File

@@ -16,7 +16,7 @@ class Static_ extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->vars = $vars;
}

View File

@@ -19,7 +19,7 @@ class Switch_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $cases, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->cases = $cases;
}

View File

@@ -16,7 +16,7 @@ class Throw_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->expr = $expr;
}

View File

@@ -20,7 +20,7 @@ class TraitUse extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $traits, array $adaptations = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->traits = $traits;
$this->adaptations = $adaptations;
}

View File

@@ -21,7 +21,7 @@ class Alias extends Node\Stmt\TraitUseAdaptation
* @param array $attributes Additional attributes
*/
public function __construct($trait, $method, $newModifier, $newName, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->trait = $trait;
$this->method = $method;
$this->newModifier = $newModifier;

View File

@@ -18,7 +18,7 @@ class Precedence extends Node\Stmt\TraitUseAdaptation
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->trait = $trait;
$this->method = $method;
$this->insteadof = $insteadof;

View File

@@ -14,7 +14,7 @@ class Trait_ extends ClassLike
* @param array $attributes Additional attributes
*/
public function __construct($name, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->name = $name;
$this->stmts = $stmts;
}

View File

@@ -27,7 +27,7 @@ class TryCatch extends Node\Stmt
throw new Error('Cannot use try without catch or finally');
}
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->stmts = $stmts;
$this->catches = $catches;
$this->finallyStmts = $finallyStmts;

View File

@@ -16,7 +16,7 @@ class Unset_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->vars = $vars;
}

View File

@@ -7,6 +7,8 @@ use PhpParser\Error;
class UseUse extends Node\Stmt
{
/** @var int One of the Stmt\Use_::TYPE_* constants. Will only differ from TYPE_UNKNOWN for mixed group uses */
public $type;
/** @var Node\Name Namespace, class, function or constant to alias */
public $name;
/** @var string Alias */
@@ -17,9 +19,10 @@ class UseUse extends Node\Stmt
*
* @param Node\Name $name Namespace/Class to alias
* @param null|string $alias Alias
* @param int $type Type of the use element (for mixed group use declarations only)
* @param array $attributes Additional attributes
*/
public function __construct(Node\Name $name, $alias = null, array $attributes = array()) {
public function __construct(Node\Name $name, $alias = null, $type = Use_::TYPE_UNKNOWN, array $attributes = array()) {
if (null === $alias) {
$alias = $name->getLast();
}
@@ -31,12 +34,13 @@ class UseUse extends Node\Stmt
));
}
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = $type;
$this->name = $name;
$this->alias = $alias;
}
public function getSubNodeNames() {
return array('name', 'alias');
return array('type', 'name', 'alias');
}
}

View File

@@ -6,8 +6,17 @@ use PhpParser\Node\Stmt;
class Use_ extends Stmt
{
const TYPE_NORMAL = 1;
/**
* Unknown type. Both Stmt\Use_ / Stmt\GroupUse and Stmt\UseUse have a $type property, one of them will always be
* TYPE_UNKNOWN while the other has one of the three other possible types. For normal use statements the type on the
* Stmt\UseUse is unknown. It's only the other way around for mixed group use declarations.
*/
const TYPE_UNKNOWN = 0;
/** Class or namespace import */
const TYPE_NORMAL = 1;
/** Function import */
const TYPE_FUNCTION = 2;
/** Constant import */
const TYPE_CONSTANT = 3;
/** @var int Type of alias */
@@ -23,7 +32,7 @@ class Use_ extends Stmt
* @param array $attributes Additional attributes
*/
public function __construct(array $uses, $type = self::TYPE_NORMAL, array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->type = $type;
$this->uses = $uses;
}

View File

@@ -19,7 +19,7 @@ class While_ extends Node\Stmt
* @param array $attributes Additional attributes
*/
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
parent::__construct(null, $attributes);
parent::__construct($attributes);
$this->cond = $cond;
$this->stmts = $stmts;
}