@@ -231,9 +231,10 @@ public function isAbstract()
231
231
*/
232
232
public function setExtends ($ names )
233
233
{
234
- if (!is_string ($ names ) && !( is_array ($ names) && Nette \ Utils \Arrays:: every ( $ names , ' is_string ' ) )) {
234
+ if (!is_string ($ names ) && !is_array ($ names )) {
235
235
throw new Nette \InvalidArgumentException ('Argument must be string or string[]. ' );
236
236
}
237
+ $ this ->validate ((array ) $ names );
237
238
$ this ->extends = $ names ;
238
239
return $ this ;
239
240
}
@@ -254,8 +255,9 @@ public function getExtends()
254
255
*/
255
256
public function addExtend ($ name )
256
257
{
258
+ $ this ->validate ([$ name ]);
257
259
$ this ->extends = (array ) $ this ->extends ;
258
- $ this ->extends [] = ( string ) $ name ;
260
+ $ this ->extends [] = $ name ;
259
261
return $ this ;
260
262
}
261
263
@@ -266,6 +268,7 @@ public function addExtend($name)
266
268
*/
267
269
public function setImplements (array $ names )
268
270
{
271
+ $ this ->validate ($ names );
269
272
$ this ->implements = $ names ;
270
273
return $ this ;
271
274
}
@@ -286,7 +289,8 @@ public function getImplements()
286
289
*/
287
290
public function addImplement ($ name )
288
291
{
289
- $ this ->implements [] = (string ) $ name ;
292
+ $ this ->validate ([$ name ]);
293
+ $ this ->implements [] = $ name ;
290
294
return $ this ;
291
295
}
292
296
@@ -297,6 +301,7 @@ public function addImplement($name)
297
301
*/
298
302
public function setTraits (array $ names )
299
303
{
304
+ $ this ->validate ($ names );
300
305
$ this ->traits = array_fill_keys ($ names , []);
301
306
return $ this ;
302
307
}
@@ -317,6 +322,7 @@ public function getTraits()
317
322
*/
318
323
public function addTrait ($ name , array $ resolutions = [])
319
324
{
325
+ $ this ->validate ([$ name ]);
320
326
$ this ->traits [$ name ] = $ resolutions ;
321
327
return $ this ;
322
328
}
@@ -492,4 +498,14 @@ public function addMethod($name)
492
498
return $ this ->methods [$ name ] = $ method ;
493
499
}
494
500
501
+
502
+ private function validate (array $ names )
503
+ {
504
+ foreach ($ names as $ name ) {
505
+ if (!Helpers::isNamespaceIdentifier ($ name , TRUE )) {
506
+ throw new Nette \InvalidArgumentException ("Value ' $ name' is not valid class name. " );
507
+ }
508
+ }
509
+ }
510
+
495
511
}
0 commit comments