No Description

Property.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Error;
  5. /**
  6. * @property int $type Modifiers
  7. * @property PropertyProperty[] $props Properties
  8. */
  9. class Property extends Node\Stmt
  10. {
  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 (0 === ($type & Class_::VISIBILITY_MODIFER_MASK)) {
  20. // If no visibility modifier given, PHP defaults to public
  21. $type |= Class_::MODIFIER_PUBLIC;
  22. }
  23. if ($type & Class_::MODIFIER_ABSTRACT) {
  24. throw new Error('Properties cannot be declared abstract');
  25. }
  26. if ($type & Class_::MODIFIER_FINAL) {
  27. throw new Error('Properties cannot be declared final');
  28. }
  29. parent::__construct(
  30. array(
  31. 'type' => $type,
  32. 'props' => $props,
  33. ),
  34. $attributes
  35. );
  36. }
  37. public function isPublic() {
  38. return (bool) ($this->type & Class_::MODIFIER_PUBLIC);
  39. }
  40. public function isProtected() {
  41. return (bool) ($this->type & Class_::MODIFIER_PROTECTED);
  42. }
  43. public function isPrivate() {
  44. return (bool) ($this->type & Class_::MODIFIER_PRIVATE);
  45. }
  46. public function isStatic() {
  47. return (bool) ($this->type & Class_::MODIFIER_STATIC);
  48. }
  49. }