@@ -54,14 +54,19 @@ class FileHandler extends BaseHandler
54
54
*/
55
55
public function __construct (Cache $ config )
56
56
{
57
- $ this ->path = ! empty ($ config ->file ['storePath ' ]) ? $ config ->file ['storePath ' ] : WRITEPATH . 'cache ' ;
58
- $ this ->path = rtrim ($ this ->path , '/ ' ) . '/ ' ;
57
+ $ options = [
58
+ ...['storePath ' => WRITEPATH . 'cache ' , 'mode ' => 0640 ],
59
+ ...$ config ->file ,
60
+ ];
61
+
62
+ $ this ->path = $ options ['storePath ' ] !== '' ? $ options ['storePath ' ] : WRITEPATH . 'cache ' ;
63
+ $ this ->path = rtrim ($ this ->path , '\\/ ' ) . '/ ' ;
59
64
60
65
if (! is_really_writable ($ this ->path )) {
61
66
throw CacheException::forUnableToWrite ($ this ->path );
62
67
}
63
68
64
- $ this ->mode = $ config -> file ['mode ' ] ?? 0640 ;
69
+ $ this ->mode = $ options ['mode ' ];
65
70
$ this ->prefix = $ config ->prefix ;
66
71
67
72
helper ('filesystem ' );
@@ -342,33 +347,46 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs
342
347
* @param bool $topLevelOnly Look only at the top level directory specified?
343
348
* @param bool $_recursion Internal variable to determine recursion status - do not use in calls
344
349
*
345
- * @return array|false
350
+ * @return array<string, array{
351
+ * name: string,
352
+ * server_path: string,
353
+ * size: int,
354
+ * date: int,
355
+ * relative_path: string,
356
+ * }>|false
346
357
*/
347
358
protected function getDirFileInfo (string $ sourceDir , bool $ topLevelOnly = true , bool $ _recursion = false )
348
359
{
349
- static $ _filedata = [];
350
- $ relativePath = $ sourceDir ;
360
+ static $ filedata = [];
361
+
362
+ $ relativePath = $ sourceDir ;
363
+ $ filePointer = @opendir ($ sourceDir );
351
364
352
- if ($ fp = @ opendir ( $ sourceDir )) {
365
+ if (! is_bool ( $ filePointer )) {
353
366
// reset the array and make sure $sourceDir has a trailing slash on the initial call
354
367
if ($ _recursion === false ) {
355
- $ _filedata = [];
356
- $ sourceDir = rtrim (realpath ($ sourceDir ) ?: $ sourceDir , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
368
+ $ filedata = [];
369
+
370
+ $ resolvedSrc = realpath ($ sourceDir );
371
+ $ resolvedSrc = $ resolvedSrc === false ? $ sourceDir : $ resolvedSrc ;
372
+
373
+ $ sourceDir = rtrim ($ resolvedSrc , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ;
357
374
}
358
375
359
376
// Used to be foreach (scandir($sourceDir, 1) as $file), but scandir() is simply not as fast
360
- while (false !== ( $ file = readdir ($ fp ) )) {
377
+ while (false !== $ file = readdir ($ filePointer )) {
361
378
if (is_dir ($ sourceDir . $ file ) && $ file [0 ] !== '. ' && $ topLevelOnly === false ) {
362
379
$ this ->getDirFileInfo ($ sourceDir . $ file . DIRECTORY_SEPARATOR , $ topLevelOnly , true );
363
380
} elseif (! is_dir ($ sourceDir . $ file ) && $ file [0 ] !== '. ' ) {
364
- $ _filedata [$ file ] = $ this ->getFileInfo ($ sourceDir . $ file );
365
- $ _filedata [$ file ]['relative_path ' ] = $ relativePath ;
381
+ $ filedata [$ file ] = $ this ->getFileInfo ($ sourceDir . $ file );
382
+
383
+ $ filedata [$ file ]['relative_path ' ] = $ relativePath ;
366
384
}
367
385
}
368
386
369
- closedir ($ fp );
387
+ closedir ($ filePointer );
370
388
371
- return $ _filedata ;
389
+ return $ filedata ;
372
390
}
373
391
374
392
return false ;
@@ -382,10 +400,19 @@ protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true,
382
400
*
383
401
* @deprecated 4.6.1 Use `get_file_info()` instead.
384
402
*
385
- * @param string $file Path to file
386
- * @param array |string $returnedValues Array or comma separated string of information returned
403
+ * @param string $file Path to file
404
+ * @param list<string> |string $returnedValues Array or comma separated string of information returned
387
405
*
388
- * @return array|false
406
+ * @return array{
407
+ * name?: string,
408
+ * server_path?: string,
409
+ * size?: int,
410
+ * date?: int,
411
+ * readable?: bool,
412
+ * writable?: bool,
413
+ * executable?: bool,
414
+ * fileperms?: int
415
+ * }|false
389
416
*/
390
417
protected function getFileInfo (string $ file , $ returnedValues = ['name ' , 'server_path ' , 'size ' , 'date ' ])
391
418
{
0 commit comments