1212namespace Overblog \GraphQLBundle \Generator ;
1313
1414use Overblog \GraphQLGenerator \Generator \TypeGenerator as BaseTypeGenerator ;
15- use Symfony \Component \ClassLoader \ClassCollectionLoader ;
1615use Symfony \Component \ClassLoader \MapClassLoader ;
1716use Symfony \Component \Filesystem \Filesystem ;
1817
@@ -150,7 +149,7 @@ function ($childrenComplexity, $args = []) <closureUseStatements> {
150149 return $ code ;
151150 }
152151
153- public function compile (array $ configs )
152+ public function compile (array $ configs, $ loadClasses = true )
154153 {
155154 $ cacheDir = $ this ->getCacheDir ();
156155 if (file_exists ($ cacheDir )) {
@@ -159,16 +158,10 @@ public function compile(array $configs)
159158 }
160159
161160 $ classes = $ this ->generateClasses ($ configs , $ cacheDir , true );
161+ file_put_contents ($ this ->getClassesMap (), "<?php \nreturn " .var_export ($ classes , true ).'; ' );
162162
163- if (!empty ($ classes )) {
164- $ file = $ this ->getClassCollectionPath ();
165-
166- $ mapClassLoader = new MapClassLoader ($ classes );
167- $ mapClassLoader ->register ();
168-
169- ClassCollectionLoader::load (array_keys ($ classes ), dirname ($ file ), basename ($ file , '.php.cache ' ), false , false , '.php.cache ' );
170-
171- self ::$ classMapLoaded = true ;
163+ if ($ loadClasses ) {
164+ $ this ->loadClasses (true );
172165 }
173166
174167 return $ classes ;
@@ -177,18 +170,17 @@ public function compile(array $configs)
177170 public function loadClasses ($ forceReload = false )
178171 {
179172 if (!self ::$ classMapLoaded || $ forceReload ) {
180- $ classCollectionPath = $ this ->getClassCollectionPath ();
173+ $ classes = require $ this ->getClassesMap ();
181174
182- if (file_exists ($ classCollectionPath )) {
183- require_once $ classCollectionPath ;
184- }
175+ $ mapClassLoader = new MapClassLoader ($ classes );
176+ $ mapClassLoader ->register ();
185177
186178 self ::$ classMapLoaded = true ;
187179 }
188180 }
189181
190- private function getClassCollectionPath ()
182+ private function getClassesMap ()
191183 {
192- return $ this ->getCacheDir ().'/__types.bootstrap.php.cache ' ;
184+ return $ this ->getCacheDir ().'/__classes.map ' ;
193185 }
194186}
0 commit comments