@@ -89,6 +89,12 @@ public function __construct($name = NULL, PhpNamespace $namespace = NULL)
8989 */
9090 public function __toString ()
9191 {
92+ $ traits = [];
93+ foreach ($ this ->traits as $ trait => $ resolutions ) {
94+ $ traits [] = 'use ' . ($ this ->namespace ? $ this ->namespace ->unresolveName ($ trait ) : $ trait )
95+ . ($ resolutions ? " { \n\t" . implode ("; \n\t" , $ resolutions ) . "; \n} " : '; ' );
96+ }
97+
9298 $ consts = [];
9399 foreach ($ this ->consts as $ const ) {
94100 $ consts [] = Helpers::formatDocComment ($ const ->getComment ())
@@ -117,7 +123,7 @@ public function __toString()
117123 . ($ this ->implements ? 'implements ' . implode (', ' , $ mapper ($ this ->implements )) . ' ' : '' )
118124 . ($ this ->name ? "\n" : '' ) . "{ \n"
119125 . Strings::indent (
120- ($ this ->traits ? ' use ' . implode ("; \n use " , $ mapper ( $ this -> traits )) . "; \n\n" : '' )
126+ ($ this ->traits ? implode ("\n " , $ traits ) . "\n\n" : '' )
121127 . ($ this ->consts ? implode ('' , $ consts ) . "\n" : '' )
122128 . ($ this ->properties ? implode ("\n" , $ properties ) . "\n" : '' )
123129 . ($ this ->methods ? "\n" . implode ("\n\n\n" , $ this ->methods ) . "\n\n" : '' ), 1 )
@@ -293,7 +299,7 @@ public function addImplement($type)
293299 */
294300 public function setTraits (array $ traits )
295301 {
296- $ this ->traits = $ traits ;
302+ $ this ->traits = array_fill_keys ( $ traits, []) ;
297303 return $ this ;
298304 }
299305
@@ -303,17 +309,17 @@ public function setTraits(array $traits)
303309 */
304310 public function getTraits ()
305311 {
306- return $ this ->traits ;
312+ return array_keys ( $ this ->traits ) ;
307313 }
308314
309315
310316 /**
311317 * @param string
312318 * @return static
313319 */
314- public function addTrait ($ trait )
320+ public function addTrait ($ trait, array $ resolutions = [] )
315321 {
316- $ this ->traits [] = ( string ) $ trait ;
322+ $ this ->traits [$ trait ] = $ resolutions ;
317323 return $ this ;
318324 }
319325
0 commit comments