@@ -54,14 +54,19 @@ class FileHandler extends BaseHandler
5454 */
5555 public function __construct (Cache $ config )
5656 {
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 , '\\/ ' ) . '/ ' ;
5964
6065 if (! is_really_writable ($ this ->path )) {
6166 throw CacheException::forUnableToWrite ($ this ->path );
6267 }
6368
64- $ this ->mode = $ config -> file ['mode ' ] ?? 0640 ;
69+ $ this ->mode = $ options ['mode ' ];
6570 $ this ->prefix = $ config ->prefix ;
6671
6772 helper ('filesystem ' );
@@ -342,33 +347,46 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs
342347 * @param bool $topLevelOnly Look only at the top level directory specified?
343348 * @param bool $_recursion Internal variable to determine recursion status - do not use in calls
344349 *
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
346357 */
347358 protected function getDirFileInfo (string $ sourceDir , bool $ topLevelOnly = true , bool $ _recursion = false )
348359 {
349- static $ _filedata = [];
350- $ relativePath = $ sourceDir ;
360+ static $ filedata = [];
361+
362+ $ relativePath = $ sourceDir ;
363+ $ filePointer = @opendir ($ sourceDir );
351364
352- if ($ fp = @ opendir ( $ sourceDir )) {
365+ if (! is_bool ( $ filePointer )) {
353366 // reset the array and make sure $sourceDir has a trailing slash on the initial call
354367 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 ;
357374 }
358375
359376 // 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 )) {
361378 if (is_dir ($ sourceDir . $ file ) && $ file [0 ] !== '. ' && $ topLevelOnly === false ) {
362379 $ this ->getDirFileInfo ($ sourceDir . $ file . DIRECTORY_SEPARATOR , $ topLevelOnly , true );
363380 } 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 ;
366384 }
367385 }
368386
369- closedir ($ fp );
387+ closedir ($ filePointer );
370388
371- return $ _filedata ;
389+ return $ filedata ;
372390 }
373391
374392 return false ;
@@ -382,10 +400,19 @@ protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true,
382400 *
383401 * @deprecated 4.6.1 Use `get_file_info()` instead.
384402 *
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
387405 *
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
389416 */
390417 protected function getFileInfo (string $ file , $ returnedValues = ['name ' , 'server_path ' , 'size ' , 'date ' ])
391418 {
0 commit comments