2017-08-18 22:57:27 +02:00
|
|
|
<?php declare(strict_types=1);
|
2014-12-11 17:24:10 +01:00
|
|
|
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
|
|
|
|
use PhpParser;
|
2017-04-24 21:15:11 +02:00
|
|
|
use PhpParser\BuilderHelpers;
|
2014-12-11 17:24:10 +01:00
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\Stmt;
|
|
|
|
|
2017-11-04 12:43:02 +01:00
|
|
|
class Namespace_ extends Declaration
|
2014-12-11 17:24:10 +01:00
|
|
|
{
|
|
|
|
private $name;
|
2017-08-13 14:06:08 +02:00
|
|
|
private $stmts = [];
|
2014-12-11 17:24:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a namespace builder.
|
|
|
|
*
|
2015-03-10 15:28:19 +01:00
|
|
|
* @param Node\Name|string|null $name Name of the namespace
|
2014-12-11 17:24:10 +01:00
|
|
|
*/
|
|
|
|
public function __construct($name) {
|
2017-04-24 21:15:11 +02:00
|
|
|
$this->name = null !== $name ? BuilderHelpers::normalizeName($name) : null;
|
2014-12-11 17:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a statement.
|
|
|
|
*
|
|
|
|
* @param Node|PhpParser\Builder $stmt The statement to add
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function addStmt($stmt) {
|
2017-04-24 21:15:11 +02:00
|
|
|
$this->stmts[] = BuilderHelpers::normalizeStmt($stmt);
|
2014-12-11 17:24:10 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the built node.
|
|
|
|
*
|
|
|
|
* @return Node The built node
|
|
|
|
*/
|
2017-04-28 21:40:59 +02:00
|
|
|
public function getNode() : Node {
|
2017-11-04 12:43:02 +01:00
|
|
|
return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes);
|
2014-12-11 17:24:10 +01:00
|
|
|
}
|
|
|
|
}
|