ClassMethod.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @property int $type Type
  4. * @property bool $byRef Whether to return by reference
  5. * @property string $name Name
  6. * @property PHPParser_Node_Param[] $params Parameters
  7. * @property PHPParser_Node[] $stmts Statements
  8. */
  9. class PHPParser_Node_Stmt_ClassMethod extends PHPParser_Node_Stmt
  10. {
  11. /**
  12. * Constructs a class method node.
  13. *
  14. * @param string $name Name
  15. * @param array $subNodes Array of the following optional subnodes:
  16. * 'type' => MODIFIER_PUBLIC: Type
  17. * 'byRef' => false : Whether to return by reference
  18. * 'params' => array() : Parameters
  19. * 'stmts' => array() : Statements
  20. * @param array $attributes Additional attributes
  21. */
  22. public function __construct($name, array $subNodes = array(), array $attributes = array()) {
  23. parent::__construct(
  24. $subNodes + array(
  25. 'type' => PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC,
  26. 'byRef' => false,
  27. 'params' => array(),
  28. 'stmts' => array(),
  29. ),
  30. $attributes
  31. );
  32. $this->name = $name;
  33. if (($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC)
  34. && ('__construct' == $this->name || '__destruct' == $this->name || '__clone' == $this->name)
  35. ) {
  36. throw new PHPParser_Error(sprintf('"%s" method cannot be static', $this->name));
  37. }
  38. }
  39. public function isPublic() {
  40. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC);
  41. }
  42. public function isProtected() {
  43. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED);
  44. }
  45. public function isPrivate() {
  46. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE);
  47. }
  48. public function isAbstract() {
  49. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT);
  50. }
  51. public function isFinal() {
  52. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_FINAL);
  53. }
  54. public function isStatic() {
  55. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC);
  56. }
  57. }