@@ -169,6 +169,39 @@ class Combinator extends CombinatorBase {
169
169
return last ;
170
170
}
171
171
172
+ addTypedefInclude ( typeName ) {
173
+ let accessPath = typeName . split ( '.' ) ;
174
+ let importName = '' ;
175
+ let fromName = '' ;
176
+ let typedefModule = { } ;
177
+ if ( accessPath . length === 2 ) {
178
+ if ( this . dependencies [ accessPath [ 0 ] ]
179
+ && this . dependencies [ accessPath [ 0 ] ] . typedef
180
+ && this . dependencies [ accessPath [ 0 ] ] . typedef [ accessPath [ 1 ] ] ) {
181
+ typedefModule = this . dependencies [ accessPath [ 0 ] ] . typedef [ accessPath [ 1 ] ] ;
182
+ }
183
+ } else if ( accessPath . length === 1 && this . typedef [ accessPath [ 0 ] ] ) {
184
+ typedefModule = this . typedef [ accessPath [ 0 ] ] ;
185
+ }
186
+ if ( typedefModule . import || typedefModule . package ) {
187
+ if ( typedefModule . import ) {
188
+ fromName = typedefModule . import ;
189
+ }
190
+ if ( typedefModule . type ) {
191
+ importName = typedefModule . type ;
192
+ }
193
+ }
194
+
195
+ let existResult = this . includeList . some ( item => item . import === importName && item . from === fromName ) ;
196
+ if ( ! existResult ) {
197
+ this . includeList . push ( {
198
+ import : fromName && importName ? `${ fromName } \\${ importName } ` : fromName ? fromName : importName ? importName : null ,
199
+ alias : null ,
200
+ } ) ;
201
+ }
202
+ return typedefModule . type || typeName ;
203
+ }
204
+
172
205
combine ( objectArr = [ ] ) {
173
206
if ( this . config . packageInfo ) {
174
207
const packageInfo = new PackageInfo ( this . config , this . dependencies ) ;
@@ -466,7 +499,11 @@ class Combinator extends CombinatorBase {
466
499
} else if ( prop . type instanceof TypeBase || prop . type instanceof TypeBytes || prop . type instanceof TypeStream ) {
467
500
emitter . emitln ( `$res['${ name } '] = $this->${ prop . name } ;` , this . level ) ;
468
501
} else {
469
- emitter . emitln ( `$res['${ name } '] = null !== $this->${ prop . name } ? $this->${ prop . name } ->toMap() : null;` , this . level ) ;
502
+ if ( prop . type . objectName . indexOf ( '%' ) === 0 ) {
503
+ emitter . emitln ( `$res['${ name } '] = $this->${ prop . name } ;` , this . level ) ;
504
+ } else {
505
+ emitter . emitln ( `$res['${ name } '] = null !== $this->${ prop . name } ? $this->${ prop . name } ->toMap() : null;` , this . level ) ;
506
+ }
470
507
}
471
508
this . levelDown ( ) ;
472
509
emitter . emitln ( '}' , this . level ) ;
@@ -516,7 +553,7 @@ class Combinator extends CombinatorBase {
516
553
}
517
554
this . levelDown ( ) ;
518
555
emitter . emitln ( '}' , this . level ) ;
519
- } else if ( prop . type instanceof TypeObject ) {
556
+ } else if ( prop . type instanceof TypeObject && prop . type . objectName . indexOf ( '%' ) !== 0 ) {
520
557
emitter . emitln ( `$model->${ prop . name } = ${ this . resolveName ( prop . type . objectName ) } ::fromMap(${ mapVal } );` , this . level ) ;
521
558
} else {
522
559
emitter . emitln ( `$model->${ prop . name } = ${ mapVal } ;` , this . level ) ;
@@ -724,24 +761,28 @@ class Combinator extends CombinatorBase {
724
761
let importClass ;
725
762
if ( include . import === this . config . tea . exception . name ) {
726
763
importClass = include . import ;
727
- } else {
764
+ } else if ( include . import ) {
728
765
importClass = include . import . split ( '\\' ) . filter ( str => str . length > 0 ) . join ( '\\' ) ;
729
766
}
730
- let emitContent = include . alias ? `use ${ importClass } as ${ include . alias . split ( '->' ) . join ( '' ) } ;` : `use ${ importClass } ;` ;
731
- if ( emitSet . indexOf ( emitContent ) === - 1 ) {
732
- emitter . emitln ( emitContent ) ;
733
- emitSet . push ( emitContent ) ;
767
+ if ( importClass ) {
768
+ let emitContent = include . alias ? `use ${ importClass } as ${ include . alias . split ( '->' ) . join ( '' ) } ;` : `use ${ importClass } ;` ;
769
+ if ( emitSet . indexOf ( emitContent ) === - 1 ) {
770
+ emitter . emitln ( emitContent ) ;
771
+ emitSet . push ( emitContent ) ;
772
+ }
734
773
}
735
774
} ) ;
736
775
if ( this . includeList . length ) {
737
776
emitter . emitln ( ) ;
738
777
}
739
778
this . includeModelList . forEach ( include => {
740
779
const importClass = include . import . split ( '\\' ) . filter ( str => str . length > 0 ) . join ( '\\' ) ;
741
- let emitContent = include . alias ? `use ${ importClass } as ${ include . alias } ;` : `use ${ importClass } ;` ;
742
- if ( emitSet . indexOf ( emitContent ) === - 1 ) {
743
- emitter . emitln ( emitContent ) ;
744
- emitSet . push ( emitContent ) ;
780
+ if ( importClass ) {
781
+ let emitContent = include . alias ? `use ${ importClass } as ${ include . alias } ;` : `use ${ importClass } ;` ;
782
+ if ( emitSet . indexOf ( emitContent ) === - 1 ) {
783
+ emitter . emitln ( emitContent ) ;
784
+ emitSet . push ( emitContent ) ;
785
+ }
745
786
}
746
787
} ) ;
747
788
if ( this . includeModelList . length ) {
0 commit comments