League\CLImate\TerminalObject\Helper\Art::fileSearch PHP Method

fileSearch() protected method

Find a set of files in the current art directories based on a pattern
protected fileSearch ( string $art, string $pattern ) : array
$art string
$pattern string
return array
    protected function fileSearch($art, $pattern)
    {
        foreach ($this->art_dirs as $dir) {
            $directory_iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
            $paths = [];
            $regex = '~' . preg_quote($art) . $pattern . '~';
            foreach ($directory_iterator as $file) {
                if ($file->isDir()) {
                    continue;
                }
                // Look for anything that has the $art filename
                if (preg_match($regex, $file)) {
                    $paths[] = $file->getPathname();
                }
            }
            asort($paths);
            // If we've got one, no need to look any further
            if (!empty($paths)) {
                return $paths;
            }
        }
        return [];
    }