@@ -218,9 +218,10 @@ public function isAbstract(): bool
218
218
*/
219
219
public function setExtends ($ names ): self
220
220
{
221
- if (!is_string ($ names ) && !( is_array ($ names) && Nette \ Utils \Arrays:: every ( $ names , ' is_string ' ) )) {
221
+ if (!is_string ($ names ) && !is_array ($ names )) {
222
222
throw new Nette \InvalidArgumentException ('Argument must be string or string[]. ' );
223
223
}
224
+ $ this ->validate ((array ) $ names );
224
225
$ this ->extends = $ names ;
225
226
return $ this ;
226
227
}
@@ -240,6 +241,7 @@ public function getExtends()
240
241
*/
241
242
public function addExtend (string $ name ): self
242
243
{
244
+ $ this ->validate ([$ name ]);
243
245
$ this ->extends = (array ) $ this ->extends ;
244
246
$ this ->extends [] = $ name ;
245
247
return $ this ;
@@ -252,6 +254,7 @@ public function addExtend(string $name): self
252
254
*/
253
255
public function setImplements (array $ names ): self
254
256
{
257
+ $ this ->validate ($ names );
255
258
$ this ->implements = $ names ;
256
259
return $ this ;
257
260
}
@@ -271,6 +274,7 @@ public function getImplements(): array
271
274
*/
272
275
public function addImplement (string $ name ): self
273
276
{
277
+ $ this ->validate ([$ name ]);
274
278
$ this ->implements [] = $ name ;
275
279
return $ this ;
276
280
}
@@ -282,6 +286,7 @@ public function addImplement(string $name): self
282
286
*/
283
287
public function setTraits (array $ names ): self
284
288
{
289
+ $ this ->validate ($ names );
285
290
$ this ->traits = array_fill_keys ($ names , []);
286
291
return $ this ;
287
292
}
@@ -301,6 +306,7 @@ public function getTraits(): array
301
306
*/
302
307
public function addTrait (string $ name , array $ resolutions = []): self
303
308
{
309
+ $ this ->validate ([$ name ]);
304
310
$ this ->traits [$ name ] = $ resolutions ;
305
311
return $ this ;
306
312
}
@@ -459,4 +465,14 @@ public function addMethod(string $name): Method
459
465
return $ this ->methods [$ name ] = $ method ;
460
466
}
461
467
468
+
469
+ private function validate (array $ names )
470
+ {
471
+ foreach ($ names as $ name ) {
472
+ if (!Helpers::isNamespaceIdentifier ($ name , TRUE )) {
473
+ throw new Nette \InvalidArgumentException ("Value ' $ name' is not valid class name. " );
474
+ }
475
+ }
476
+ }
477
+
462
478
}
0 commit comments