@@ -89,6 +89,12 @@ public function __construct($name = NULL, PhpNamespace $namespace = NULL)
89
89
*/
90
90
public function __toString ()
91
91
{
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
+
92
98
$ consts = [];
93
99
foreach ($ this ->consts as $ const ) {
94
100
$ consts [] = Helpers::formatDocComment ($ const ->getComment ())
@@ -117,7 +123,7 @@ public function __toString()
117
123
. ($ this ->implements ? 'implements ' . implode (', ' , $ mapper ($ this ->implements )) . ' ' : '' )
118
124
. ($ this ->name ? "\n" : '' ) . "{ \n"
119
125
. Strings::indent (
120
- ($ this ->traits ? ' use ' . implode ("; \n use " , $ mapper ( $ this -> traits )) . "; \n\n" : '' )
126
+ ($ this ->traits ? implode ("\n " , $ traits ) . "\n\n" : '' )
121
127
. ($ this ->consts ? implode ('' , $ consts ) . "\n" : '' )
122
128
. ($ this ->properties ? implode ("\n" , $ properties ) . "\n" : '' )
123
129
. ($ this ->methods ? "\n" . implode ("\n\n\n" , $ this ->methods ) . "\n\n" : '' ), 1 )
@@ -293,7 +299,7 @@ public function addImplement($type)
293
299
*/
294
300
public function setTraits (array $ traits )
295
301
{
296
- $ this ->traits = $ traits ;
302
+ $ this ->traits = array_fill_keys ( $ traits, []) ;
297
303
return $ this ;
298
304
}
299
305
@@ -303,17 +309,17 @@ public function setTraits(array $traits)
303
309
*/
304
310
public function getTraits ()
305
311
{
306
- return $ this ->traits ;
312
+ return array_keys ( $ this ->traits ) ;
307
313
}
308
314
309
315
310
316
/**
311
317
* @param string
312
318
* @return static
313
319
*/
314
- public function addTrait ($ trait )
320
+ public function addTrait ($ trait, array $ resolutions = [] )
315
321
{
316
- $ this ->traits [] = ( string ) $ trait ;
322
+ $ this ->traits [$ trait ] = $ resolutions ;
317
323
return $ this ;
318
324
}
319
325
0 commit comments