Closure.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace PhpParser\Node\Expr;
  3. use PhpParser\Node;
  4. use PhpParser\Node\Expr;
  5. use PhpParser\Node\FunctionLike;
  6. class Closure extends Expr implements FunctionLike
  7. {
  8. /** @var bool Whether the closure is static */
  9. public $static;
  10. /** @var bool Whether to return by reference */
  11. public $byRef;
  12. /** @var Node\Param[] Parameters */
  13. public $params;
  14. /** @var ClosureUse[] use()s */
  15. public $uses;
  16. /** @var null|string|Node\Name|Node\NullableType Return type */
  17. public $returnType;
  18. /** @var Node[] Statements */
  19. public $stmts;
  20. /**
  21. * Constructs a lambda function node.
  22. *
  23. * @param array $subNodes Array of the following optional subnodes:
  24. * 'static' => false : Whether the closure is static
  25. * 'byRef' => false : Whether to return by reference
  26. * 'params' => array(): Parameters
  27. * 'uses' => array(): use()s
  28. * 'returnType' => null : Return type
  29. * 'stmts' => array(): Statements
  30. * @param array $attributes Additional attributes
  31. */
  32. public function __construct(array $subNodes = array(), array $attributes = array()) {
  33. parent::__construct($attributes);
  34. $this->static = isset($subNodes['static']) ? $subNodes['static'] : false;
  35. $this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
  36. $this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
  37. $this->uses = isset($subNodes['uses']) ? $subNodes['uses'] : array();
  38. $this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
  39. $this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
  40. }
  41. public function getSubNodeNames() {
  42. return array('static', 'byRef', 'params', 'uses', 'returnType', 'stmts');
  43. }
  44. public function returnsByRef() {
  45. return $this->byRef;
  46. }
  47. public function getParams() {
  48. return $this->params;
  49. }
  50. public function getReturnType() {
  51. return $this->returnType;
  52. }
  53. public function getStmts() {
  54. return $this->stmts;
  55. }
  56. }