private function getFiles(string $dir, bool $recursive = false, $limit = null): array
    {
        if ($limit === 0) {
            return [];
        }
        $result = [];
        if (is_dir($dir)) {
            $list = scandir($dir);
            if (is_array($list)) {
                foreach ($list as $filename) {
                    if ($filename != '.' && $filename != '..') {
                        if (is_dir($dir . $filename)) {
                            if ($recursive === true) {
                                $dirResult = $this->getFiles($dir . $filename . '/', true, $limit !== null ? ($limit - sizeof($result)) : null);
                                if (!empty($dirResult)) {
                                    foreach ($dirResult as $index => $value) {
                                        $dirResult[$index] = $filename . '/' . $value;
                                    }
                                    $result = array_merge($result, $dirResult);
                                }
                            }
                        } else {
                            $result[] = $filename;
                            if ($limit !== null && $limit === sizeof($result)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        return $result;
    }