Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Created May 24, 2019 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lynt-smitka/3f723bd79a687879235540034c051629 to your computer and use it in GitHub Desktop.
Save lynt-smitka/3f723bd79a687879235540034c051629 to your computer and use it in GitHub Desktop.
/* 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