99
1010use Nette ;
1111use Nette \Caching \Cache ;
12- use function dirname , fclose , filemtime , flock , fopen , fseek , ftruncate , fwrite , is_dir , is_string , microtime , mkdir , mt_getrandmax , mt_rand , rmdir , serialize , str_pad , str_repeat , stream_get_contents , strlen , strrpos , substr_replace , time , touch , unlink , unserialize , urlencode ;
12+ use function dirname , fclose , filemtime , flock , fopen , fseek , ftruncate , fwrite , is_array , is_dir , is_string , microtime , mkdir , mt_getrandmax , mt_rand , rmdir , serialize , str_pad , str_repeat , stream_get_contents , strlen , strrpos , substr_replace , time , touch , unlink , unserialize , urlencode ;
1313use const LOCK_EX , LOCK_SH , LOCK_UN , STR_PAD_LEFT ;
1414
1515
@@ -286,7 +286,7 @@ public function clean(array $conditions): void
286286
287287 // cleaning using journal
288288 if ($ this ->journal ) {
289- foreach ($ this ->journal ->clean ($ conditions ) as $ file ) {
289+ foreach ($ this ->journal ->clean ($ conditions ) ?? [] as $ file ) {
290290 $ this ->delete ($ file );
291291 }
292292 }
@@ -295,6 +295,7 @@ public function clean(array $conditions): void
295295
296296 /**
297297 * Reads cache data from disk.
298+ * @param int<0, 7> $lock
298299 * @return ?array<string, mixed> meta data with 'file' and 'handle' keys added, or null if not found
299300 */
300301 protected function readMetaAndLock (string $ file , int $ lock ): ?array
@@ -309,10 +310,13 @@ protected function readMetaAndLock(string $file, int $lock): ?array
309310 $ size = (int ) stream_get_contents ($ handle , self ::MetaHeaderLen);
310311 if ($ size ) {
311312 $ meta = stream_get_contents ($ handle , $ size , self ::MetaHeaderLen);
312- $ meta = unserialize ($ meta );
313- $ meta [self ::File] = $ file ;
314- $ meta [self ::Handle] = $ handle ;
315- return $ meta ;
313+ if ($ meta !== false ) {
314+ $ meta = unserialize ($ meta );
315+ assert (is_array ($ meta ));
316+ $ meta [self ::File] = $ file ;
317+ $ meta [self ::Handle] = $ handle ;
318+ return $ meta ;
319+ }
316320 }
317321
318322 flock ($ handle , LOCK_UN );
@@ -330,8 +334,11 @@ protected function readData(array $meta): mixed
330334 $ data = stream_get_contents ($ meta [self ::Handle]);
331335 flock ($ meta [self ::Handle], LOCK_UN );
332336 fclose ($ meta [self ::Handle]);
333-
334- return empty ($ meta [self ::MetaSerialized]) ? $ data : unserialize ($ data );
337+ return match (true ) {
338+ $ data === false => null ,
339+ empty ($ meta [self ::MetaSerialized]) => $ data ,
340+ default => unserialize ($ data ),
341+ };
335342 }
336343
337344
0 commit comments