1 | <?php |
||
48 | class GroupUrlRule extends CompositeUrlRule |
||
49 | { |
||
50 | /** |
||
51 | * @var array the rules contained within this composite rule. Please refer to [[UrlManager::rules]] |
||
52 | * for the format of this property. |
||
53 | * @see prefix |
||
54 | * @see routePrefix |
||
55 | */ |
||
56 | public $rules = []; |
||
57 | /** |
||
58 | * @var string the prefix for the pattern part of every rule declared in [[rules]]. |
||
59 | * The prefix and the pattern will be separated with a slash. |
||
60 | */ |
||
61 | public $prefix; |
||
62 | /** |
||
63 | * @var string the prefix for the route part of every rule declared in [[rules]]. |
||
64 | * The prefix and the route will be separated with a slash. |
||
65 | * If this property is not set, it will take the value of [[prefix]]. |
||
66 | */ |
||
67 | public $routePrefix; |
||
68 | /** |
||
69 | * @var array the default configuration of URL rules. Individual rule configurations |
||
70 | * specified via [[rules]] will take precedence when the same property of the rule is configured. |
||
71 | */ |
||
72 | public $ruleConfig = ['class' => 'yii\web\UrlRule']; |
||
73 | |||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 2 | public function init() |
|
84 | |||
85 | /** |
||
86 | * @inheritdoc |
||
87 | */ |
||
88 | 2 | protected function createRules() |
|
89 | { |
||
90 | 2 | $rules = []; |
|
91 | 2 | foreach ($this->rules as $key => $rule) { |
|
92 | 2 | if (!is_array($rule)) { |
|
93 | $rule = [ |
||
94 | 2 | 'pattern' => ltrim($this->prefix . '/' . $key, '/'), |
|
95 | 2 | 'route' => ltrim($this->routePrefix . '/' . $rule, '/'), |
|
96 | ]; |
||
97 | 1 | } elseif (isset($rule['pattern'], $rule['route'])) { |
|
98 | 1 | $rule['pattern'] = ltrim($this->prefix . '/' . $rule['pattern'], '/'); |
|
99 | 1 | $rule['route'] = ltrim($this->routePrefix . '/' . $rule['route'], '/'); |
|
100 | } |
||
101 | |||
102 | 2 | $rule = Yii::createObject(array_merge($this->ruleConfig, $rule)); |
|
103 | 2 | if (!$rule instanceof UrlRuleInterface) { |
|
104 | throw new InvalidConfigException('URL rule class must implement UrlRuleInterface.'); |
||
105 | } |
||
106 | 2 | $rules[] = $rule; |
|
107 | } |
||
108 | 2 | return $rules; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 1 | public function parseRequest($manager, $request) |
|
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | 1 | public function createUrl($manager, $route, $params) |
|
136 | } |
||
137 |