mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-29 05:07:34 +01:00
Rename Expr\ClosureUse -> ClosureUse
This is not a real expression, treat it similarly to Node\Arg or Node\Param. The old name is retained as an alias for compatibility.
This commit is contained in:
parent
23be1f9bd1
commit
b0469d127e
@ -59,6 +59,14 @@ $parser = $factory->create(ParserFactory::ONLY_PHP5);
|
||||
$parser = $factory->createForVersion("5.6");
|
||||
```
|
||||
|
||||
### Renamed nodes
|
||||
|
||||
A number of AST nodes have been renamed or moved in the AST hierarchy:
|
||||
|
||||
* `Node\Expr\ClosureUse` is now `Node\ClosureUse` and no longer extends `Node\Expr`. The `ClosureUse` node can only occur inside closure use lists, not as a general expression.
|
||||
|
||||
The old class names have been retained as aliases for backwards compatibility. However, the `Node::getType()` method will now always return the new name (e.g. `ClosureUse` instead of `Expr_ClosureUse`).
|
||||
|
||||
### Changes to the default pretty printer
|
||||
|
||||
A number of changes to the standard pretty printer have been made, to make it match contemporary coding style conventions (and in particular PSR-12). Options to restore the previous behavior are not provided, but it is possible to override the formatting methods (such as `pStmt_ClassMethod`) with your preferred formatting.
|
||||
|
37
lib/PhpParser/Node/ClosureUse.php
Normal file
37
lib/PhpParser/Node/ClosureUse.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\NodeAbstract;
|
||||
|
||||
class ClosureUse extends NodeAbstract
|
||||
{
|
||||
/** @var Expr\Variable Variable to use */
|
||||
public $var;
|
||||
/** @var bool Whether to use by reference */
|
||||
public $byRef;
|
||||
|
||||
/**
|
||||
* Constructs a closure use node.
|
||||
*
|
||||
* @param Expr\Variable $var Variable to use
|
||||
* @param bool $byRef Whether to use by reference
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) {
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->byRef = $byRef;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['var', 'byRef'];
|
||||
}
|
||||
|
||||
public function getType() : string {
|
||||
return 'ClosureUse';
|
||||
}
|
||||
}
|
||||
|
||||
// @deprecated compatibility alias
|
||||
class_alias(ClosureUse::class, Expr\ClosureUse::class);
|
@ -3,6 +3,7 @@
|
||||
namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\ClosureUse;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
|
@ -1,34 +1,3 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
class ClosureUse extends Expr
|
||||
{
|
||||
/** @var Expr\Variable Variable to use */
|
||||
public $var;
|
||||
/** @var bool Whether to use by reference */
|
||||
public $byRef;
|
||||
|
||||
/**
|
||||
* Constructs a closure use node.
|
||||
*
|
||||
* @param Expr\Variable $var Variable to use
|
||||
* @param bool $byRef Whether to use by reference
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) {
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->byRef = $byRef;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['var', 'byRef'];
|
||||
}
|
||||
|
||||
public function getType() : string {
|
||||
return 'Expr_ClosureUse';
|
||||
}
|
||||
}
|
||||
require __DIR__ . '/../ClosureUse.php';
|
@ -2465,7 +2465,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
$this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)];
|
||||
},
|
||||
480 => function ($stackPos) {
|
||||
$this->semValue = new Expr\ClosureUse($this->semStack[$stackPos-(2-2)], $this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes);
|
||||
$this->semValue = new Node\ClosureUse($this->semStack[$stackPos-(2-2)], $this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes);
|
||||
},
|
||||
481 => function ($stackPos) {
|
||||
$this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes);
|
||||
|
@ -649,7 +649,7 @@ class Standard extends PrettyPrinterAbstract
|
||||
. $this->p($node->expr);
|
||||
}
|
||||
|
||||
protected function pExpr_ClosureUse(Expr\ClosureUse $node) {
|
||||
protected function pClosureUse(Node\ClosureUse $node) {
|
||||
return ($node->byRef ? '&' : '') . $this->p($node->var);
|
||||
}
|
||||
|
||||
|
18
test/PhpParser/CompatibilityTest.php
Normal file
18
test/PhpParser/CompatibilityTest.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
class CompatibilityTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testAliases1() {
|
||||
$node = new Node\ClosureUse(new Expr\Variable('x'));
|
||||
$this->assertTrue($node instanceof Expr\ClosureUse);
|
||||
}
|
||||
|
||||
public function testAliases2() {
|
||||
$node = new Node\Expr\ClosureUse(new Expr\Variable('x'));
|
||||
$this->assertTrue($node instanceof Node\ClosureUse);
|
||||
}
|
||||
}
|
@ -63,7 +63,7 @@ array(
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
0: Expr_ClosureUse(
|
||||
0: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: b
|
||||
)
|
||||
@ -84,13 +84,13 @@ array(
|
||||
params: array(
|
||||
)
|
||||
uses: array(
|
||||
0: Expr_ClosureUse(
|
||||
0: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: a
|
||||
)
|
||||
byRef: false
|
||||
)
|
||||
1: Expr_ClosureUse(
|
||||
1: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: b
|
||||
)
|
||||
@ -182,7 +182,7 @@ array(
|
||||
params: array(
|
||||
)
|
||||
uses: array(
|
||||
0: Expr_ClosureUse(
|
||||
0: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: a
|
||||
)
|
||||
|
@ -13,7 +13,7 @@ array(
|
||||
params: array(
|
||||
)
|
||||
uses: array(
|
||||
0: Expr_ClosureUse(
|
||||
0: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: a
|
||||
)
|
||||
|
@ -302,7 +302,7 @@ array(
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
0: Expr_ClosureUse(
|
||||
0: ClosureUse(
|
||||
var: Expr_Variable(
|
||||
name: f
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user