@@ -204,7 +204,7 @@ private function cacheFilename(string $file): string
204204 return $ this ->tmpDir . basename ($ file ) . '. ' . $ cacheKey . '.json ' ;
205205 }
206206
207- private function saveLatteContextDataToCache (string $ file , LatteContextData $ fileResult )
207+ private function saveLatteContextDataToCache (string $ file , LatteContextData $ fileResult ): void
208208 {
209209 if (!is_dir ($ this ->tmpDir )) {
210210 Filesystem::createDir ($ this ->tmpDir , 0777 );
@@ -258,28 +258,47 @@ private function loadLatteContextDataFromCache(string $file): ?LatteContextData
258258 return null ;
259259 }
260260
261+ $ file = $ cacheData ['file ' ];
262+ $ fileHash = $ cacheData ['fileHash ' ];
263+
264+ if (!is_string ($ file ) || !is_string ($ fileHash )) {
265+ FileSystem::delete ($ cacheFile );
266+ return null ;
267+ }
268+
261269 // Check if the file has changed since the cache was created
262- if (sha1 (Filesystem::read ($ cacheData [ ' file ' ] )) !== $ cacheData [ ' fileHash ' ] ) {
270+ if (sha1 (Filesystem::read ($ file )) !== $ fileHash ) {
263271 return null ;
264272 }
265273
266274 if (isset ($ cacheData ['dependencies ' ]) && is_array ($ cacheData ['dependencies ' ])) {
267275 foreach ($ cacheData ['dependencies ' ] as $ dependency ) {
268- if (!isset ($ dependency ['file ' ], $ dependency ['fileHash ' ])) {
276+ if (!is_array ( $ dependency ) || ! isset ($ dependency ['file ' ], $ dependency ['fileHash ' ])) {
269277 return null ;
270278 }
271- if (!is_file ($ dependency ['file ' ])) {
279+ $ dependencyFile = $ dependency ['file ' ];
280+ $ dependencyFileHash = $ dependency ['fileHash ' ];
281+ if (!is_string ($ dependencyFile ) || !is_string ($ dependencyFileHash )) {
282+ return null ;
283+ }
284+ if (!is_file ($ dependencyFile )) {
272285 return null ;
273286 }
274287 // Check if the dependency file has changed since the cache was created
275- if (sha1 (Filesystem::read ($ dependency [ ' file ' ] )) !== $ dependency [ ' fileHash ' ] ) {
288+ if (sha1 (Filesystem::read ($ dependencyFile )) !== $ dependencyFileHash ) {
276289 return null ;
277290 }
278291 }
279292 }
280293
294+ $ data = $ cacheData ['data ' ];
295+ if (!is_array ($ data )) {
296+ FileSystem::delete ($ cacheFile );
297+ return null ;
298+ }
299+
281300 try {
282- return LatteContextData::fromJson ($ cacheData [ ' data ' ] , $ this ->typeStringResolver );
301+ return LatteContextData::fromJson ($ data , $ this ->typeStringResolver );
283302 } catch (Exception ) {
284303 FileSystem::delete ($ cacheFile );
285304 return null ;
0 commit comments