mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-17 12:21:25 +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
|
||||
|
||||
* 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
|
||||
`KIND_BRACED`. (#417)
|
||||
* Added `setDocComment()` method to namespace builder. (#437)
|
||||
|
||||
Version 3.1.1 (2017-09-02)
|
||||
--------------------------
|
||||
|
@@ -6,7 +6,7 @@ use PhpParser;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt;
|
||||
|
||||
class Namespace_ extends PhpParser\BuilderAbstract
|
||||
class Namespace_ extends Declaration
|
||||
{
|
||||
private $name;
|
||||
private $stmts = array();
|
||||
@@ -33,27 +33,12 @@ class Namespace_ extends PhpParser\BuilderAbstract
|
||||
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.
|
||||
*
|
||||
* @return Node The built node
|
||||
*/
|
||||
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) {
|
||||
// HHVM uses a special token for #! hashbang lines
|
||||
$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
|
||||
$tokenMap[$i] = constant($name);
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
public $params;
|
||||
/** @var null|string|Node\Name|Node\NullableType Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
/** @var Node[]|null Statements */
|
||||
public $stmts;
|
||||
|
||||
/** @deprecated Use $flags instead */
|
||||
|
@@ -21,7 +21,15 @@ abstract class NodeAbstract implements Node, \JsonSerializable
|
||||
* @return string Type of the node
|
||||
*/
|
||||
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;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt;
|
||||
|
||||
@@ -15,19 +16,23 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase
|
||||
$stmt1 = new Stmt\Class_('SomeClass');
|
||||
$stmt2 = new Stmt\Interface_('SomeInterface');
|
||||
$stmt3 = new Stmt\Function_('someFunction');
|
||||
$docComment = new Doc('/** Test */');
|
||||
$expected = new Stmt\Namespace_(
|
||||
new Node\Name('Name\Space'),
|
||||
array($stmt1, $stmt2, $stmt3)
|
||||
array($stmt1, $stmt2, $stmt3),
|
||||
array('comments' => array($docComment))
|
||||
);
|
||||
|
||||
$node = $this->createNamespaceBuilder('Name\Space')
|
||||
->addStmt($stmt1)
|
||||
->addStmts(array($stmt2, $stmt3))
|
||||
->setDocComment($docComment)
|
||||
->getNode()
|
||||
;
|
||||
$this->assertEquals($expected, $node);
|
||||
|
||||
$node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space')))
|
||||
->setDocComment($docComment)
|
||||
->addStmts(array($stmt1, $stmt2))
|
||||
->addStmt($stmt3)
|
||||
->getNode()
|
||||
|
Reference in New Issue
Block a user