File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public function __construct(
2020 public function save (): void
2121 {
2222 $ template = $ this ->getTwigEnvironment ()->load ('class.twig ' );
23+ $ this ->cleanupOutputFolder ();
2324
2425 foreach ($ this ->definitions as $ definition ) {
2526 $ classContent = $ template ->render ($ definition );
@@ -39,4 +40,23 @@ private function getTwigEnvironment(): Environment
3940 ]
4041 );
4142 }
43+
44+ private function cleanupOutputFolder (): void
45+ {
46+ $ filesToRemove = [];
47+ $ dataTransferFiles = glob ($ this ->outputPath . DIRECTORY_SEPARATOR . '*Transfer.php ' );
48+ $ immutableDataTransferFiles = glob ($ this ->outputPath . DIRECTORY_SEPARATOR . '*TransferImmutable.php ' );
49+ if ($ dataTransferFiles !== false ) {
50+ $ filesToRemove = array_merge ($ filesToRemove , $ dataTransferFiles );
51+ }
52+ if ($ immutableDataTransferFiles !== false ) {
53+ $ filesToRemove = array_merge ($ filesToRemove , $ immutableDataTransferFiles );
54+ }
55+
56+ foreach ($ filesToRemove as $ filename ) {
57+ if (is_file ($ filename ) && is_writable ($ filename )) {
58+ unlink ($ filename );
59+ }
60+ }
61+ }
4262}
You can’t perform that action at this time.
0 commit comments