No Description

Function_.php 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\Node;
  5. use PhpParser\Node\Stmt;
  6. class Function_ extends FunctionLike
  7. {
  8. protected $name;
  9. protected $stmts = array();
  10. /**
  11. * Creates a function builder.
  12. *
  13. * @param string $name Name of the function
  14. */
  15. public function __construct($name) {
  16. $this->name = $name;
  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 function node.
  31. *
  32. * @return Stmt\Function_ The built function node
  33. */
  34. public function getNode() {
  35. return new Stmt\Function_($this->name, array(
  36. 'byRef' => $this->returnByRef,
  37. 'params' => $this->params,
  38. 'stmts' => $this->stmts,
  39. ), $this->attributes);
  40. }
  41. }