1 | <?php |
||
17 | class ClassDefinition extends ParentDefinition |
||
18 | { |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $type; |
||
23 | |||
24 | /** |
||
25 | * Class methods |
||
26 | * |
||
27 | * @var ClassMethod[] |
||
28 | */ |
||
29 | protected $methods = array(); |
||
30 | |||
31 | /** |
||
32 | * Class properties |
||
33 | * |
||
34 | * @var Node\Stmt\Property[] |
||
35 | */ |
||
36 | protected $properties = array(); |
||
37 | |||
38 | /** |
||
39 | * Class constants |
||
40 | * |
||
41 | * @var Node\Stmt\Const_[] |
||
42 | */ |
||
43 | protected $constants = array(); |
||
44 | |||
45 | /** |
||
46 | * @todo Use Finder |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $filepath; |
||
51 | |||
52 | /** |
||
53 | * @var string|null |
||
54 | */ |
||
55 | protected $extendsClass; |
||
56 | |||
57 | /** |
||
58 | * @var ClassDefinition|null |
||
59 | */ |
||
60 | protected $extendsClassDefinition; |
||
|
|||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $interfaces = array(); |
||
66 | |||
67 | /** |
||
68 | * @param string $name |
||
69 | * @param integer $type |
||
70 | */ |
||
71 | 370 | public function __construct($name, $type) |
|
76 | |||
77 | /** |
||
78 | * @param ClassMethod $methodDefintion |
||
79 | */ |
||
80 | 1 | public function addMethod(ClassMethod $methodDefintion) |
|
84 | |||
85 | /** |
||
86 | * @param Node\Stmt\Property $property |
||
87 | */ |
||
88 | 1 | public function addProperty(Node\Stmt\Property $property) |
|
92 | |||
93 | /** |
||
94 | * @param Node\Stmt\ClassConst $const |
||
95 | */ |
||
96 | public function addConst(Node\Stmt\ClassConst $const) |
||
100 | |||
101 | /** |
||
102 | * @param Context $context |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function compile(Context $context) |
||
145 | |||
146 | /** |
||
147 | * @param string $name |
||
148 | * @param boolean|false $inherit |
||
149 | * @return bool |
||
150 | */ |
||
151 | 1 | public function hasMethod($name, $inherit = false) |
|
152 | { |
||
153 | 1 | if (isset($this->methods[$name])) { |
|
154 | 1 | return true; |
|
155 | } |
||
156 | |||
157 | 1 | if ($inherit && $this->extendsClassDefinition && $this->extendsClassDefinition->hasMethod($name, true)) { |
|
158 | $method = $this->extendsClassDefinition->getMethod($name); |
||
159 | return $method && ($method->isPublic() || $method->isProtected()); |
||
160 | } |
||
161 | |||
162 | 1 | return false; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * @param $name |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function hasConst($name) |
||
173 | |||
174 | /** |
||
175 | * @param $name |
||
176 | * @param boolean|false $inherit |
||
177 | * @return ClassMethod|null |
||
178 | */ |
||
179 | 1 | public function getMethod($name, $inherit = false) |
|
191 | |||
192 | /** |
||
193 | * @param $name |
||
194 | * @param bool $inherit |
||
195 | * @return bool |
||
196 | */ |
||
197 | 1 | public function hasProperty($name, $inherit = false) |
|
205 | |||
206 | /** |
||
207 | * @param $name |
||
208 | * @param bool $inherit |
||
209 | * @return Node\Stmt\Property |
||
210 | */ |
||
211 | public function getProperty($name, $inherit = false) |
||
221 | |||
222 | /** |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getFilepath() |
||
229 | |||
230 | /** |
||
231 | * @param string $filepath |
||
232 | */ |
||
233 | public function setFilepath($filepath) |
||
237 | |||
238 | /** |
||
239 | * @return bool |
||
240 | */ |
||
241 | public function isAbstract() |
||
245 | |||
246 | /** |
||
247 | * @param null|string $extendsClass |
||
248 | */ |
||
249 | public function setExtendsClass($extendsClass) |
||
253 | |||
254 | /** |
||
255 | * @return null|ClassDefinition |
||
256 | */ |
||
257 | public function getExtendsClassDefinition() |
||
261 | |||
262 | /** |
||
263 | * @param ClassDefinition $extendsClassDefinition |
||
264 | */ |
||
265 | public function setExtendsClassDefinition(ClassDefinition $extendsClassDefinition) |
||
269 | |||
270 | /** |
||
271 | * @param array $interface |
||
272 | */ |
||
273 | public function addInterface($interface) |
||
277 | |||
278 | /** |
||
279 | * @return null|string |
||
280 | */ |
||
281 | public function getExtendsClass() |
||
285 | } |
||
286 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.