mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-18 04:41:33 +02:00
Compare commits
6 Commits
v4.0.0alph
...
v3.1.3
Author | SHA1 | Date | |
---|---|---|---|
|
579f4ce846 | ||
|
94ca9a7ab9 | ||
|
bac91b426e | ||
|
08131e7ff2 | ||
|
0ba710affa | ||
|
72231abe6d |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,6 +1,19 @@
|
|||||||
Version 3.1.2-dev
|
Version 3.1.4-dev
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
Nothing yet.
|
||||||
|
|
||||||
|
Version 3.1.3 (2017-12-26)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Improve compatibility with php-scoper, by supporting prefixed namespaces in
|
||||||
|
`NodeAbstract::getType()`.
|
||||||
|
|
||||||
|
Version 3.1.2 (2017-11-04)
|
||||||
|
--------------------------
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Comments on empty blocks are now preserved on a `Stmt\Nop` node. (#382)
|
* Comments on empty blocks are now preserved on a `Stmt\Nop` node. (#382)
|
||||||
@@ -9,6 +22,7 @@ Version 3.1.2-dev
|
|||||||
|
|
||||||
* Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
|
* Added `kind` attribute for `Stmt\Namespace_` node, which is one of `KIND_SEMICOLON` or
|
||||||
`KIND_BRACED`. (#417)
|
`KIND_BRACED`. (#417)
|
||||||
|
* Added `setDocComment()` method to namespace builder. (#437)
|
||||||
|
|
||||||
Version 3.1.1 (2017-09-02)
|
Version 3.1.1 (2017-09-02)
|
||||||
--------------------------
|
--------------------------
|
||||||
|
@@ -6,7 +6,7 @@ use PhpParser;
|
|||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Namespace_ extends PhpParser\BuilderAbstract
|
class Namespace_ extends Declaration
|
||||||
{
|
{
|
||||||
private $name;
|
private $name;
|
||||||
private $stmts = array();
|
private $stmts = array();
|
||||||
@@ -33,27 +33,12 @@ class Namespace_ extends PhpParser\BuilderAbstract
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds multiple statements.
|
|
||||||
*
|
|
||||||
* @param array $stmts The statements to add
|
|
||||||
*
|
|
||||||
* @return $this The builder instance (for fluid interface)
|
|
||||||
*/
|
|
||||||
public function addStmts(array $stmts) {
|
|
||||||
foreach ($stmts as $stmt) {
|
|
||||||
$this->addStmt($stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the built node.
|
* Returns the built node.
|
||||||
*
|
*
|
||||||
* @return Node The built node
|
* @return Node The built node
|
||||||
*/
|
*/
|
||||||
public function getNode() {
|
public function getNode() {
|
||||||
return new Stmt\Namespace_($this->name, $this->stmts);
|
return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -360,7 +360,7 @@ class Lexer
|
|||||||
if ('T_HASHBANG' === $name) {
|
if ('T_HASHBANG' === $name) {
|
||||||
// HHVM uses a special token for #! hashbang lines
|
// HHVM uses a special token for #! hashbang lines
|
||||||
$tokenMap[$i] = Tokens::T_INLINE_HTML;
|
$tokenMap[$i] = Tokens::T_INLINE_HTML;
|
||||||
} else if (defined($name = 'PhpParser\Parser\Tokens::' . $name)) {
|
} else if (defined($name = Tokens::class . '::' . $name)) {
|
||||||
// Other tokens can be mapped directly
|
// Other tokens can be mapped directly
|
||||||
$tokenMap[$i] = constant($name);
|
$tokenMap[$i] = constant($name);
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
|||||||
public $params;
|
public $params;
|
||||||
/** @var null|string|Node\Name|Node\NullableType Return type */
|
/** @var null|string|Node\Name|Node\NullableType Return type */
|
||||||
public $returnType;
|
public $returnType;
|
||||||
/** @var Node[] Statements */
|
/** @var Node[]|null Statements */
|
||||||
public $stmts;
|
public $stmts;
|
||||||
|
|
||||||
/** @deprecated Use $flags instead */
|
/** @deprecated Use $flags instead */
|
||||||
|
@@ -21,7 +21,15 @@ abstract class NodeAbstract implements Node, \JsonSerializable
|
|||||||
* @return string Type of the node
|
* @return string Type of the node
|
||||||
*/
|
*/
|
||||||
public function getType() {
|
public function getType() {
|
||||||
return strtr(substr(rtrim(get_class($this), '_'), 15), '\\', '_');
|
$className = rtrim(get_class($this), '_');
|
||||||
|
return strtr(
|
||||||
|
substr(
|
||||||
|
$className,
|
||||||
|
strpos($className, 'PhpParser\Node') + 15
|
||||||
|
),
|
||||||
|
'\\',
|
||||||
|
'_'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace PhpParser\Builder;
|
namespace PhpParser\Builder;
|
||||||
|
|
||||||
|
use PhpParser\Comment\Doc;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
@@ -15,19 +16,23 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase
|
|||||||
$stmt1 = new Stmt\Class_('SomeClass');
|
$stmt1 = new Stmt\Class_('SomeClass');
|
||||||
$stmt2 = new Stmt\Interface_('SomeInterface');
|
$stmt2 = new Stmt\Interface_('SomeInterface');
|
||||||
$stmt3 = new Stmt\Function_('someFunction');
|
$stmt3 = new Stmt\Function_('someFunction');
|
||||||
|
$docComment = new Doc('/** Test */');
|
||||||
$expected = new Stmt\Namespace_(
|
$expected = new Stmt\Namespace_(
|
||||||
new Node\Name('Name\Space'),
|
new Node\Name('Name\Space'),
|
||||||
array($stmt1, $stmt2, $stmt3)
|
array($stmt1, $stmt2, $stmt3),
|
||||||
|
array('comments' => array($docComment))
|
||||||
);
|
);
|
||||||
|
|
||||||
$node = $this->createNamespaceBuilder('Name\Space')
|
$node = $this->createNamespaceBuilder('Name\Space')
|
||||||
->addStmt($stmt1)
|
->addStmt($stmt1)
|
||||||
->addStmts(array($stmt2, $stmt3))
|
->addStmts(array($stmt2, $stmt3))
|
||||||
|
->setDocComment($docComment)
|
||||||
->getNode()
|
->getNode()
|
||||||
;
|
;
|
||||||
$this->assertEquals($expected, $node);
|
$this->assertEquals($expected, $node);
|
||||||
|
|
||||||
$node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space')))
|
$node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space')))
|
||||||
|
->setDocComment($docComment)
|
||||||
->addStmts(array($stmt1, $stmt2))
|
->addStmts(array($stmt1, $stmt2))
|
||||||
->addStmt($stmt3)
|
->addStmt($stmt3)
|
||||||
->getNode()
|
->getNode()
|
||||||
|
Reference in New Issue
Block a user