Retrieve all yaml files from a directory.

@param string $directory The directory to scan

@return array

@throws FileSystemException
8377
protected function retrieveFiles(string $directory): array
    {
        $files = [];

        foreach (scandir($directory) as $file) {
            $elem = $this->pathHelper->join($directory, $file);

            if (
                $elem != '.' &&
                $elem != '..' &&
                \is_file($elem) &&
                \is_readable($elem) &&
                $this->stringHelper->endsWith($elem, '.yaml')
            ) {
                $files[] = $elem;
            }
        }

        if (count($files) == 0) {
            throw new FileSystemException('Path does not contain any readable yaml files!', 1527452904);
        }

        return $files;
    }
956623
public static function files(\RecursiveDirectoryIterator $directory): array
    {
        if (!$directory instanceof \RecursiveDirectoryIterator) {
            $directory = new \RecursiveDirectoryIterator($directory);
        }
        $files = [];
        for (; $directory->valid(); $directory->next()) {
            if ($directory->isDir() && !$directory->isDot()) {
                if ($directory->haschildren()) {
                    $files = array_merge($files, static::files($directory->getChildren()));
                };
            } else if ($directory->isFile()) {
                $files[] = $directory->getPathName();
            }
        }
        return $files;
    }
55781
protected function listDirectoryContentsRecursive($directory)
    {
        $listing = $this->normalizeListing($this->ftpRawlist('-aln', $directory) ?: [], $directory);
        $output = [];

        foreach ($listing as $directory) {
            $output[] = $directory;
            if ($directory['type'] !== 'dir') {
                continue;
            }

            $output = array_merge($output, $this->listDirectoryContentsRecursive($directory['path']));
        }

        return $output;
    }
637461
public function items($directory)
    {
        $directory = trim($directory, '/') . '/';

        $options = array(
            'return_prefixes' => true,
            'sort_results' => true
        );

        $objectIterator = $this->clientS3->getIterator('ListObjects', array(
            'Bucket'    => $this->bucket,
            'Prefix'    => $directory,
            'Delimiter' => '/',
        ), $options);

        $iterator = new CallbackFilterIterator($objectIterator, function($object){
            return (isset($object['Key']) || isset($object['Prefix']));
        });

        $files = array();

        foreach ($iterator as $object)
        {
            $files[] = isset($object['Key']) ? $object['Key'] : $object['Prefix'];
        }

        return $files;
    }
1327016
public function listFiles($directory)
    {
        $writeBinn= new BinnList;

        $writeBinn->addUint8(self::FSERV_READDIR);
        $writeBinn->addStr($directory);     // Dir path
        $writeBinn->addUint8(0);       // Mode

        $read = $this->writeAndReadSocket($writeBinn->serialize());

        $readBinn = new BinnList;

        $readBinn->binnOpen($read);
        $results = $readBinn->unserialize();

        if ($results[0] != self::FSERV_STATUS_OK) {
            // Error
            throw new RuntimeException('GDaemon List files error:' . isset($results[1]) ? $results[1] : 'Unknown');
        }

        $filesList = $results[2];
        $returnList = [];

        foreach($filesList as &$file) {

            if (in_array(basename($file[0]), ['.', '..'])) {
                continue;
            }

            $returnList[] = basename($file[0]);
        }

        return $returnList;
    }
1249478
public function getDirs($dir)
    {
        $dirArr = array();
        $files = ftp_rawlist($this->link, $dir);
        foreach ($files as $v) {
            $file = ltrim(strrchr($v, ' '), ' ');
            $path = "{$dir}/{$file}";
            if (preg_match('/^d/', $v)) {
                if (in_array($file, array('.', '..'))) {
                    continue;
                }
                if (preg_match('/^[a-zA-z0-9]+$/', $file)) { //file check
                    $dirArr[] = $path;
                    $dirArr = array_merge($dirArr, self::getDirs($path));
                }
            }
        }
        return $dirArr;
    }
1277526
protected function _scanDir($dir)
    {
        $dir = new Folder($dir);
        $contents = $dir->read(true, true);
        if (empty($contents[1])) {
            return [];
        }
        $shells = [];
        foreach ($contents[1] as $file) {
            if (substr($file, -4) !== '.php') {
                continue;
            }
            $shells[] = substr($file, 0, -4);
        }

        return $shells;
    }
656132
private function readDirectoryContent(string $directory): void
    {
        $items = new DirectoryIterator($directory);

        foreach ($items as $item) {

            if ($item->isFile() && $this->isFile($item->getFilename())) {
                $this->readFileContent($item->getPathname());
            }
        }
    }
1022250
private static function getAllYamls(string $directory): \Generator
    {
        /** @var \SplFileInfo $file */
        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file) {
            if ($file->isFile() && $file->getExtension() === 'yml') {
                $fileName = $file->getPathname();
                yield $fileName => Yaml::parse(file_get_contents($fileName));
            }
        }
    }
643311
protected function getFilesFromDir($dir)
    {
        $finder = new Finder();
        $finder->files()->ignoreUnreadableDirs()->in(realpath($dir));

        foreach ($this->excludes as $exclude) {
            $finder->notPath($exclude);
        }

        foreach ($this->extensions as $extension) {
            $finder->name('*.'.$extension);
        }

        return iterator_to_array($finder);
    }
128873
public function findClasses($directory)
    {
        $classes = [];
        foreach (Finder::create()->in($directory)->name('*.php') as $file) {
            $classes[] = $this->findClass($file->getRealPath());
        }
        return array_filter($classes);
    }
371236
public function getPlugin(string $directory)
    {
        $files = $this->files->files($this->app->mupluginsPath($directory));

        foreach ($files as $file) {
            $headers = $this->headers($file->getRealPath(), $this->headers);

            if (! empty($headers['name'])) {
                return array_merge(['root' => $file->getFilename()], $headers);
                break;
            }
        }
    }
517894
public function files($directory)
    {
        $files = array();

        $metadata = $this->dropbox->getMetadataWithChildren($this->pathRoot.$directory);

        if (isset($metadata['contents']) && is_array($metadata['contents']))
        {
            foreach ($metadata['contents'] as $file)
            {
                if ($file['is_dir'] == false) {
                    $files[] = $file['path'];
                }
            }
        }

        return $files;
    }
1072717
public function fetchDirectories($yaml)
    {
        $parsed = Yaml::parse($yaml);

        if (!isset($parsed['parameters'])) {
            throw new \RuntimeException(sprintf('Configuration must contain root node "parameters" (%s).', $yaml));
        }

        $config = $parsed['parameters'];

        $dirs = [];

        foreach ($this->params as $param) {
            if (!array_key_exists($param, $config)) {
                throw new \RuntimeException(sprintf('Parameter "%s" does not exist (%s).', $param, $yaml));
            }

            $dirs[$param] = trim($config[$param], DIRECTORY_SEPARATOR);
        }

        return $dirs;
    }
948237
public function scanDir($dir)
    {
        return collect(scandir($dir))->map(function ($item) use ($dir) {
            return $dir.DIRECTORY_SEPARATOR.$item;
        });
    }
275408
protected function getFileNames(string $directory = 'default'): array
    {
        $directoryIterator = $this->getDirectoryIterator($directory);
        $files = [];
        foreach ($directoryIterator as $file) {
            $this->resolveFile($file, $files);
        }
        return $files;
    }
913580
protected function listDirectoryContentsRecursive($directory)
    {
        $listing = $this->normalizeListing($this->ftpRawlist('-aln', $directory) ?: [], $directory);
        $output = [];

        foreach ($listing as $dir) {
            $output[] = [$dir];
            if ($dir['type'] !== 'dir') {
                continue;
            }

            $output[] = $this->listDirectoryContentsRecursive($dir['path']);
        }

        return \array_merge(...$output);
    }