yii\web\UrlManager::buildRules PHP Method

buildRules() protected method

Builds URL rule objects from the given rule declarations.
protected buildRules ( array $rules ) : yii\web\UrlRuleInterface[]
$rules array the rule declarations. Each array element represents a single rule declaration. Please refer to [[rules]] for the acceptable rule formats.
return yii\web\UrlRuleInterface[] the rule objects built from the given rule declarations
    protected function buildRules($rules)
    {
        $compiledRules = [];
        $verbs = 'GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS';
        foreach ($rules as $key => $rule) {
            if (is_string($rule)) {
                $rule = ['route' => $rule];
                if (preg_match("/^((?:({$verbs}),)*({$verbs}))\\s+(.*)\$/", $key, $matches)) {
                    $rule['verb'] = explode(',', $matches[1]);
                    // rules that do not apply for GET requests should not be use to create urls
                    if (!in_array('GET', $rule['verb'])) {
                        $rule['mode'] = UrlRule::PARSING_ONLY;
                    }
                    $key = $matches[4];
                }
                $rule['pattern'] = $key;
            }
            if (is_array($rule)) {
                $rule = Yii::createObject(array_merge($this->ruleConfig, $rule));
            }
            if (!$rule instanceof UrlRuleInterface) {
                throw new InvalidConfigException('URL rule class must implement UrlRuleInterface.');
            }
            $compiledRules[] = $rule;
        }
        return $compiledRules;
    }