ClassMethod.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. switch (strtolower($this->name)) {
  35. case '__construct':
  36. throw new PHPParser_Error(sprintf('Constructor %s() cannot be static', $this->name));
  37. case '__destruct':
  38. throw new PHPParser_Error(sprintf('Destructor %s() cannot be static', $this->name));
  39. case '__clone':
  40. throw new PHPParser_Error(sprintf('Clone method %s() cannot be static', $this->name));
  41. }
  42. }
  43. }
  44. public function isPublic() {
  45. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC);
  46. }
  47. public function isProtected() {
  48. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED);
  49. }
  50. public function isPrivate() {
  51. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE);
  52. }
  53. public function isAbstract() {
  54. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT);
  55. }
  56. public function isFinal() {
  57. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_FINAL);
  58. }
  59. public function isStatic() {
  60. return (bool) ($this->type & PHPParser_Node_Stmt_Class::MODIFIER_STATIC);
  61. }
  62. }