1 | <?php declare(strict_types = 1); |
||
13 | class ClassGenerator extends AbstractGenerator |
||
14 | { |
||
15 | use AbstractFinalTrait; |
||
16 | |||
17 | /** OOP public visibility */ |
||
18 | const VISIBILITY_PUBLIC = 'public'; |
||
19 | |||
20 | /** OOP protected visibility */ |
||
21 | const VISIBILITY_PROTECTED = 'protected'; |
||
22 | |||
23 | /** OOP private visibility */ |
||
24 | const VISIBILITY_PRIVATE = 'private'; |
||
25 | |||
26 | /** @var string Class name */ |
||
27 | protected $className; |
||
28 | |||
29 | /** @var string Class namespace */ |
||
30 | protected $namespace; |
||
31 | |||
32 | /** @var array Collection of class uses */ |
||
33 | protected $uses = []; |
||
34 | |||
35 | /** @var array Collection of class used traits */ |
||
36 | protected $traits = []; |
||
37 | |||
38 | /** @var string Multi-line file description */ |
||
39 | protected $fileDescription; |
||
40 | |||
41 | /** |
||
42 | * ClassGenerator constructor. |
||
43 | * |
||
44 | * @param string $className Class name |
||
45 | * @param AbstractGenerator $parent Parent generator |
||
46 | */ |
||
47 | public function __construct(string $className, AbstractGenerator $parent = null) |
||
53 | |||
54 | /** |
||
55 | * Set class file description. |
||
56 | * |
||
57 | * @param array $description Collection of class file description lines |
||
58 | * |
||
59 | * @return ClassGenerator |
||
60 | */ |
||
61 | public function defDescription(array $description) : ClassGenerator |
||
72 | |||
73 | /** |
||
74 | * Set class namespace. |
||
75 | * |
||
76 | * @param string $namespace |
||
77 | * |
||
78 | * @return ClassGenerator |
||
79 | */ |
||
80 | public function defNamespace(string $namespace) : ClassGenerator |
||
86 | |||
87 | /** |
||
88 | * Set class use. |
||
89 | * |
||
90 | * @param string $use Use class name |
||
91 | * |
||
92 | * @return ClassGenerator |
||
93 | */ |
||
94 | public function defUse(string $use) : ClassGenerator |
||
100 | |||
101 | /** |
||
102 | * Set class trait use. |
||
103 | * |
||
104 | * @param string $trait Trait class name |
||
105 | * |
||
106 | * @return ClassGenerator |
||
107 | */ |
||
108 | public function defTrait(string $trait) : ClassGenerator |
||
114 | |||
115 | /** |
||
116 | * Set protected class property. |
||
117 | * |
||
118 | * @param string $name Property name |
||
119 | * @param string $type Property type |
||
120 | * @param mixed $value Property value |
||
121 | * @param string $description Property description |
||
122 | * |
||
123 | * @return PropertyGenerator |
||
124 | */ |
||
125 | public function defProtectedProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
129 | |||
130 | /** |
||
131 | * Set class property. |
||
132 | * |
||
133 | * @param string $name Property name |
||
134 | * @param string $type Property type |
||
135 | * @param mixed $value Property value |
||
136 | * @param string $description Property description |
||
137 | * |
||
138 | * @return PropertyGenerator |
||
139 | */ |
||
140 | public function defProperty(string $name, string $type, $value = null, string $description = null) : PropertyGenerator |
||
149 | |||
150 | /** |
||
151 | * Set protected static class property. |
||
152 | * |
||
153 | * @param string $name Property name |
||
154 | * @param string $type Property type |
||
155 | * @param mixed $value Property value |
||
156 | * @param string $description Property description |
||
157 | * |
||
158 | * @return PropertyGenerator |
||
159 | */ |
||
160 | public function defProtectedStaticProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
164 | |||
165 | /** |
||
166 | * Set static class property. |
||
167 | * |
||
168 | * @param string $name Property name |
||
169 | * @param string $type Property type |
||
170 | * @param mixed $value Property value |
||
171 | * @param string $description Property description |
||
172 | * |
||
173 | * @return PropertyGenerator |
||
174 | */ |
||
175 | public function defStaticProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
179 | |||
180 | /** |
||
181 | * Set protected class method. |
||
182 | * |
||
183 | * @param string $name Method name |
||
184 | * |
||
185 | * @return MethodGenerator |
||
186 | */ |
||
187 | public function defProtectedMethod(string $name) : MethodGenerator |
||
191 | |||
192 | /** |
||
193 | * Set public class method. |
||
194 | * |
||
195 | * @param string $name Method name |
||
196 | * |
||
197 | * @return MethodGenerator |
||
198 | */ |
||
199 | public function defMethod(string $name) : MethodGenerator |
||
203 | |||
204 | /** |
||
205 | * Set protected static class method. |
||
206 | * |
||
207 | * @param string $name Method name |
||
208 | * |
||
209 | * @return MethodGenerator |
||
210 | */ |
||
211 | public function defProtectedStaticMethod(string $name) : MethodGenerator |
||
215 | |||
216 | /** |
||
217 | * Set public static class method. |
||
218 | * |
||
219 | * @param string $name Method name |
||
220 | * |
||
221 | * @return MethodGenerator |
||
222 | */ |
||
223 | public function defStaticMethod(string $name) : MethodGenerator |
||
227 | |||
228 | /** |
||
229 | * Set class constant. |
||
230 | * |
||
231 | * @param string $name |
||
232 | * @param mixed $value |
||
233 | * |
||
234 | * @return $this|ClassConstantGenerator |
||
235 | */ |
||
236 | public function defConstant(string $name, $value, string $type, string $description) : ClassConstantGenerator |
||
245 | |||
246 | protected function buildUsesCode(array $formattedCode) : array |
||
260 | |||
261 | protected function buildCommentsCode(array $formattedCode) : array |
||
270 | |||
271 | protected function buildTraitsCode(array $formattedCode, string $innerIndentation) : array |
||
285 | |||
286 | protected function buildFileDescriptionCode(array $formattedCode) : array |
||
295 | |||
296 | protected function buildConstantsCode(array $formattedCode) : array |
||
305 | |||
306 | protected function buildPropertiesCode(array $formattedCode) : array |
||
314 | |||
315 | protected function buildMethodsCode(array $formattedCode) : array |
||
323 | |||
324 | protected function buildNamespaceCode(array $formattedCode = []) : array |
||
337 | |||
338 | /** |
||
339 | * {@inheritdoc} |
||
340 | * @throws \InvalidArgumentException |
||
341 | */ |
||
342 | public function code(int $indentation = 0) : string |
||
365 | |||
366 | /** |
||
367 | * Build class definition. |
||
368 | * |
||
369 | * @return string Function definition |
||
370 | */ |
||
371 | protected function buildDefinition() |
||
378 | } |
||
379 |