根据规则扫描文件路径

@param string $path     扫描路径
@param null   $pattern  扫描匹配规则
@param string $strategy 扫描算法
@return array
@throws \InvalidArgumentException
340419
public static function glob(string $path, $pattern = null, $strategy = self::SCAN_DFS): array
    {
        if (! is_dir($path) || ! $pattern) {
            throw new \InvalidArgumentException('Invalid $path or $pattern for DirHelper::glob');
        }

        $files = self::scan($path, $strategy);
        $result = [];
        foreach ($files as $file) {
            if (false === self::matchPattern($pattern, $file)) {
                continue;
            }
            $result[] = $file;
        }
        return $result;
    }
913619
private function findAction(&$pathInfo, &$path)
    {
        if ($pathInfo[0] == '/' && !isset($pathInfo[1])) {
            $pathInfo = explode('/', trim(Config::get('url_default_action'), '/'));
        }
        $controllerPath = $controllerName = '';

        $routeAppHierarchy = Config::get('route_app_hierarchy', 1);
        $i = 0;

        $controllerSuffix = Config::get('controller_suffix');
        while ($dir = array_shift($pathInfo)) {
            $controllerName = ucfirst($dir);
            $controller = Cml::getApplicationDir('apps_path') . $path . Cml::getApplicationDir('app_controller_path_name') . '/'
                . $controllerPath . $controllerName . $controllerSuffix . '.php';

            if ($i >= $routeAppHierarchy && is_file($controller)) {
                self::$urlParams['controller'] = $controllerPath . $controllerName;
                break;
            } else {
                if ($i++ < $routeAppHierarchy) {
                    $path .= $dir . '/';
                } else {
                    $controllerPath .= $dir . '/';
                }
            }
        }
        empty(self::$urlParams['controller']) && self::$urlParams['controller'] = $controllerName;//用于404的时候挂载插件用
        self::$urlParams['action'] = array_shift($pathInfo);
    }
196549
public function rm($pattern = null) {
        if($pattern) {
            $files = $this->options['path'] . $pattern;
        }
        else {
            $files = $this->options['path'] . '/*' . $this->options['ext'];
        }
        return array_map('unlink', glob($files));
    }
548674
private function matchByRegex(string $pattern, string $path): array
    {
        $isPatternMatched = (bool) \preg_match_all("~^$pattern$~", $path, $matches);

        if (!$isPatternMatched) {
            return [$isPatternMatched, []];
        }

        foreach ($matches as $k => $match) {
            $match = \array_shift($match);
            if (\is_int($k) || empty($match)) {
                unset($matches[$k]);
                continue;
            }
            $matches[$k] = $match;
        }

        return [$isPatternMatched, $matches];
    }
711010
public function getStrategy($strategy, $concrete = null, $options = [])
    {
        // Try to build the strategy
        $strategy = $this->builder->buildStrategy($strategy, $concrete);
        if (!$strategy || !$strategy->isExecutable()) {
            return;
        }

        // Configure strategy
        if ($options || $this->options) {
            $options = array_replace((array) $options, $strategy->getOptions(), $this->options);
            $strategy = $strategy->setOptions($options);
        }

        return $this->explainer->displayBelow(function () use ($strategy) {
            return $strategy->displayStatus();
        });
    }
342525
public static function lookupByPath($path)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException('Argument "path" cannot be empty');
        }

        foreach (self::$methods_config as $key => $val) {
            if ($val['path'] === $path) {
                return $val;
            }
        }

        return null;
    }
854564
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $value, bool $caseSensitive)
    {
        $wrapCase = $this->createWrapCase($caseSensitive);
        $valueParameter = $queryNameGenerator->generateParameterName($field);

        switch ($strategy) {
            case null:
            case self::STRATEGY_EXACT:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' = '.$wrapCase(':%s'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_PARTIAL:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_START:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(:%s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_END:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%s.%s').' LIKE '.$wrapCase('CONCAT(\'%%\', :%s)'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            case self::STRATEGY_WORD_START:
                $queryBuilder
                    ->andWhere(sprintf($wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(:%3$s, \'%%\')').' OR '.$wrapCase('%1$s.%2$s').' LIKE '.$wrapCase('CONCAT(\'%% \', :%3$s, \'%%\')'), $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);
                break;
            default:
                throw new InvalidArgumentException(sprintf('strategy %s does not exist.', $strategy));
        }
    }
1153734
protected function getFileIterator($path, $pattern = '/^.+\.php$/')
    {
        if (is_dir($path)) {
            return new \RegexIterator(new \DirectoryIterator($path), $pattern, \RegexIterator::GET_MATCH);
        }
        if (is_file($path) && 1 === preg_match($pattern, $path)) {
            return [new \SplFileInfo($path)];
        }
        return [];
    }
828727
public function deleteConditionStrategy(string $strategy, array $parameters = []): Model
    {
        if ( ! array_has($this->main, 'delete_condition')) {
            $this->main['delete_condition'] = '';
        }

        $this->main['delete_condition'] .= ($this->main['delete_condition'] ? '|' : '') . $strategy;

        if (count($parameters)) {

            $serializedParameters = implode(
                ',',
                array_map(
                    function ($value) {
                        return (string) $value;
                    },
                    $parameters
                )
            );

            $this->main['delete_condition'] .= ':' . $serializedParameters;
        }

        return $this;
    }
423806
public function getFiles(string $location, string $pattern = null, Finder $finder = null): array
    {
        $finder = $finder ?? new Finder();
        $finder->files()->in($location);

        if (!empty($pattern)) {
            $finder->name($pattern);
        }

        $result = [];
        foreach ($finder->getIterator() as $file) {
            $result[] = $this->normalizePath((string)$file);
        }

        return $result;
    }
1142205
public static function decode($strategy, $value)
	{
		switch ($strategy) {
			case 'explode':
				return explode(',', $value);
			case 'json':
				return json_decode($value);
			case 'serialize':
				return unserialize($value);
		}

		return $value;
	}
1240180
public function addRule($rule, $route, $method = '*', $option = [], $pattern = [])
    {
        // 读取路由标识
        if (is_array($rule)) {
            $name = $rule[0];
            $rule = $rule[1];
        } elseif (is_string($route)) {
            $name = $route;
        } else {
            $name = null;
        }

        $method = strtolower($method);

        if ('/' === $rule || '' === $rule) {
            // 首页自动完整匹配
            $rule .= '$';
        }

        // 创建路由规则实例
        $ruleItem = new RuleItem($this->router, $this, $name, $rule, $route, $method, $option, $pattern);

        if (!empty($option['cross_domain'])) {
            $this->router->setCrossDomainRule($ruleItem, $method);
        }

        $this->addRuleItem($ruleItem, $method);

        return $ruleItem;
    }
14838
public function get($strategy = null)
    {
        if(!$strategy) {
            return $this->defaultStrategy;
        }

        $strategy = $this->getOrNull($strategy);

        if(!$strategy) {
            throw new UnknownStrategyException;
        }

        return $strategy;
    }
412452
public function controller($rule, $route = '', array $option = [], array $pattern = [])
    {
        $group = new RuleGroup($this, $this->group, $rule, null, $option, $pattern);

        foreach ($this->methodPrefix as $type => $val) {
            $group->addRule('<action>', $val . '<action>', $type);
        }

        return $group->prefix($route . '/');
    }
13303
protected function prepareStrategies()
    {
        $associations = $this->metadata->getAssociationNames();

        foreach ($associations as $association) {
            if ($this->metadata->isCollectionValuedAssociation($association)) {
                // Add a strategy if the association has none set by user
                if (! $this->hasStrategy($association)) {
                    if ($this->byValue) {
                        $strategyClassName = $this->getDefaultByValueStrategy();
                    } else {
                        $strategyClassName = $this->getDefaultByReferenceStrategy();
                    }

                    $this->addStrategy($association, new $strategyClassName());
                }

                $strategy = $this->getStrategy($association);

                if (! $strategy instanceof Strategy\AbstractCollectionStrategy) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'Strategies used for collections valued associations must inherit from '
                            . 'Strategy\AbstractCollectionStrategy, %s given',
                            get_class($strategy)
                        )
                    );
                }

                $strategy->setCollectionName($association)
                         ->setClassMetadata($this->metadata);
            }
        }
    }
494296
protected static function convertPartialMatchStrategy($strategy)
  {
    /** @var RMatchStrategy $convertedStrategy */
    $convertedStrategy = null;
    if (!empty($strategy)) {
      $rules = $strategy->getRules();
      if (!empty($rules)) {
        $convertedStrategy = new RMatchStrategy();
        /** @var MPartialMatchRule $r */
        foreach ($rules as $r) {
          array_push($rules, Query::convertPartialMatchRule($r));
        }
        $strategy->setRules($rules);
      }
    }
    return $convertedStrategy;
  }
144367
public function loadFromFile($pattern)
    {
        if (isset($this->files[$pattern])) {
            return $this;
        }

        $file = sprintf($pattern, $this->locale);
        if (!is_file($file)) {
            $defaultFile = sprintf($pattern, $this->defaultLocale);
            if (!is_file($defaultFile)) {
                throw new \InvalidArgumentException(sprintf('File "%s" and "%s" not found or not readable', $file, $defaultFile));
            } else {
                $file = $defaultFile;
            }
        }

        $this->files[$pattern] = true;

        return $this->loadFromArray(require $file);
    }