public function directoryToArray($directory, $recursive = true, $listDirs = false, $listFiles = true, $exclude = '')
{
$arrayItems = [];
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match("/(^(([\\.]){1,2})\$|(\\.(svn|git|md))|(Thumbs\\.db|\\.DS_STORE))\$/iu", $file, $skip);
if ($exclude) {
preg_match($exclude, $file, $skipByExclude);
}
if (!$skip && !$skipByExclude) {
if (is_dir($directory . '/' . $file)) {
if ($recursive) {
$arrayItems = array_merge($arrayItems, $this->directoryToArray($directory . '/' . $file, $recursive, $listDirs, $listFiles, $exclude));
}
if ($listDirs) {
$file = $directory . '/' . $file;
$arrayItems[] = $file;
}
} else {
if ($listFiles) {
$file = $directory . '/' . $file;
$arrayItems[] = $file;
}
}
}
}
closedir($handle);
}
return $arrayItems;
}