@@ -231,9 +231,10 @@ public function isAbstract()
231231 */
232232 public function setExtends ($ names )
233233 {
234- if (!is_string ($ names ) && !( is_array ($ names) && Nette \ Utils \Arrays:: every ( $ names , ' is_string ' ) )) {
234+ if (!is_string ($ names ) && !is_array ($ names )) {
235235 throw new Nette \InvalidArgumentException ('Argument must be string or string[]. ' );
236236 }
237+ $ this ->validate ((array ) $ names );
237238 $ this ->extends = $ names ;
238239 return $ this ;
239240 }
@@ -254,8 +255,9 @@ public function getExtends()
254255 */
255256 public function addExtend ($ name )
256257 {
258+ $ this ->validate ([$ name ]);
257259 $ this ->extends = (array ) $ this ->extends ;
258- $ this ->extends [] = ( string ) $ name ;
260+ $ this ->extends [] = $ name ;
259261 return $ this ;
260262 }
261263
@@ -266,6 +268,7 @@ public function addExtend($name)
266268 */
267269 public function setImplements (array $ names )
268270 {
271+ $ this ->validate ($ names );
269272 $ this ->implements = $ names ;
270273 return $ this ;
271274 }
@@ -286,7 +289,8 @@ public function getImplements()
286289 */
287290 public function addImplement ($ name )
288291 {
289- $ this ->implements [] = (string ) $ name ;
292+ $ this ->validate ([$ name ]);
293+ $ this ->implements [] = $ name ;
290294 return $ this ;
291295 }
292296
@@ -297,6 +301,7 @@ public function addImplement($name)
297301 */
298302 public function setTraits (array $ names )
299303 {
304+ $ this ->validate ($ names );
300305 $ this ->traits = array_fill_keys ($ names , []);
301306 return $ this ;
302307 }
@@ -317,6 +322,7 @@ public function getTraits()
317322 */
318323 public function addTrait ($ name , array $ resolutions = [])
319324 {
325+ $ this ->validate ([$ name ]);
320326 $ this ->traits [$ name ] = $ resolutions ;
321327 return $ this ;
322328 }
@@ -492,4 +498,14 @@ public function addMethod($name)
492498 return $ this ->methods [$ name ] = $ method ;
493499 }
494500
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+
495511}
0 commit comments