菜谱项目

Function_.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. 'returnType' => $this->returnType,
  39. 'stmts' => $this->stmts,
  40. ), $this->attributes);
  41. }
  42. }