Created
May 24, 2019 12:36
-
-
Save lynt-smitka/3f723bd79a687879235540034c051629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* cache proměnná pro podadresáře */ | |
$subdirsCache=array(); | |
/** | |
* Získání všech názvů podadresářů pro zadaný adresář | |
* | |
* @author Martin Hlaváč | |
* @link http://www.ktstudio.cz | |
* | |
* @return array | |
*/ | |
function kt_get_subdirs_names($dirPath, $checkForDirExists = true) { | |
global $subdirsCache; | |
/* pokud se podsložka už testovala, vrátí se z cache */ | |
if(isset($subdirsCache[$dirPath])) { | |
return $subdirsCache[$dirPath]; | |
} | |
if (isset($dirPath) && is_dir($dirPath)) { | |
$subdirsNames = array(); | |
$names = array_diff(scandir($dirPath), array(".", "..", ".git", ".gitignore", "LICENSE", "README.md", "composer.json", "kt_init.inc.php")); | |
foreach ($names as $name) { // procházíme základní adresáře v KT, tedy moduly | |
if ($checkForDirExists === true) { | |
if (substr(strrchr($name, "."), 1) !== 'php' && is_dir(path_join($dirPath, $name))) { //pokud končí na .php nenude to složka | |
array_push($subdirsNames, $name); | |
} | |
} else { | |
array_push($subdirsNames, $name); | |
} | |
} | |
$subdirsCache[$dirPath] = $subdirsNames; | |
return $subdirsNames; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment