Raw function returning the elements contained in the given directory
@param string $path
@param string|callable $type
@param bool $hidden
@param string $detailed
@return array
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;
  }
927995
public static function getInstallationTypes($include_hidden = FALSE) {
    $path = drupal_get_path('profile', 'openy');
    $installation_types = Yaml::decode(file_get_contents($path . '/openy.installation_types.yml'));

    foreach ($installation_types as $key => $installation_type) {
      if (!empty($installation_type['hidden']) && !$include_hidden) {
        unset($installation_types[$key]);
      }
    }

    return $installation_types;
  }
1286836
public static function getFileExt($path, $type = self::MIME_FINFO)
    {
        $mime = self::getFileMime($path, $type);
        return $mime ? self::mimeToExt($mime) : null;
    }
1264786
public function getByType($type, $enabled = false)
    {
        $modules = $enabled ? $this->getEnabled() : $this->getList();

        foreach ($modules as $id => $info) {
            if ($type !== $info['type']) {
                unset($modules[$id]);
            }
        }

        return $modules;
    }
1022615
public function importResource($type, $path) {
        $src = '/static/'.$path;
        $template = self::$resTemplate[$type];
        $result = str_replace('{url}', $src, $template);
        return $result;
	}
293237
protected function _arrayInclude($path, array $options = [], $type = 'css')
    {
        $doc = $this->Document;
        if (is_array($path)) {
            $out = '';
            foreach ($path as $i) {
                $out .= $this->{$type}($i, $options);
            }

            if (empty($options['block'])) {
                return $out . $doc->eol;
            }

            return null;
        }

        return false;
    }
418802
public static function scandir($path, bool $show_files=true, bool $show_dirs=true, int $depth=-1) {
		ref\file::path($path, true);
		if (! $path || ! @\is_dir($path) || (! $show_files && ! $show_dirs)) {
			return array();
		}

		// Set the depth for recursion.
		if ($depth < 0) {
			$inner_depth = -1;
		}
		elseif ($depth >= 1) {
			$inner_depth = $depth - 1;
		}
		else {
			$inner_depth = 0;
		}

		$out = array();
		if ($handle = @\opendir($path)) {
			ref\file::trailingslash($path);
			while (false !== ($file = @\readdir($handle))) {
				// Always ignore dots.
				if (('.' === $file) || ('..' === $file)) {
					continue;
				}

				// This is a file.
				if (@\is_file("{$path}{$file}")) {
					if ($show_files) {
						$out[] = "{$path}{$file}";
					}
				}
				elseif (@\is_dir("{$path}{$file}")) {
					if ($show_dirs) {
						$out[] = "{$path}{$file}/";
					}

					if ((-1 === $inner_depth) || $inner_depth > 0) {
						$out = \array_merge($out, static::scandir("{$path}{$file}", $show_files, $show_dirs, $inner_depth));
					}
				}
			}
			\closedir($handle);
		}

		\sort($out);
		return $out;
	}
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;
    }
191818
public function listFiles(string $path = '', bool $recursive = false)
    {
        $contents = $this->listContents($path, $recursive);

        $filter = function ($object) {
            return $object['type'] === 'file';
        };

        return \array_values(\array_filter($contents, $filter));
    }
985769
public function listItem($type, $dir = '.', $recursive = false, $ignore = array())
    {
        if ($type != 'dir' && $type != 'file') {
            throw new \InvalidArgumentException('$type must "file" or "dir"');
        }
        $fileList = $this->nList($dir);
        $fileInfo = array();
        foreach ($fileList as $file) {
            // remove directory and subdirectory name
            $file = str_replace("$dir/", '', $file);
            if ($this->ignoreItem($type, $file, $ignore) !== true && $this->isDirOrFile("$dir/$file") == $type) {
                $fileInfo[] = $file;
            }
            if ($recursive === true && $this->isDirOrFile("$dir/$file") == 'dir') {
                $fileInfo = array_merge($fileInfo, $this->listItem($type, "$dir/$file", $recursive, $ignore));
            }
        }
        return $fileInfo;
    }
936293
protected function _getCurrentUrlAndOptions($path, array $options, $type, $external)
    {
        if (strpos($path, '//') !== false) {
            $url      = $path;
            $external = true;
            unset($options['fullBase']);
        } else {
            $url = $this->Url->{$type}($path, $options);
            $options = array_diff_key($options, ['fullBase' => null, 'pathPrefix' => null]);
        }

        return [$url, $options, $external];
    }
315400
public function getDirectoryList($path = null, $showHidden = true)
    {
        $uri = 'directory.list';
        $uriData = [];

        if ($path) {
            $uriData['path'] = $path;
        }
        if ($showHidden) {
            $uriData['show_hidden'] = true;
        }

        try {
            $response = $this->_request(
                [
                    'uri' => $uri,
                    'type' => 'get',
                    'data' => $uriData
                ]
            );
        } catch (\Exception $e) {
            throw new InvalidException($e->getMessage());
        }

        return $response->getBody()->getContents();
    }
577803
public function listDirectory($path, $recursive = false, $withHidden = true)
    {
        $dirs = $this->formatDirsAndFiles($this->laravelFS->directories($path, $recursive));
        $files = $this->formatDirsAndFiles($this->laravelFS->files($path, $recursive));

        $dirsAndFiles = $this->mergeDirsAndFiles($dirs, $files);

        return $this->formatDirsAndFiles($dirsAndFiles);
    }
6250
public function listContents($depth = 0, $filter = null, $type = 'all', $asHandlers = false)
	{
		$pattern = $this->path.'/*';

		if (is_array($filter))
		{
			$filters = $filter;
			$filter = new Filter;

			foreach ($filters as $f => $type)
			{
				if ( ! is_int($f))
				{
					$f = $type;
					$type = null;
				}

				$expected = true;

				if (strpos($f, '!') === 0)
				{
					$f = substr($f, 1);
					$expected = false;
				}

				$filter->addFilter($f, $expected, $type);
			}
		}

		if ($filter instanceof \Closure)
		{
			$callback = $filter;
			$filter = new Filter();
			$callback($filter);
		}

		if ( ! $filter)
		{
			$filter = new Filter;
		}

		$flags = GLOB_MARK;

		if ($type === 'file' and ! pathinfo($pattern, PATHINFO_EXTENSION))
		{
			// Add an extension wildcard
			$pattern .= '.*';
		}
		elseif ($type === 'dir')
		{
			$flags = GLOB_MARK | GLOB_ONLYDIR;
		}

		$contents = glob($pattern, $flags);

		// Filter the content.
		$contents = $filter->filter($contents);

		// Lower the depth for a recursive call
		if ($depth and $depth !== true)
		{
			$depth--;
		}

		$formatted = array();

		foreach ($contents as $item)
		{
			if ($filter->isCorrectType('dir', $item))
			{
				$_contents = array();

				if (($depth === true or $depth === 0) and ! $asHandlers)
				{
					$dir = new Directory($item);

					$_contents = $dir->listContents($item, $filter, $depth, $type);
				}

				if ($asHandlers)
				{
					$formatted[] = new Directory($item);
				}
				else
				{
					$formatted[$item] = $_contents;
				}
			}
			elseif ($filter->isCorrectType('file', $item))
			{
				if ($asHandlers)
				{
					$item = new File($item);
				}

				$formatted[] = $item;
			}
		}

		return $formatted;
	}
647592
public static function GetDirContent($path)
    {
        $files = array();
        $directory = opendir($path);

        while(($file = readdir($directory)) !== false)
        {
            $full_path = $path . "/" . $file;

            if(is_file($full_path))
            {
                $files[] = $full_path;
            }
            elseif($file != "." && $file != ".." && is_dir($full_path))
            {
                $files[] = $full_path;
                $files = array_merge($files, self::GetDirContent($full_path));
            }
        }

        closedir($directory);

        return $files;
    }
511294
public function findClasses($bundles, $directory = '', $type = '')
    {
        $finder = Finder::create()->files()->name('*.php')->sortByName()->ignoreUnreadableDirs();
        $found  = false;

        foreach ($bundles as $bundle) {
            $path = rtrim($bundle->getPath(), DIRECTORY_SEPARATOR);

            if (true === empty($directory)) {
                $found = true;
                $finder->in($path);
                continue;
            }

            if (false === is_array($directory)) {
                $directory = [$directory];
            }

            foreach ($directory as $dir) {
                $pathname = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, trim($dir, DIRECTORY_SEPARATOR));
                if (true === is_dir($pathname)) {
                    $found = true;
                    $finder->in($pathname);
                }
            }
        }

        if (false === $found) {
            return [];
        }

        $files = [];
        foreach ($finder as $file) {
            $files[] = $file->getPathname();
        }

        $classes = [];
        foreach ($files as $file) {
            foreach ($bundles as $bundle) {
                if (null !== $class = $this->getClassFromFileAndBundle($file, $bundle)) {
                    $classes[] = $class;
                    continue;
                }
            }
        }

        $classes = array_filter($classes, function ($e) {
            return class_exists($e);
        });

        if (false === empty($type)) {
            if (false === (class_exists($type) || interface_exists($type))) {
                throw new \InvalidArgumentException(sprintf('Class or interface "%s" unknown', $type));
            }
            $classes = array_filter($classes, function ($e) use ($type) {
                return is_subclass_of($e, $type);
            });
        }

        return $classes;
    }
659047
protected function getScandir($path) {
		$files = array();
		
		!isset($this->dirsCache[$path]) && $this->cacheDir($path);

		foreach ($this->dirsCache[$path] as $p) {
			if (($stat = $this->stat($p)) && empty($stat['hidden'])) {
				$files[] = $stat;
			}
		}

		return $files;
	}