77use Composer \InstalledVersions ;
88use Efabrica \PHPStanLatte \Compiler \Compiler \CompilerInterface ;
99use Efabrica \PHPStanLatte \Exception \ParseException ;
10+ use Efabrica \PHPStanLatte \Temp \TempDirResolver ;
1011use Efabrica \PHPStanLatte \Template \Template ;
1112use InvalidArgumentException ;
1213use Latte \CompileException ;
1516
1617final class LatteToPhpCompiler
1718{
18- private string $ tmpDir ;
19+ private string $ compileDir ;
20+
21+ private string $ analyseDir ;
1922
2023 private string $ cacheKey ;
2124
@@ -27,14 +30,18 @@ final class LatteToPhpCompiler
2730
2831 public function __construct (
2932 string $ cacheKey ,
30- CompiledTemplateDirResolver $ compiledTemplateDirResolver ,
33+ TempDirResolver $ tempDirResolver ,
3134 CompilerInterface $ compiler ,
3235 Postprocessor $ postprocessor ,
3336 bool $ debugMode = false
3437 ) {
35- $ this ->tmpDir = $ compiledTemplateDirResolver ->resolve ();
36- if (file_exists ($ this ->tmpDir ) && $ debugMode ) {
37- FileSystem::delete ($ this ->tmpDir );
38+ $ this ->compileDir = $ tempDirResolver ->resolveCompileDir ();
39+ $ this ->analyseDir = $ tempDirResolver ->resolveAnalyseDir ();
40+ if (file_exists ($ this ->compileDir ) && $ debugMode ) {
41+ FileSystem::delete ($ this ->compileDir );
42+ }
43+ if (file_exists ($ this ->analyseDir )) {
44+ FileSystem::delete ($ this ->analyseDir );
3845 }
3946 $ this ->cacheKey = $ cacheKey . md5 (
4047 Engine::VERSION_ID .
@@ -73,11 +80,13 @@ public function compileFile(Template $template, string $context = ''): string
7380 $ templateDir = substr ($ templateDir , strlen ($ replacedPath ));
7481 }
7582
76- $ compileDir = $ this ->normalizeCompileDir ($ this ->tmpDir . ' / ' . $ templateDir );
83+ $ compileDir = $ this ->normalizeCompileDir ($ this ->compileDir . DIRECTORY_SEPARATOR . $ templateDir );
7784 if (!file_exists ($ compileDir )) {
7885 mkdir ($ compileDir , 0777 , true );
7986 }
80- $ compileFilePath = $ compileDir . '/ ' . $ templateFileName . '. ' . $ contextHash . '.php ' ;
87+
88+ $ fileName = $ templateFileName . '. ' . $ contextHash . '.php ' ;
89+ $ compileFilePath = $ compileDir . DIRECTORY_SEPARATOR . $ fileName ;
8190
8291 if (!$ this ->debugMode && file_exists ($ compileFilePath )) {
8392 require ($ compileFilePath ); // load type definitions from compiled template
@@ -91,7 +100,7 @@ public function compileFile(Template $template, string $context = ''): string
91100
92101 private function normalizeCompileDir (string $ compileDir ): string
93102 {
94- $ compileDirParts = array_filter (explode (' / ' , $ compileDir ));
103+ $ compileDirParts = array_filter (explode (DIRECTORY_SEPARATOR , $ compileDir ));
95104 $ newCompileDirParts = [];
96105 foreach ($ compileDirParts as $ compileDirPart ) {
97106 if ($ compileDirPart === '.. ' ) {
@@ -100,6 +109,6 @@ private function normalizeCompileDir(string $compileDir): string
100109 }
101110 $ newCompileDirParts [] = $ compileDirPart ;
102111 }
103- return ' / ' . implode (' / ' , $ newCompileDirParts );
112+ return DIRECTORY_SEPARATOR . implode (DIRECTORY_SEPARATOR , $ newCompileDirParts );
104113 }
105114}
0 commit comments