Skip to content

Commit

Permalink
Fixes #2646: Added support for specifying hostinfo in the pattern of …
Browse files Browse the repository at this point in the history
…a URL rule
  • Loading branch information
qiangxue committed Mar 7, 2014
1 parent 6d3e60f commit 65bfd16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Yii Framework 2 Change Log
- Enh #2499: Added ability to downgrade migrations by their absolute apply time (resurtm, gorcer)
- Enh #2525: Added support for formatting file sizes with `yii\base\Formatter` (VinceG)
- Enh #2526: Allow for null values in batchInsert (skotos)
- Enh #2646: Added support for specifying hostinfo in the pattern of a URL rule (qiangxue)
- Enh: Added support for using arrays as option values for console commands (qiangxue)
- Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark)
- Enh: Added `Widget::autoIdPrefix` to support prefixing automatically generated widget IDs (qiangxue)
Expand Down
6 changes: 6 additions & 0 deletions framework/web/UrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ public function init()
$this->_template = '';
$this->pattern = '#^$#u';
return;
} elseif (($pos = strpos($this->pattern, ':https://')) !== false) {
if (($pos2 = strpos($this->pattern, '/', $pos + 3)) !== false) {
$this->host = substr($this->pattern, 0, $pos2);
} else {
$this->host = $this->pattern;
}
} else {
$this->pattern = '/' . $this->pattern . '/';
}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/framework/web/UrlRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ protected function getTestsForCreateUrl()
['post/index', ['page' => 1, 'tag' => 'a', 'lang' => 'en'], 'http:https://en.example.com/post/a'],
],
],
[
'with host info in pattern',
[
'pattern' => 'http:https://<lang:en|fr>.example.com/post/<page:\d+>/<tag>',
'route' => 'post/index',
'defaults' => ['page' => 1],
],
[
['post/index', ['page' => 1, 'tag' => 'a'], false],
['post/index', ['page' => 1, 'tag' => 'a', 'lang' => 'en'], 'http:https://en.example.com/post/a'],
],
],
];
}

Expand Down Expand Up @@ -659,6 +671,18 @@ protected function getTestsForParseRequest()
['post/1/a', false],
],
],
[
'with host info in pattern',
[
'pattern' => 'http:https://<lang:en|fr>.example.com/post/<page:\d+>',
'route' => 'post/index',
],
[
['post/1', 'post/index', ['page' => '1', 'lang' => 'en']],
['post/a', false],
['post/1/a', false],
],
],
];
}
}

0 comments on commit 65bfd16

Please sign in to comment.