| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Dependencies\PhpParser\Builder; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser; |
| 6 |
use WPDeveloper\BetterDocs\Dependencies\PhpParser\Node\Stmt; |
| 7 |
|
| 8 |
class Property extends WPDeveloper\BetterDocs\Dependencies\PhpParser\BuilderAbstract |
| 9 |
{ |
| 10 |
protected $name; |
| 11 |
|
| 12 |
protected $flags = 0; |
| 13 |
protected $default = null; |
| 14 |
protected $attributes = array(); |
| 15 |
|
| 16 |
/** |
| 17 |
* Creates a property builder. |
| 18 |
* |
| 19 |
* @param string $name Name of the property |
| 20 |
*/ |
| 21 |
public function __construct($name) { |
| 22 |
$this->name = $name; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Makes the property public. |
| 27 |
* |
| 28 |
* @return $this The builder instance (for fluid interface) |
| 29 |
*/ |
| 30 |
public function makePublic() { |
| 31 |
$this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); |
| 32 |
|
| 33 |
return $this; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Makes the property protected. |
| 38 |
* |
| 39 |
* @return $this The builder instance (for fluid interface) |
| 40 |
*/ |
| 41 |
public function makeProtected() { |
| 42 |
$this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); |
| 43 |
|
| 44 |
return $this; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Makes the property private. |
| 49 |
* |
| 50 |
* @return $this The builder instance (for fluid interface) |
| 51 |
*/ |
| 52 |
public function makePrivate() { |
| 53 |
$this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); |
| 54 |
|
| 55 |
return $this; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Makes the property static. |
| 60 |
* |
| 61 |
* @return $this The builder instance (for fluid interface) |
| 62 |
*/ |
| 63 |
public function makeStatic() { |
| 64 |
$this->setModifier(Stmt\Class_::MODIFIER_STATIC); |
| 65 |
|
| 66 |
return $this; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Sets default value for the property. |
| 71 |
* |
| 72 |
* @param mixed $value Default value to use |
| 73 |
* |
| 74 |
* @return $this The builder instance (for fluid interface) |
| 75 |
*/ |
| 76 |
public function setDefault($value) { |
| 77 |
$this->default = $this->normalizeValue($value); |
| 78 |
|
| 79 |
return $this; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Sets doc comment for the property. |
| 84 |
* |
| 85 |
* @param WPDeveloper\BetterDocs\Dependencies\PhpParser\Comment\Doc|string $docComment Doc comment to set |
| 86 |
* |
| 87 |
* @return $this The builder instance (for fluid interface) |
| 88 |
*/ |
| 89 |
public function setDocComment($docComment) { |
| 90 |
$this->attributes = array( |
| 91 |
'comments' => array($this->normalizeDocComment($docComment)) |
| 92 |
); |
| 93 |
|
| 94 |
return $this; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Returns the built class node. |
| 99 |
* |
| 100 |
* @return Stmt\Property The built property node |
| 101 |
*/ |
| 102 |
public function getNode() { |
| 103 |
return new Stmt\Property( |
| 104 |
$this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC, |
| 105 |
array( |
| 106 |
new Stmt\PropertyProperty($this->name, $this->default) |
| 107 |
), |
| 108 |
$this->attributes |
| 109 |
); |
| 110 |
} |
| 111 |
} |