format: Refactor searchInformation

- Rename function to getFormatName
- Add documentation
- Rename variables
- Remove unused variables
This commit is contained in:
logmanoriginal 2018-11-15 20:16:21 +01:00
parent d7c374bd8c
commit 59f2d755fe
2 changed files with 17 additions and 15 deletions

View file

@ -29,7 +29,7 @@ EOD;
$inactiveBridges = ''; $inactiveBridges = '';
$bridgeList = Bridge::getBridgeNames(); $bridgeList = Bridge::getBridgeNames();
$formats = Format::searchInformation(); $formats = Format::getFormatNames();
$totalBridges = count($bridgeList); $totalBridges = count($bridgeList);

View file

@ -140,25 +140,27 @@ class Format {
} }
/** /**
* Read format dir and catch informations about each format depending annotation * Returns the list of format names from the working directory.
* @return array Informations about each format *
*/ * The list is cached internally to allow for successive calls.
public static function searchInformation(){ *
$pathDirFormat = self::getWorkingDir(); * @return array List of format names
*/
public static function getFormatNames(){
static $formatNames = array(); // Initialized on first call
$listFormat = array(); if(empty($formatNames)) {
$files = scandir(self::getWorkingDir());
$searchCommonPattern = array('name'); if($files !== false) {
foreach($files as $file) {
$dirFiles = scandir($pathDirFormat); if(preg_match('/^([^.]+)Format\.php$/U', $file, $out)) {
if($dirFiles !== false) { $formatNames[] = $out[1];
foreach($dirFiles as $fileName) { }
if(preg_match('@^([^.]+)Format\.php$@U', $fileName, $out)) { // Is PHP file ?
$listFormat[] = $out[1];
} }
} }
} }
return $listFormat; return $formatNames;
} }
} }