Property.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. class Property extends Node\Stmt
  6. {
  7. /** @var int Modifiers */
  8. public $type;
  9. /** @var PropertyProperty[] Properties */
  10. public $props;
  11. /**
  12. * Constructs a class property list node.
  13. *
  14. * @param int $type Modifiers
  15. * @param PropertyProperty[] $props Properties
  16. * @param array $attributes Additional attributes
  17. */
  18. public function __construct($type, array $props, array $attributes = array()) {
  19. if ($type & Class_::MODIFIER_ABSTRACT) {
  20. throw new Error('Properties cannot be declared abstract');
  21. }
  22. if ($type & Class_::MODIFIER_FINAL) {
  23. throw new Error('Properties cannot be declared final');
  24. }
  25. parent::__construct(null, $attributes);
  26. $this->type = $type;
  27. $this->props = $props;
  28. }
  29. public function getSubNodeNames() {
  30. return array('type', 'props');
  31. }
  32. public function isPublic() {
  33. return ($this->type & Class_::MODIFIER_PUBLIC) !== 0
  34. || ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0;
  35. }
  36. public function isProtected() {
  37. return (bool) ($this->type & Class_::MODIFIER_PROTECTED);
  38. }
  39. public function isPrivate() {
  40. return (bool) ($this->type & Class_::MODIFIER_PRIVATE);
  41. }
  42. public function isStatic() {
  43. return (bool) ($this->type & Class_::MODIFIER_STATIC);
  44. }
  45. }