Traits cannot have constants in php 8.1, fix #4

This commit is contained in:
Jean-Christian Paul Denis 2023-05-31 20:42:57 +02:00
parent ec3c438fee
commit d5475e2e87
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951

View File

@ -22,20 +22,27 @@ use Dotclear\Helper\File\Path;
*/ */
trait DirTrait trait DirTrait
{ {
/** @var array<int,string> The excluded files */ /**
public const EXCLUDED = [ * Get excuded files.
'.', *
'..', * @param array<int,string> The excluded files
'__MACOSX', */
'.svn', public static function getExcluded(): array
'.hg', {
'.git', return [
'CVS', '.',
'.directory', '..',
'.DS_Store', '__MACOSX',
'Thumbs.db', '.svn',
'_disabled', '.hg',
]; '.git',
'CVS',
'.directory',
'.DS_Store',
'Thumbs.db',
'_disabled',
];
}
/** /**
* Get path structure. * Get path structure.
@ -52,7 +59,7 @@ trait DirTrait
foreach ($paths as $path) { foreach ($paths as $path) {
$dirs = Files::scanDir($path); $dirs = Files::scanDir($path);
foreach ($dirs as $k) { foreach ($dirs as $k) {
if (!is_string($k) || in_array($k, self::EXCLUDED) || !is_dir($path . DIRECTORY_SEPARATOR . $k)) { if (!is_string($k) || in_array($k, self::getExcluded()) || !is_dir($path . DIRECTORY_SEPARATOR . $k)) {
continue; continue;
} }
$stack[$k] = count(self::scanDir($path . DIRECTORY_SEPARATOR . $k)); $stack[$k] = count(self::scanDir($path . DIRECTORY_SEPARATOR . $k));
@ -107,7 +114,7 @@ trait DirTrait
$files = Files::scandir($path); $files = Files::scandir($path);
foreach ($files as $file) { foreach ($files as $file) {
if (in_array($file, self::EXCLUDED)) { if (in_array($file, self::getExcluded())) {
continue; continue;
} }
if (is_dir($path . DIRECTORY_SEPARATOR . $file)) { if (is_dir($path . DIRECTORY_SEPARATOR . $file)) {