/
Property.php
185 lines (143 loc) 路 2.83 KB
/
Property.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
namespace Nette\PhpGenerator;
use Nette;
/**
* Class property description.
*/
class Property extends Nette\Object
{
/** @var string */
private $name = '';
/** @var mixed */
public $value;
/** @var bool */
private $static = FALSE;
/** @var string public|protected|private */
private $visibility = 'public';
/** @var string|NULL */
private $comment;
/**
* @return self
*/
public static function from(\ReflectionProperty $from)
{
$prop = new static;
$prop->name = $from->getName();
$defaults = $from->getDeclaringClass()->getDefaultProperties();
$prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
$prop->static = $from->isStatic();
$prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
$prop->comment = $from->getDocComment() ? preg_replace('#^\s*\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
return $prop;
}
/**
* @param string without $
* @return self
*/
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return self
*/
public function setValue($val)
{
$this->value = $val;
return $this;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* @param bool
* @return self
*/
public function setStatic($state = TRUE)
{
$this->static = (bool) $state;
return $this;
}
/**
* @return bool
*/
public function isStatic()
{
return $this->static;
}
/**
* @param string public|protected|private
* @return self
*/
public function setVisibility($val)
{
if (!in_array($val, ['public', 'protected', 'private'], TRUE)) {
throw new Nette\InvalidArgumentException('Argument must be public|protected|private.');
}
$this->visibility = (string) $val;
return $this;
}
/**
* @return string
*/
public function getVisibility()
{
return $this->visibility;
}
/**
* @param string|NULL
* @return self
*/
public function setComment($val)
{
$this->comment = $val ? (string) $val : NULL;
return $this;
}
/**
* @return string|NULL
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string
* @return self
*/
public function addComment($val)
{
$this->comment .= $this->comment ? "\n$val" : $val;
return $this;
}
/** @deprecated */
public function setDocuments(array $s)
{
return $this->setComment(implode("\n", $s));
}
/** @deprecated */
public function getDocuments()
{
return $this->comment ? [$this->comment] : [];
}
/** @deprecated */
public function addDocument($s)
{
return $this->addComment($s);
}
}