@@ -122,30 +122,14 @@ protected function generateModelDirectory(string $destination, string $classPath
122
122
*/
123
123
protected function renderClass (GeneratorConfiguration $ generatorConfiguration ): string
124
124
{
125
- $ render = new Render (__DIR__ . '/../Templates/ ' );
126
125
$ namespace = trim (join ('\\' , [$ generatorConfiguration ->getNamespacePrefix (), $ this ->classPath ]), '\\' );
127
126
128
- $ use = array_unique (
129
- array_merge (
130
- $ this ->schema ->getUsedClasses (),
131
- $ generatorConfiguration ->collectErrors ()
132
- ? [$ generatorConfiguration ->getErrorRegistryClass ()]
133
- : [ValidationException::class]
134
- )
135
- );
136
-
137
- // filter out non-compound uses and uses which link to the current namespace
138
- $ use = array_filter ($ use , function ($ classPath ) use ($ namespace ) {
139
- return strstr (trim (str_replace ("$ namespace " , '' , $ classPath ), '\\' ), '\\' ) ||
140
- (!strstr ($ classPath , '\\' ) && !empty ($ namespace ));
141
- });
142
-
143
127
try {
144
- $ class = $ render ->renderTemplate (
128
+ $ class = ( new Render ( __DIR__ . ' /../Templates/ ' )) ->renderTemplate (
145
129
'Model.phptpl ' ,
146
130
[
147
131
'namespace ' => $ namespace ,
148
- 'use ' => $ use ,
132
+ 'use ' => $ this -> getUseForSchema ( $ generatorConfiguration , $ namespace ) ,
149
133
'class ' => $ this ->className ,
150
134
'schema ' => $ this ->schema ,
151
135
'schemaHookResolver ' => new SchemaHookResolver ($ this ->schema ),
@@ -167,4 +151,30 @@ function ($validator) {
167
151
168
152
return $ class ;
169
153
}
170
- }
154
+
155
+ /**
156
+ * @param GeneratorConfiguration $generatorConfiguration
157
+ * @param string $namespace
158
+ *
159
+ * @return string[]
160
+ */
161
+ protected function getUseForSchema (GeneratorConfiguration $ generatorConfiguration , string $ namespace ): array
162
+ {
163
+ $ use = array_unique (
164
+ array_merge (
165
+ $ this ->schema ->getUsedClasses (),
166
+ $ generatorConfiguration ->collectErrors ()
167
+ ? [$ generatorConfiguration ->getErrorRegistryClass ()]
168
+ : [ValidationException::class]
169
+ )
170
+ );
171
+
172
+ // filter out non-compound uses and uses which link to the current namespace
173
+ $ use = array_filter ($ use , function ($ classPath ) use ($ namespace ) {
174
+ return strstr (trim (str_replace ("$ namespace " , '' , $ classPath ), '\\' ), '\\' ) ||
175
+ (!strstr ($ classPath , '\\' ) && !empty ($ namespace ));
176
+ });
177
+
178
+ return $ use ;
179
+ }
180
+ }
0 commit comments