菜谱项目

Namespace_.php 948B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\Node;
  5. use PhpParser\Node\Stmt;
  6. class Namespace_ extends Declaration
  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. * Returns the built node.
  31. *
  32. * @return Node The built node
  33. */
  34. public function getNode() {
  35. return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes);
  36. }
  37. }