private function _recursiveRead($directory) { if (self::$depth > 0 && self::$currentDepth >= self::$depth) { return []; } self::$currentDepth++; $structure = []; $handle = opendir($directory); while (($item = readdir($handle)) !== false) { $path = $directory . '/' . $item; if (!in_array($item, $this->skip)) { if (is_dir($path)) { $structure[] = ['id' => $this->GUID(), 'text' => $item, 'type' => self::FOLDER, 'children' => $this->_recursiveRead($path)]; if (self::$currentDepth < 0) { self::$currentDepth = 0; } } else { $structure[] = ['id' => $this->GUID(), 'text' => $item, 'type' => self::FILE]; } } } self::$currentDepth--; usort($structure, function ($a, $b) { if ($a['type'] == self::FOLDER && $b['type'] == self::FOLDER) { if (strcasecmp($a['text'], $b['text']) < 0) { return -1; } if (strcasecmp($a['text'], $b['text']) > 0) { return 1; } } if ($a['type'] == self::FILE && $b['type'] == self::FILE) { if (strcasecmp($a['text'], $b['text']) < 0) { return -1; } if (strcasecmp($a['text'], $b['text']) > 0) { return 1; } } if ($a['type'] == self::FOLDER && $b['type'] == self::FILE) { return -1; } if ($a['type'] == self::FILE && $b['type'] == self::FOLDER) { return 1; } }); closedir($handle); return $structure; }