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 | /** @var array Class methods */ |
||
42 | protected $methods; |
||
43 | |||
44 | /** |
||
45 | * ClassGenerator constructor. |
||
46 | * |
||
47 | * @param string $className Class name |
||
48 | * @param GenericGenerator $parent Parent generator |
||
49 | */ |
||
50 | public function __construct(string $className, GenericGenerator $parent = null) |
||
56 | |||
57 | /** |
||
58 | * Set class file description. |
||
59 | * |
||
60 | * @param array $description Collection of class file description lines |
||
61 | * |
||
62 | * @return ClassGenerator |
||
63 | */ |
||
64 | public function defDescription(array $description) : ClassGenerator |
||
75 | |||
76 | /** |
||
77 | * Set class namespace. |
||
78 | * |
||
79 | * @param string $namespace |
||
80 | * |
||
81 | * @return ClassGenerator |
||
82 | */ |
||
83 | public function defNamespace(string $namespace) : ClassGenerator |
||
89 | |||
90 | /** |
||
91 | * Set class use. |
||
92 | * |
||
93 | * @param string $use Use class name |
||
94 | * |
||
95 | * @return ClassGenerator |
||
96 | */ |
||
97 | public function defUse(string $use) : ClassGenerator |
||
103 | |||
104 | /** |
||
105 | * Set class trait use. |
||
106 | * |
||
107 | * @param string $trait Trait class name |
||
108 | * |
||
109 | * @return ClassGenerator |
||
110 | */ |
||
111 | public function defTrait(string $trait) : ClassGenerator |
||
117 | |||
118 | /** |
||
119 | * Set protected class property. |
||
120 | * |
||
121 | * @param string $name Property name |
||
122 | * @param string $type Property type |
||
123 | * @param mixed $value Property value |
||
124 | * @param string $description Property description |
||
125 | * |
||
126 | * @return PropertyGenerator |
||
127 | */ |
||
128 | public function defProtectedProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
132 | |||
133 | /** |
||
134 | * Set class property. |
||
135 | * |
||
136 | * @param string $name Property name |
||
137 | * @param string $type Property type |
||
138 | * @param mixed $value Property value |
||
139 | * @param string $description Property description |
||
140 | * |
||
141 | * @return PropertyGenerator |
||
142 | */ |
||
143 | public function defProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
151 | |||
152 | /** |
||
153 | * Set protected static class property. |
||
154 | * |
||
155 | * @param string $name Property name |
||
156 | * @param string $type Property type |
||
157 | * @param mixed $value Property value |
||
158 | * @param string $description Property description |
||
159 | * |
||
160 | * @return PropertyGenerator |
||
161 | */ |
||
162 | public function defProtectedStaticProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
166 | |||
167 | /** |
||
168 | * Set static class property. |
||
169 | * |
||
170 | * @param string $name Property name |
||
171 | * @param string $type Property type |
||
172 | * @param mixed $value Property value |
||
173 | * @param string $description Property description |
||
174 | * |
||
175 | * @return PropertyGenerator |
||
176 | */ |
||
177 | public function defStaticProperty(string $name, string $type, $value, string $description = null) : PropertyGenerator |
||
181 | |||
182 | /** |
||
183 | * Set protected class method. |
||
184 | * |
||
185 | * @param string $name Method name |
||
186 | * |
||
187 | * @return MethodGenerator |
||
188 | */ |
||
189 | public function defProtectedMethod(string $name) : MethodGenerator |
||
193 | |||
194 | /** |
||
195 | * Set public class method. |
||
196 | * |
||
197 | * @param string $name Method name |
||
198 | * |
||
199 | * @return MethodGenerator |
||
200 | */ |
||
201 | public function defMethod(string $name) : MethodGenerator |
||
205 | |||
206 | /** |
||
207 | * Set protected static class method. |
||
208 | * |
||
209 | * @param string $name Method name |
||
210 | * |
||
211 | * @return MethodGenerator |
||
212 | */ |
||
213 | public function defProtectedStaticMethod(string $name) : MethodGenerator |
||
217 | |||
218 | /** |
||
219 | * Set public static class method. |
||
220 | * |
||
221 | * @param string $name Method name |
||
222 | * |
||
223 | * @return MethodGenerator |
||
224 | */ |
||
225 | public function defStaticMethod(string $name) : MethodGenerator |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | * @throws \InvalidArgumentException |
||
233 | */ |
||
234 | public function code(int $indentation = 0) : string |
||
298 | |||
299 | /** |
||
300 | * Build function definition. |
||
301 | * |
||
302 | * @return string Function definition |
||
303 | */ |
||
304 | protected function buildDefinition() |
||
311 | } |
||
312 |