@@ -26,6 +26,7 @@ class Generator
2626 private GeneratorTwigHelper $ twigHelper ;
2727 private array $ pendingOperations = [];
2828 private ?TemplateComponentGenerator $ templateComponentGenerator ;
29+ private array $ generatedFiles = [];
2930
3031 public function __construct (
3132 private FileManager $ fileManager ,
@@ -74,6 +75,8 @@ public function generateClass(string $className, string $templateName, array $va
7475
7576 /**
7677 * Generate a normal file from a template.
78+ *
79+ * @return void
7780 */
7881 public function generateFile (string $ targetPath , string $ templateName , array $ variables = [])
7982 {
@@ -84,6 +87,9 @@ public function generateFile(string $targetPath, string $templateName, array $va
8487 $ this ->addOperation ($ targetPath , $ templateName , $ variables );
8588 }
8689
90+ /**
91+ * @return void
92+ */
8793 public function dumpFile (string $ targetPath , string $ contents )
8894 {
8995 $ this ->pendingOperations [$ targetPath ] = [
@@ -160,29 +166,6 @@ public function getRootDirectory(): string
160166 return $ this ->fileManager ->getRootDirectory ();
161167 }
162168
163- private function addOperation (string $ targetPath , string $ templateName , array $ variables ): void
164- {
165- if ($ this ->fileManager ->fileExists ($ targetPath )) {
166- throw new RuntimeCommandException (sprintf ('The file "%s" can \'t be generated because it already exists. ' , $ this ->fileManager ->relativizePath ($ targetPath )));
167- }
168-
169- $ variables ['relative_path ' ] = $ this ->fileManager ->relativizePath ($ targetPath );
170-
171- $ templatePath = $ templateName ;
172- if (!file_exists ($ templatePath )) {
173- $ templatePath = __DIR__ .'/Resources/skeleton/ ' .$ templateName ;
174-
175- if (!file_exists ($ templatePath )) {
176- throw new \Exception (sprintf ('Cannot find template "%s" ' , $ templateName ));
177- }
178- }
179-
180- $ this ->pendingOperations [$ targetPath ] = [
181- 'template ' => $ templatePath ,
182- 'variables ' => $ variables ,
183- ];
184- }
185-
186169 public function hasPendingOperations (): bool
187170 {
188171 return !empty ($ this ->pendingOperations );
@@ -196,6 +179,8 @@ public function hasPendingOperations(): bool
196179 public function writeChanges ()
197180 {
198181 foreach ($ this ->pendingOperations as $ targetPath => $ templateData ) {
182+ $ this ->generatedFiles [] = $ targetPath ;
183+
199184 if (isset ($ templateData ['contents ' ])) {
200185 $ this ->fileManager ->dumpFile ($ targetPath , $ templateData ['contents ' ]);
201186
@@ -204,7 +189,7 @@ public function writeChanges()
204189
205190 $ this ->fileManager ->dumpFile (
206191 $ targetPath ,
207- $ this ->getFileContentsForPendingOperation ($ targetPath, $ templateData )
192+ $ this ->getFileContentsForPendingOperation ($ targetPath )
208193 );
209194 }
210195
@@ -242,6 +227,14 @@ public function generateTemplate(string $targetPath, string $templateName, array
242227 );
243228 }
244229
230+ /**
231+ * Get the full path of each file created by the Generator.
232+ */
233+ public function getGeneratedFiles (): array
234+ {
235+ return $ this ->generatedFiles ;
236+ }
237+
245238 /**
246239 * @deprecated MakerBundle only supports AbstractController::class. This method will be removed in the future.
247240 */
@@ -251,4 +244,27 @@ public static function getControllerBaseClass(): ClassNameDetails
251244
252245 return new ClassNameDetails (AbstractController::class, '\\' );
253246 }
247+
248+ private function addOperation (string $ targetPath , string $ templateName , array $ variables ): void
249+ {
250+ if ($ this ->fileManager ->fileExists ($ targetPath )) {
251+ throw new RuntimeCommandException (sprintf ('The file "%s" can \'t be generated because it already exists. ' , $ this ->fileManager ->relativizePath ($ targetPath )));
252+ }
253+
254+ $ variables ['relative_path ' ] = $ this ->fileManager ->relativizePath ($ targetPath );
255+
256+ $ templatePath = $ templateName ;
257+ if (!file_exists ($ templatePath )) {
258+ $ templatePath = __DIR__ .'/Resources/skeleton/ ' .$ templateName ;
259+
260+ if (!file_exists ($ templatePath )) {
261+ throw new \Exception (sprintf ('Cannot find template "%s" ' , $ templateName ));
262+ }
263+ }
264+
265+ $ this ->pendingOperations [$ targetPath ] = [
266+ 'template ' => $ templatePath ,
267+ 'variables ' => $ variables ,
268+ ];
269+ }
254270}
0 commit comments