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