以广度优先搜索扫描路径

@param string $path 路径
@param bool $ignoreDir 是否忽略文件夹
@return array
978147
private static function scanBfs(string $path, bool $ignoreDir = true): array
    {
        $files = [];
        $queue = new \SplQueue();
        $queue->enqueue($path);

        while (! $queue->isEmpty()) {
            $file = $queue->dequeue();
            $fileType = filetype($file);
            if ('dir' == $fileType) {
                $subFiles = self::scanCurrentDir($file, false);
                foreach ($subFiles as $subFile) {
                    $queue->enqueue($subFile);
                }
                if (false === $ignoreDir && $file !== $path) {
                    $files[] = $file;
                }
            }
            if ('file' == $fileType) {
                $files[] = $file;
            }
        }
        return $files;
    }
144111
public function parseConfig($path = null)
	{
		$ini = parse_ini_file( (!is_null($path) ? $path : $this->path));

		// pull in settings from other scanned INI files
		$scannedIniList = php_ini_scanned_files();
		if ($scannedIniList !== false) {
			foreach(explode(',', $scannedIniList) as $scannedFile) {
				$scannedIni = parse_ini_file(trim($scannedFile));
				$ini = array_merge($ini, $scannedIni);
			}
		}

		$this->setConfig($ini);
		return $ini;
	}
168485
private function shouldBeIgnored($path)
    {
        $path = $this->normalizePath($path);

        if ($this->isAutomaticallyIgnored($path)) {
            return true;
        }

        foreach ($this->ignoredPaths as $ignoredPath) {
            if (Str::is($this->normalizePath($ignoredPath), $path)) {
                return true;
            }
        }

        return false;
    }
729951
public function read($path) {
        $mapping = $this->mapper->get($path);

        if (!$mapping) {
            return false;
        }

        try {
            $file = $this->client->get($mapping['fid']);

            if (!$file) {
                return false;
            }

            return [
                'contents' => stream_get_contents($file)
            ];
        } catch (SeaweedFSException $e) {
            return false;
        }
    }
702509
protected function gettree($path, $deep, $exclude='') {
		$dirs = array();
		
		!isset($this->dirsCache[$path]) && $this->cacheDir($path);

		foreach ($this->dirsCache[$path] as $p) {
			$stat = $this->stat($p);
			
			if ($stat && empty($stat['hidden']) && $path != $exclude && $stat['mime'] == 'directory') {
				$dirs[] = $stat;
				if ($deep > 0 && !empty($stat['dirs'])) {
					$dirs = array_merge($dirs, $this->gettree($p, $deep-1));
				}
			}
		}

		return $dirs;
	}
613071
public function parse($path)
    {
        $fullPath = strstr($path, '.config.php') ? $path : $path . '.config.php';
        if (!file_exists($fullPath))
        {
            throw new FileNotFoundException($fullPath);
        }

        return include($fullPath);
    }
10739
static public function ignore(string $path): bool
    {
        // 取配置
        $all = configDefault(false,'router', '_ignore');

        // 如果没有配置,或为空
        if (!$all) {
            return false;
        }

        // 逐个配置查看
        foreach ($all as $case) {
            // 是否正则匹配
            if (preg_match($case, $path)) {
                return true;
            }
        }

        // 没有能匹配的
        return false;
    }
1187341
protected function _scandir($path) {
		$files = array();

 		foreach (ftp_rawlist($this->connect, $path) as $str) {
 			if (($stat = $this->parseRaw($str))) {
 				$files[] = $path.DIRECTORY_SEPARATOR.$stat['name'];
 			}
 		}

 		return $files;
	}
947487
public function scanDirectory(string $path): array
    {
        $files = [];

        $rdi = new \RecursiveDirectoryIterator(
            $path,
            \FilesystemIterator::SKIP_DOTS |
            \FilesystemIterator::KEY_AS_FILENAME |
            \FilesystemIterator::CURRENT_AS_FILEINFO
        );

        $rii = new \RecursiveIteratorIterator($rdi);

        foreach ($rii as $fileInfo) {
            $files[] = $fileInfo;
        }

        return $files;
    }
1164527
public static function listFiles($path, array $ext = null, $returnRelative = false, &$files = [])
    {
        $path = Normalize::diskFullPath($path);

        if (!Directory::exist($path)) {
            return [];
        }

        $dir = opendir($path . '/.');
        while ($item = readdir($dir)) {
            if (is_file($sub = $path . '/' . $item)) {
                $item_ext = Str::lastIn($item, '.');
                if ($ext === null || Arr::in($item_ext, $ext)) {
                    if ($returnRelative) {
                        $files[] = $item;
                    } else {
                        $files[] = $path . DIRECTORY_SEPARATOR . $item;
                    }
                }
            } else {
                if ($item !== '.' && $item !== '..') {
                    self::listFiles($sub, $ext, $returnRelative, $files);
                }
            }
        }

        return $files;
    }
193750
private function _get_items(string $path, $type = 'both', bool $hidden = false, string $detailed = ''): array
  {
    $files = [];
    if ( ($this->mode === 'ftp') && ($detailed || ($type !== 'both')) ){
      if ( $fs = ftp_mlsd($this->stream, substr($path, strlen($this->prefix))) ){
        foreach ( $fs as $f ){
          if ( ($f['name'] !== '.') && ($f['name'] !== '..') && ($hidden || (strpos(basename($f['name']), '.') !== 0)) ){
            $ok = 0;
            if ( $type === 'both' ){
              $ok = 1;
            }
            else if ( $type === 'dir' ){
              $ok = $f['type'] === 'dir';
            }
            else if ( $type === 'file' ){
              $ok = $f['type'] === 'file';
            }
            else if ( !is_string($type) || is_file($path.'/'.$f['name']) ){
              $ok = $this->_check_filter($f['name'], $type);
            }
            if ( $ok ){
              if ( $detailed ){
                if ( !isset($has_type, $has_mod) ){
                  $has_type = stripos($detailed, 't') !== false;
                  $has_mod = stripos($detailed, 'm') !== false;
                }
                $tmp = [
                  'path' => $path.'/'.$f['name']
                ];
                if ( $has_mod ){
                  $tmp['mtime'] = mktime(
                    substr($f['modify'], 8, 2),
                    substr($f['modify'], 10, 2),
                    substr($f['modify'], 12, 2),
                    substr($f['modify'], 4, 2),
                    substr($f['modify'], 6, 2),
                    substr($f['modify'], 0, 4)
                  );
                }
                if ( $has_type ){
                  $tmp['dir'] = $f['type'] === 'dir';
                  $tmp['file'] = $f['type'] !== 'dir';
                }
                $files[] = $tmp;
              }
              else{
                $files[] = $path.'/'.$f['name'];
              }
            }
          }
        }
      }
      else{
        bbn\x::log(error_get_last(), 'filesystem');
      }
    }
    else{
      $fs = scandir($path, SCANDIR_SORT_ASCENDING);
      foreach ( $fs as $f ){
        if ( ($f !== '.') && ($f !== '..') && ($hidden || (strpos(basename($f), '.') !== 0)) ){
          $ok = 0;
          $is_dir = null;
          $is_file = null;
          if ( $type === 'both' ){
            $ok = 1;
          }
          else if ( $type === 'dir' ){
            if ( $ok = is_dir($path.'/'.$f) ){
              $is_dir = $ok;
              $is_file = !$ok;
            }
          }
          else if ( $type === 'file' ){
            if ( $ok = is_file($path.'/'.$f) ){
              $is_file = $ok;
              $is_dir = !$ok;
            }
          }
          else if ( !is_string($type) || is_file($path.'/'.$f) ){
            $ok = $this->_check_filter($f, $type);
            $is_file = true;
            $is_dir = false;
          }
          if ( $ok ){
            if ( $detailed ){
              if ( !isset($has_type, $has_mod) ){
                $has_type = stripos($detailed, 't') !== false;
                $has_mod = stripos($detailed, 'm') !== false;
              }
              $tmp = [
                'path' => $path.'/'.$f
              ];
              if ( $has_mod ){
                $tmp['mtime'] = filemtime($path.'/'.$f);
              }
              if ( $has_type ){
                $tmp['dir'] = $is_dir ?? is_dir($path.'/'.$f);
                $tmp['file'] = $is_file ?? is_file($path.'/'.$f);
              }
              $files[] = $tmp;
            }
            else {
              $files[] = $path.'/'.$f;
            }
          }
        }
      }
    }
    if ( \count($files) > 0 ){
      //bbn\x::sort($files, 'real');
    }
    return $files;
  }
978141
public function canonicalize(array $checkedPaths, array $excludedPaths)
    {
        $checkedDirectories = array_filter($checkedPaths, function ($path) {
            return is_dir($path);
        });
        $canonicalizedPaths = array();

        foreach ($excludedPaths as $path) {
            if (!$this->pathHelper->isDirectoryRelative($path) && ($canonicalizedPath = realpath($path))) {
                $canonicalizedPaths[] = $canonicalizedPath;
            } else {
                foreach ($checkedDirectories as $checkedDirectory) {
                    $nestedExcludedDirectory = realpath(realpath($checkedDirectory) . DIRECTORY_SEPARATOR . $path);
                    $nestedExcludedDirectory && $canonicalizedPaths[] = $nestedExcludedDirectory;
                }
            }
        }

        return $canonicalizedPaths;
    }
1072469
public static function getFiles($path, $ext = null, $recursive = false, $parent = null, array $list = []): array
    {
        $path = self::pathFormat($path);

        if (!is_dir($path)) {
            throw new NotFoundException("directory not exists! DIR: $path");
        }

        $len = \strlen($path);
        $ext = \is_array($ext) ? implode('|', $ext) : trim($ext);

        foreach (glob($path . '*') as $v) {
            $relatePath = substr($v, $len);

            // 匹配文件 如果没有传入$ext 则全部遍历，传入了则按传入的类型来查找
            if (is_file($v) && (!$ext || preg_match("/\.($ext)$/i", $v))) {
                $list[] = $parent . $relatePath;

            } elseif ($recursive) {
                $list = self::getFiles($v, $ext, $recursive, $relatePath . '/', $list);
            }
        }

        return $list;
    }
655941
public function get_listing($path='', $page = '') {
        if (empty($path)) {
            $path = $this->build_node_path('root', get_string('pluginname', 'repository_googledocs'));
        }
        if (!$this->issuer->get('enabled')) {
            // Empty list of files for disabled repository.
            return ['dynload' => false, 'list' => [], 'nologin' => true];
        }

        // We analyse the path to extract what to browse.
        $trail = explode('/', $path);
        $uri = array_pop($trail);
        list($id, $name) = $this->explode_node_path($uri);

        // Handle the special keyword 'search', which we defined in self::search() so that
        // we could set up a breadcrumb in the search results. In any other case ID would be
        // 'root' which is a special keyword set up by Google, or a parent (folder) ID.
        if ($id === 'search') {
            return $this->search($name);
        }

        // Query the Drive.
        $q = "'" . str_replace("'", "\'", $id) . "' in parents";
        $q .= ' AND trashed = false';
        $results = $this->query($q, $path);

        $ret = array();
        $ret['dynload'] = true;
        $ret['defaultreturntype'] = $this->default_returntype();
        $ret['path'] = $this->build_breadcrumb($path);
        $ret['list'] = $results;
        $ret['manage'] = 'https://drive.google.com/';

        return $ret;
    }
748956
public function lsDirs(string $path = '') : array
    {
        return array_filter(
            $this->ls($path),
            function(File $file) {
                return $file->isDir();
            }
        );
    }
512539
public function get_listing($path='', $page = '') {
        if (empty($path)) {
            $path = $this->build_node_path('root', get_string('pluginname', 'repository_onedrive'));
        }

        if ($this->disabled) {
            // Empty list of files for disabled repository.
            return ['dynload' => false, 'list' => [], 'nologin' => true];
        }

        // We analyse the path to extract what to browse.
        $trail = explode('/', $path);
        $uri = array_pop($trail);
        list($id, $name) = $this->explode_node_path($uri);

        // Handle the special keyword 'search', which we defined in self::search() so that
        // we could set up a breadcrumb in the search results. In any other case ID would be
        // 'root' which is a special keyword, or a parent (folder) ID.
        if ($id === 'search') {
            $q = $name;
            $id = 'root';

            // Append the active path for search.
            $str = get_string('searchfor', 'repository_onedrive', $searchtext);
            $path = $this->build_node_path('search', $str, $path);
        }

        // Query the Drive.
        $parent = $id;
        if ($parent != 'root') {
            $parent = 'items/' . $parent;
        }
        $q = '';
        $results = $this->query($q, $path, $parent);

        $ret = [];
        $ret['dynload'] = true;
        $ret['path'] = $this->build_breadcrumb($path);
        $ret['list'] = $results;
        $ret['manage'] = 'https://www.office.com/';
        return $ret;
    }
472343
public function read($path)
    {
        try {
            $response = $this->forceReadFromCDN()
                ? $this->readFromCDN($path)
                : $this->readFromSource($path);

            return ['contents' => (string) $response];
        } catch (NoSuchKeyException $e) {
            return false;
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            return false;
        }
    }