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