@@ -30,13 +30,14 @@ private function __construct(
3030 private bool $ isFinal = true ,
3131 private string $ rootNamespace = 'App ' ,
3232 private ?string $ classSuffix = null ,
33+ public readonly ?string $ implements = null ,
3334 ) {
3435 if (str_starts_with (haystack: $ this ->namespace , needle: $ this ->rootNamespace )) {
3536 $ this ->namespace = substr_replace (string: $ this ->namespace , replace: '' , offset: 0 , length: \strlen ($ this ->rootNamespace ) + 1 );
3637 }
3738 }
3839
39- public static function create (string $ class , ?string $ suffix = null , ?string $ extendsClass = null , bool $ isEntity = false , array $ useStatements = []): self
40+ public static function create (string $ class , ?string $ suffix = null , ?string $ extendsClass = null , bool $ isEntity = false , array $ useStatements = [], ? string $ implements = null ): self
4041 {
4142 $ className = Str::getShortClassName ($ class );
4243
@@ -50,13 +51,18 @@ public static function create(string $class, ?string $suffix = null, ?string $ex
5051 $ useStatements ->addUseStatement ($ extendsClass );
5152 }
5253
54+ if ($ implements ) {
55+ $ useStatements ->addUseStatement ($ implements );
56+ }
57+
5358 return new self (
5459 className: Str::asClassName ($ className ),
5560 namespace: Str::getNamespace ($ class ),
5661 extends: null === $ extendsClass ? null : Str::getShortClassName ($ extendsClass ),
5762 isEntity: $ isEntity ,
5863 useStatementGenerator: $ useStatements ,
5964 classSuffix: $ suffix ,
65+ implements: null === $ implements ? null : Str::getShortClassName ($ implements ),
6066 );
6167 }
6268
@@ -130,10 +136,17 @@ public function getClassDeclaration(): string
130136 $ extendsDeclaration = \sprintf (' extends %s ' , $ this ->extends );
131137 }
132138
139+ $ implementsDeclaration = '' ;
140+
141+ if (null !== $ this ->implements ) {
142+ $ implementsDeclaration = \sprintf (' implements %s ' , $ this ->implements );
143+ }
144+
133145 return \sprintf ('%sclass %s%s ' ,
134146 $ this ->isFinal ? 'final ' : '' ,
135147 $ this ->className ,
136148 $ extendsDeclaration ,
149+ $ implementsDeclaration
137150 );
138151 }
139152
0 commit comments