菜谱项目

ClassMethod.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Node\FunctionLike;
  5. class ClassMethod extends Node\Stmt implements FunctionLike
  6. {
  7. /** @var int Flags */
  8. public $flags;
  9. /** @var bool Whether to return by reference */
  10. public $byRef;
  11. /** @var string Name */
  12. public $name;
  13. /** @var Node\Param[] Parameters */
  14. public $params;
  15. /** @var null|string|Node\Name|Node\NullableType Return type */
  16. public $returnType;
  17. /** @var Node[]|null Statements */
  18. public $stmts;
  19. /** @deprecated Use $flags instead */
  20. public $type;
  21. /**
  22. * Constructs a class method node.
  23. *
  24. * @param string $name Name
  25. * @param array $subNodes Array of the following optional subnodes:
  26. * 'flags => MODIFIER_PUBLIC: Flags
  27. * 'byRef' => false : Whether to return by reference
  28. * 'params' => array() : Parameters
  29. * 'returnType' => null : Return type
  30. * 'stmts' => array() : Statements
  31. * @param array $attributes Additional attributes
  32. */
  33. public function __construct($name, array $subNodes = array(), array $attributes = array()) {
  34. parent::__construct($attributes);
  35. $this->flags = isset($subNodes['flags']) ? $subNodes['flags']
  36. : (isset($subNodes['type']) ? $subNodes['type'] : 0);
  37. $this->type = $this->flags;
  38. $this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
  39. $this->name = $name;
  40. $this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
  41. $this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
  42. $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
  43. }
  44. public function getSubNodeNames() {
  45. return array('flags', 'byRef', 'name', 'params', 'returnType', 'stmts');
  46. }
  47. public function returnsByRef() {
  48. return $this->byRef;
  49. }
  50. public function getParams() {
  51. return $this->params;
  52. }
  53. public function getReturnType() {
  54. return $this->returnType;
  55. }
  56. public function getStmts() {
  57. return $this->stmts;
  58. }
  59. public function isPublic() {
  60. return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
  61. || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
  62. }
  63. public function isProtected() {
  64. return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
  65. }
  66. public function isPrivate() {
  67. return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
  68. }
  69. public function isAbstract() {
  70. return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
  71. }
  72. public function isFinal() {
  73. return (bool) ($this->flags & Class_::MODIFIER_FINAL);
  74. }
  75. public function isStatic() {
  76. return (bool) ($this->flags & Class_::MODIFIER_STATIC);
  77. }
  78. }