scanSubDir and check empty folder

This commit is contained in:
Prof Langues 2021-02-10 16:59:17 +01:00
parent c648d328d6
commit 3f68897639
2 changed files with 41 additions and 40 deletions

View File

@ -137,30 +137,51 @@ class helper {
public static function getModules() { public static function getModules() {
$dirs = array_diff(scandir('module'), array('..', '.')); $dirs = array_diff(scandir('module'), array('..', '.'));
foreach ($dirs as $key => $value) { foreach ($dirs as $key => $value) {
// Lire les constantes // Dossier non vide
$class_reflex = new \ReflectionClass($value); if (file_exists('module/' . $value . '/' . $value . '.php')) {
$class_constants = $class_reflex->getConstants(); // Lire les constantes
// Constante REALNAME $class_reflex = new \ReflectionClass($value);
if (array_key_exists('REALNAME', $class_constants)) { $class_constants = $class_reflex->getConstants();
$realName = $value::REALNAME; // Constante REALNAME
} else { if (array_key_exists('REALNAME', $class_constants)) {
$realName = ucfirst($value); $realName = $value::REALNAME;
} else {
$realName = ucfirst($value);
}
// Constante VERSION
if (array_key_exists('VERSION', $class_constants)) {
$version = $value::VERSION;
} else {
$version = '0.0';
}
// Affection
$modules [$value] = [
'realName' => $realName,
'version' => $version
];
} }
// Constante VERSION
if (array_key_exists('VERSION', $class_constants)) {
$version = $value::VERSION;
} else {
$version = '0.0';
}
// Affection
$modules [$value] = [
'realName' => $realName,
'version' => $version
];
} }
return($modules); return($modules);
} }
/**
* Scanne le contenu d'un dossier et de ses sous-dossiers
* @param string $dir Dossier à scanner
* @return array
*/
public static function scanSubDir($dir) {
$dirContent = [];
$iterator = new DirectoryIterator($dir);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isDir()) {
$dirContent[] = $dir . '/' . $fileInfos->getBasename();
$dirContent = array_merge($dirContent, self::scanSubDir($dir . '/' . $fileInfos->getBasename()));
}
}
return $dirContent;
}
/** /**
* Retourne true si le protocole est en TLS * Retourne true si le protocole est en TLS

View File

@ -324,7 +324,7 @@ class gallery extends common {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'display' => self::DISPLAY_JSON, 'display' => self::DISPLAY_JSON,
'content' => galleriesHelper::scanDir(self::FILE_DIR.'source') 'content' => helper::scanSubDir(self::FILE_DIR.'source')
]); ]);
} }
@ -673,24 +673,4 @@ class gallery extends common {
]); ]);
} }
}
class galleriesHelper extends helper {
/**
* Scan le contenu d'un dossier et de ses sous-dossiers
* @param string $dir Dossier à scanner
* @return array
*/
public static function scanDir($dir) {
$dirContent = [];
$iterator = new DirectoryIterator($dir);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isDir()) {
$dirContent[] = $dir . '/' . $fileInfos->getBasename();
$dirContent = array_merge($dirContent, self::scanDir($dir . '/' . $fileInfos->getBasename()));
}
}
return $dirContent;
}
} }