| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace PhpParser\Node\Stmt; |
| 4 |
|
| 5 |
use PhpParser\Node; |
| 6 |
use PhpParser\Node\ComplexType; |
| 7 |
use PhpParser\Node\Identifier; |
| 8 |
use PhpParser\Node\Name; |
| 9 |
|
| 10 |
class Property extends Node\Stmt |
| 11 |
{ |
| 12 |
/** @var int Modifiers */ |
| 13 |
public $flags; |
| 14 |
/** @var PropertyProperty[] Properties */ |
| 15 |
public $props; |
| 16 |
/** @var null|Identifier|Name|ComplexType Type declaration */ |
| 17 |
public $type; |
| 18 |
/** @var Node\AttributeGroup[] PHP attribute groups */ |
| 19 |
public $attrGroups; |
| 20 |
|
| 21 |
/** |
| 22 |
* Constructs a class property list node. |
| 23 |
* |
| 24 |
* @param int $flags Modifiers |
| 25 |
* @param PropertyProperty[] $props Properties |
| 26 |
* @param array $attributes Additional attributes |
| 27 |
* @param null|string|Identifier|Name|ComplexType $type Type declaration |
| 28 |
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups |
| 29 |
*/ |
| 30 |
public function __construct(int $flags, array $props, array $attributes = [], $type = null, array $attrGroups = []) { |
| 31 |
$this->attributes = $attributes; |
| 32 |
$this->flags = $flags; |
| 33 |
$this->props = $props; |
| 34 |
$this->type = \is_string($type) ? new Identifier($type) : $type; |
| 35 |
$this->attrGroups = $attrGroups; |
| 36 |
} |
| 37 |
|
| 38 |
public function getSubNodeNames() : array { |
| 39 |
return ['attrGroups', 'flags', 'type', 'props']; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Whether the property is explicitly or implicitly public. |
| 44 |
* |
| 45 |
* @return bool |
| 46 |
*/ |
| 47 |
public function isPublic() : bool { |
| 48 |
return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 |
| 49 |
|| ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Whether the property is protected. |
| 54 |
* |
| 55 |
* @return bool |
| 56 |
*/ |
| 57 |
public function isProtected() : bool { |
| 58 |
return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Whether the property is private. |
| 63 |
* |
| 64 |
* @return bool |
| 65 |
*/ |
| 66 |
public function isPrivate() : bool { |
| 67 |
return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Whether the property is static. |
| 72 |
* |
| 73 |
* @return bool |
| 74 |
*/ |
| 75 |
public function isStatic() : bool { |
| 76 |
return (bool) ($this->flags & Class_::MODIFIER_STATIC); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Whether the property is readonly. |
| 81 |
* |
| 82 |
* @return bool |
| 83 |
*/ |
| 84 |
public function isReadonly() : bool { |
| 85 |
return (bool) ($this->flags & Class_::MODIFIER_READONLY); |
| 86 |
} |
| 87 |
|
| 88 |
public function getType() : string { |
| 89 |
return 'Stmt_Property'; |
| 90 |
} |
| 91 |
} |
| 92 |
|