Extracts files from an array of args

@param array $args
@param bool $allowWildcards Whether wildcards are allowed
@return array
495695
public static function filterFiles($args, $allowWildcards = true)
    {
        $files = array();
        foreach ($args as $arg) {
            if (file_exists($arg)) {
                $files[] = $arg;
            } else if ($allowWildcards && strpos($arg, '*') !== false) {
                $files = array_merge($files, glob($arg));
            }
        }
        return $files;
    }
1162284
private static function scanDfs(string $path, bool $excludeDir = true): array
    {
        $files = [];
        $subFiles = self::scanCurrentDir($path, false);

        foreach ($subFiles as $subFile) {
            $fileType = filetype($subFile);
            if ('dir' == $fileType) {
                $innerFiles = self::scanDfs($subFile, $excludeDir);
                $files = ArrayHelper::merge($files, $innerFiles);
                if (false === $excludeDir) {
                    $files[] = $subFile;
                }
            }
            if ('file' == $fileType) {
                $files[] = $subFile;
            }
        }
        return $files;
    }
1003523
public function fetchSingle(...$args)
    { 
        $args[] = QB::limit(1);
        $select = $this->select($args);
        return $select->fetch();
    }
1042700
public function parseExcludes($excludes)
    {
        $this->requestedExcludes = [];

        if (is_string($excludes)) {
            $excludes = explode(',', $excludes);
        }

        if (! is_array($excludes)) {
            throw new \InvalidArgumentException(
                'The parseExcludes() method expects a string or an array. '.gettype($excludes).' given'
            );
        }

        foreach ($excludes as $excludeName) {
            $excludeName = $this->trimToAcceptableRecursionLevel($excludeName);

            if (in_array($excludeName, $this->requestedExcludes)) {
                continue;
            }

            $this->requestedExcludes[] = $excludeName;
        }

        return $this;
    }
943790
public static function getPairs($args = array())
    {
        $called_class = get_called_class();
        $instance = Post\Factory::create($called_class);

        // Optimize the query if no args
        // Unfortunately, WP doesn't provide a clean way to specify which columns to select
        // If WP allowed that, this custom SQL wouldn't be necessary
        if (!Arr::iterable($args)) {
            global $wpdb;
            $sql = sprintf(
                "SELECT
                    p.ID,
                    p.post_title
                FROM $wpdb->posts p
                WHERE p.post_type = '%s'
                AND (p.post_status = 'publish')
                ORDER BY p.post_title ASC",
                $instance->getPostType()
            );
            $results = $wpdb->get_results($sql);
            if (!Arr::iterable($results)) {
                return array();
            }
            
            return array_combine(
                Collection::pluck($results, 'ID'),
                Collection::pluck($results, 'post_title')
            );
        }
        
        // Custom args provided
        $default_args = array(
            'post_type'  => $instance->getPostType(),
            'numberposts'=> -1,
            'order'      => 'ASC',
            'orderby'    => 'title',
        );
        $args = (Arr::iterable($args)) ? $args : $default_args;
        if (!array_key_exists('post_type', $args)) {
            $args['post_type'] = $instance->getPostType();
        }

        $all = get_posts($args);
        if (!Arr::iterable($all)) {
            return array();
        }

        return array_combine(
            Collection::pluck($all, self::ID),
            Collection::pluck($all, 'post_title')
        );
    }
772418
protected function mkfile($args) {
		$target = $args['target'];
		$name   = $args['name'];
		
		if (($volume = $this->volume($target)) == false) {
			return array('error' => $this->error(self::ERROR_MKFILE, $name, self::ERROR_TRGDIR_NOT_FOUND, '#'.$target));
		}

		return ($file = $volume->mkfile($target, $args['name'])) == false
			? array('error' => $this->error(self::ERROR_MKFILE, $name, $volume->error()))
			: array('added' => array($file));
	}
191797
public static function prepareParse (string $input, bool $allowFile) : array
    {
        // Is string or is file ?
        if ($allowFile === true && is_file($input)) :
            $input = file_get_contents($input);
        endif;

        // Line
        $input = preg_replace("(\r\n|\n|\r)",';',$input);
        $input = explode(';', $input);

        // Delete comments
        foreach ($input as &$line) :
            // Delete comments
            $is_comment = mb_strpos($line, '#');
            if ($is_comment !== false) :
                $line = substr($line, 0, $is_comment);
            endif;

            // Trim
            $line = trim($line);
        endforeach;

        return $input;
    }
883896
private function getSelectedModules(Args $args)
    {
        $states = $this->getSelectedStates($args);
        $expr = Expr::true();
        $envs = array();

        if ($states !== ModuleState::all()) {
            $expr = $expr->andMethod('getState', Expr::in($states));
        }

        if ($args->isOptionSet('installer')) {
            $expr = $expr->andMethod('getInstallInfo', Expr::method('getInstallerName', Expr::same($args->getOption('installer'))));
        }

        if ($args->isOptionSet('prod')) {
            $envs[] = Environment::PROD;
        }

        if ($args->isOptionSet('dev')) {
            $envs[] = Environment::DEV;
        }

        if (count($envs) > 0) {
            $expr = $expr->andMethod('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs)));
        }

        return $this->moduleManager->findModules($expr);
    }
231059
protected function isIterable(...$args)
    {
        foreach ($args as $arg) {
            if (!is_array($arg) && !$arg instanceof \IteratorAggregate) {
                return false;
            }
        }

        return true;
    }
381595
protected function getFiles($path, $allowFiles, &$files = [])
    {
        if (! is_dir($path)) {
            return null;
        }
        if (in_array(basename($path), $this->ignoreDir)) {
            return null;
        }
        if (substr($path, strlen($path) - 1) != '/') {
            $path .= '/';
        }
        $handle = opendir($path);
        //baseUrl用于兼容使用alias的二级目录部署方式
        $baseUrl = str_replace(yii::getAlias('@frontend/web'), '', yii::getAlias('@ueditor'));
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                $path2 = $path . $file;
                if (is_dir($path2)) {
                    $this->getFiles($path2, $allowFiles, $files);
                } else {
                    if ($this->controller->action->id == 'list-image' && $this->thumbnail) {
                        $pat = "/\.thumbnail\.(" . $allowFiles . ")$/i";
                    } else {
                        $pat = "/\.(" . $allowFiles . ")$/i";
                    }
                    if (preg_match($pat, $file)) {
                        $files[] = [
                            'url' => yii::$app->params['site']['url'] . $baseUrl . substr($path2, strlen(yii::getAlias('@ueditor'))),
                            'mtime' => filemtime($path2)
                        ];
                    }
                }
            }
        }
        return $files;
    }
179305
private function getPathMappingStates(Args $args)
    {
        $states = array(
            PathMappingState::ENABLED => 'enabled',
            PathMappingState::NOT_FOUND => 'not-found',
            PathMappingState::CONFLICT => 'conflict',
        );

        $states = array_filter($states, function ($option) use ($args) {
            return $args->isOptionSet($option);
        });

        return array_keys($states) ?: PathMappingState::all();
    }
1178281
protected function getFiles($path, $allowFiles, &$files = [])
    {
        if (!is_dir($path)) return null;
        if (in_array(basename($path), $this->ignoreDir)) return null;
        if (substr($path, strlen($path) - 1) != '/') $path .= '/';
        $handle = opendir($path);
        //baseUrl用于兼容使用alias的二级目录部署方式
        $baseUrl = Yii::$app->request->baseUrl;
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                $path2 = $path . $file;
                if (is_dir($path2)) {
                    $this->getFiles($path2, $allowFiles, $files);
                } else {
                    if ($this->action->id == 'list-image') {
                        $pat = "/\.thumbnail\.(" . $allowFiles . ")$/i";
                    } else {
                        $pat = "/\.(" . $allowFiles . ")$/i";
                    }
                    if (preg_match($pat, $file)) {
                        $files[] = [
                            'url' => $baseUrl . substr($path2, strlen($this->webroot)),
                            'mtime' => filemtime($path2)
                        ];
                    }
                }
            }
        }
        return $files;
    }
1257283
protected function loadFiles(
        string $path,
        array $excludes
    ) {
        $fileFinder = new FileFinder();

        /**
         * Building the real directory or file to work in.
         */
        $filesystem = new Filesystem();
        if (!$filesystem->isAbsolutePath($path)) {
            $path = getcwd() . DIRECTORY_SEPARATOR . ltrim($path, '/');
        }

        if (!is_file($path) && !is_dir($path)) {
            throw new Exception('Directory or file "' . $path . '" does not exist');
        }

        return $fileFinder
            ->findPHPFilesByPath(
                $path,
                $excludes
            );
    }
1108675
private function getOnePathData($data, string $root, bool $allowFiles, bool $allowDirs): ?string
    {
        if ($data === null) {
            return null;
        }

        if (!\is_array($data)) {
            $data = [$data];
        }

        $result = $this->existingPaths($data, $root, $allowFiles, $allowDirs);

        if ($result === null || \count($result) !== 1) {
            return null;
        }

        return reset($result);
    }
199347
public function removeExcludedPath(array $files, $excludePath)
    {
        $result = $includedFiles = array();

        if (true === empty($excludePath)) {
            return $files;
        }

        foreach ($files as $filePath) {
            preg_match_all($this->coverFishHelper->getRegexPath($excludePath), $filePath, $result, PREG_SET_ORDER);
            if (true === empty($result)) {
                $includedFiles[] = $filePath;
            }
        }

        return $includedFiles;
    }
490567
private function extract(iterable $extractors, string $method, array $arguments)
    {
        foreach ($extractors as $extractor) {
            if (null !== $value = $extractor->{$method}(...$arguments)) {
                return $value;
            }
        }
    }
650901
private function parseArgs(array $args)
    {
        if (! count($args)) {
            return $this->createHelpArgument();
        }

        $arg1 = array_shift($args);

        if (in_array($arg1, ['-h', '--help', 'help'], true)) {
            return $this->createHelpArgument();
        }

        if (! count($args)) {
            return $this->createErrorArgument('Missing class name');
        }

        $configFile = $arg1;
        switch (file_exists($configFile)) {
            case true:
                $config = require $configFile;

                if (! is_array($config)) {
                    return $this->createErrorArgument(sprintf(
                        'Configuration at path "%s" does not return an array.',
                        $configFile
                    ));
                }

                break;
            case false:
                // fall-through
            default:
                if (! is_writable(dirname($configFile))) {
                    return $this->createErrorArgument(sprintf(
                        'Cannot create configuration at path "%s"; not writable.',
                        $configFile
                    ));
                }

                $config = [];
                break;
        }

        $class = array_shift($args);

        if (! class_exists($class)) {
            return $this->createErrorArgument(sprintf(
                'Class "%s" does not exist or could not be autoloaded.',
                $class
            ));
        }

        return $this->createArguments(self::COMMAND_DUMP, $configFile, $config, $class);
    }