Returns the directory and its content data recursively
@param string $path - Path to directory from where to start
@param bool   $onlyLevel
@param int    $lvl  - level
@return array with content
516978
public static function scanDirs($path, $onlyLevel = false, $lvl = 0)
    {
        static $res;

        if ($lvl == 0) {
            $res = [];
        }

        if (!is_dir($path)) {
            return [];
        }

        if (substr($path, -1) == '/') {
            $path = substr($path, 0, -1);
        }
        $dir_base_length = strlen(DIR_BASE) - 1;

        foreach (array_diff(scandir($path), ['.', '..']) as $f) {
            if (is_dir($path . '/' . $f)) {
                if (!$onlyLevel) $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => 0,
                    'type'     => 'dir'
                ];
                self::scanDirs($path . '/' . $f, $onlyLevel, $lvl + 1);
            } elseif ($onlyLevel) {
                $res[] = $path . '/' . $f;
            } else {
                $res[] = [
                    'path_url' => substr($path, $dir_base_length),
                    'path'     => $path,
                    'name'     => $f,
                    'full'     => $path . '/' . $f,
                    'fs'       => filesize($path . '/' . $f),
                    'type'     => 'file'
                ];
            }
        }

        if ($lvl == 0) {
            return $res;
        }

        return [];
    }
1279696
public function fileGetContents($path)
    {
        if (! $this->isFile($path))
            return false;
        return $this->at($path)->content;
    }
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;
	}
94641
public static function getFiles($onlySuccessful)
    {
        if (self::$request === null) {
            self::$request = new Request();
        }
        return self::$request->getUploadedFiles($onlySuccessful);
    }
110341
protected function  getfiles($path, $allowFiles, &$files = array())
    {

        if (!is_dir($path)) return null;
        if(substr($path, strlen($path) - 1) != '/') $path .= '/';
        $handle = opendir($path);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                $path2 = $path . $file;
                if (is_dir($path2)) {
                    $this->getfiles($path2, $allowFiles, $files);
                } else {
                    if (preg_match("/\.(".$allowFiles.")$/i", $file)) {
                        $files[] = array(
                            'url'=> str_replace(public_path(), '', $path2),
                            'mtime'=> filemtime($path2)
                        );
                    }
                }
            }
        }
        return $files;
    }
738956
public function _getByPath($path)
    {
        $result = null;
        $steps = $this->_pathAsArray($path);
        $depth = count($steps); // number of steps in the path
        if ($depth == 0) {
            $result = $this->data;
        } else {
            $pointer = $this->data;
            $level = 0;
            foreach ($steps as $step) {
                if (is_array($pointer)) {
                    if (isset($pointer[$step])) {
                        /* go to the next step */
                        $pointer = $pointer[$step];
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } elseif ($pointer instanceof \Flancer32\Lib\Data) {
                    if (!is_null($pointer->get($step))) {
                        /* go to the next step */
                        $pointer = $pointer->get($step);
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } elseif (is_object($pointer)) {
                    if (isset($pointer->$step)) {
                        /* go to the next step */
                        $pointer = $pointer->$step;
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } else {
                    /* we have no data for the next step */
                    break;
                }
                $level++; // one step on the path is done
            }
            if ($level >= $depth) {
                /* we have reached the end of path */
                $result = $pointer;
            }
        }
        return $result;
    }
1196227
public function dirname(string $path, int $levels = 1): string
    {
        [$scheme, $path] = $this->getSchemeAndHierarchy($path);

        if ($this->normalize || ($scheme && null === $this->normalize)) {
            $path = $this->normalizePathPart($path);
        }

        [$scheme, $path] = $this->dirnameInternal($scheme, $path, $levels);

        return $this->toString($scheme, $path);
    }
758144
public function runFilters($data, $path, $lvl = 0)
    {
        $filterMatches = array();
        $restrictions = $this->getRestrictions();
        $sig = md5(print_r($data, true));

        $cache = $this->getCache();
        if ($cache !== null) {
            $cacheData = $cache->get($sig);
            if ($cacheData !== null) {
                return $cacheData;
            }
        }

        $data = new \ArrayIterator($data);
        $data->rewind();
        while($data->valid() && !$this->impactLimitReached()) {
            $index = $data->key();
            $value = $data->current();
            $data->next();

            if (count($path) > $lvl) {
                $path = array_slice($path, 0, $lvl);
            }

            $path[] = $index;

            // see if it's an exception
            if ($this->isException(implode('.', $path))) {
                $this->getLogger()->info('Exception found on '.implode('.', $path));
                continue;
            }

            if (is_array($value)) {
                $l = $lvl+1;
                $filterMatches = array_merge(
                    $filterMatches,
                    $this->runFilters($value, $path, $l)
                );
                continue;
            }

            $p = implode('.', $path);

            // See if we have restrictions & if the path matches
            if (!empty($restrictions) && !in_array($p, $restrictions)) {
                $this->getLogger()->info(
                    'Restrictions enabled, no match on path '.implode('.', $path),
                    array('restrictions' => $restrictions)
                );
                continue;
            }

            $filterMatches = array_merge(
                $filterMatches,
                $this->processFilters($value, $index, $path)
            );
        }

        if ($cache !== null) {
            $cache->save($sig, $filterMatches);
        }
        return $filterMatches;
    }
857806
public function getFiles($onlySuccessful = true)
    {
        $context = $this->_context;

        $files = [];

        /** @var $_FILES array */
        foreach ($context->_FILES as $key => $file) {
            if (is_int($file['error'])) {
                if (!$onlySuccessful || $file['error'] === UPLOAD_ERR_OK) {
                    $fileInfo = [
                        'name' => $file['name'],
                        'type' => $file['type'],
                        'tmp_name' => $file['tmp_name'],
                        'error' => $file['error'],
                        'size' => $file['size'],
                    ];
                    $files[] = new File($key, $fileInfo);
                }
            } else {
                $countFiles = count($file['error']);
                /** @noinspection ForeachInvariantsInspection */
                for ($i = 0; $i < $countFiles; $i++) {
                    if (!$onlySuccessful || $file['error'][$i] === UPLOAD_ERR_OK) {
                        $fileInfo = [
                            'name' => $file['name'][$i],
                            'type' => $file['type'][$i],
                            'tmp_name' => $file['tmp_name'][$i],
                            'error' => $file['error'][$i],
                            'size' => $file['size'][$i],
                        ];
                        $files[] = new File($key, $fileInfo);
                    }
                }
            }
        }

        return $files;
    }
720943
protected function getApartLevelFile($path, $type)
    {
        if ($this->config['single']) {
            $name = is_string($this->config['single']) ? $this->config['single'] : 'worker';

            $name .= '_' . $type;
        } elseif ($this->config['max_files']) {
            $name = date('Ymd') . '_' . $type . '_worker';
        } else {
            $name = date('d') . '_' . $type . '_worker';
        }

        return $path . DIRECTORY_SEPARATOR . $name . '.log';
    }
143313
public function gzip($path = null, $level = 9)
    {
        $content = $this->execute($path);
        $content = gzencode($content, $level, FORCE_GZIP);

        // save to path
        if ($path !== null) {
            $this->save($content, $path);
        }

        return $content;
    }
327749
public static function dirs($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) use ($path, $recursive)
		{
			if ($recursive)
			{
				// Ignore self
				if ($iterator->getRealPath() == static::cleanPath($path))
				{
					return false;
				}

				// If set to recursive, every returned folder name will include a dot (.),
				// so we can't using isDot() to detect folder.
				return $iterator->isDir() && ($iterator->getBasename() != '..');
			}
			else
			{
				return $iterator->isDir() && !$iterator->isDot();
			}
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
	    
	    return $files;
	}
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);
    }
335858
public function get($path, $depth = 0)
    {
        $node = $this->nodeRepoForDepth($depth)->getByPathOrFail($path);
        return $this->ensureEloquentFile($node);
    }
1227600
public function getSubtreeContent($sourceId, $onlyIds = false)
    {
        try {
            return $this->innerGateway->getSubtreeContent($sourceId, $onlyIds);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
73431
protected function getPhpFiles($path)
    {
        if (is_dir($path)) {
            return new RegexIterator(
                new RecursiveIteratorIterator(
                    new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
                    RecursiveIteratorIterator::SELF_FIRST,
                    RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
                ),
                '/^.+\.php$/i',
                RecursiveRegexIterator::GET_MATCH
            );
        }
        else {
            return [];
        }
    }
1187323
protected function _getContents($path) {
		$contents = '';
		try {
			$contents = $this->dropbox->getFile($path);
		} catch (Dropbox_Exception $e) {
			return $this->setError('Dropbox error: '.$e->getMessage());
		}
		return $contents;
	}