Namespace_.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\Node;
  5. use PhpParser\Node\Stmt;
  6. class Namespace_ extends PhpParser\BuilderAbstract
  7. {
  8. private $name;
  9. private $stmts = array();
  10. /**
  11. * Creates a namespace builder.
  12. *
  13. * @param Node\Name|string|null $name Name of the namespace
  14. */
  15. public function __construct($name) {
  16. $this->name = null !== $name ? $this->normalizeName($name) : null;
  17. }
  18. /**
  19. * Adds a statement.
  20. *
  21. * @param Node|PhpParser\Builder $stmt The statement to add
  22. *
  23. * @return $this The builder instance (for fluid interface)
  24. */
  25. public function addStmt($stmt) {
  26. $this->stmts[] = $this->normalizeNode($stmt);
  27. return $this;
  28. }
  29. /**
  30. * Adds multiple statements.
  31. *
  32. * @param array $stmts The statements to add
  33. *
  34. * @return $this The builder instance (for fluid interface)
  35. */
  36. public function addStmts(array $stmts) {
  37. foreach ($stmts as $stmt) {
  38. $this->addStmt($stmt);
  39. }
  40. return $this;
  41. }
  42. /**
  43. * Returns the built node.
  44. *
  45. * @return Node The built node
  46. */
  47. public function getNode() {
  48. return new Stmt\Namespace_($this->name, $this->stmts);
  49. }
  50. }