Commit 65bfd163 by Qiang Xue

Fixes #2646: Added support for specifying hostinfo in the pattern of a URL rule

parent 6d3e60f9
......@@ -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)
......
......@@ -134,6 +134,12 @@ class UrlRule extends Object implements UrlRuleInterface
$this->_template = '';
$this->pattern = '#^$#u';
return;
} elseif (($pos = strpos($this->pattern, '://')) !== 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 . '/';
}
......
......@@ -350,6 +350,18 @@ class UrlRuleTest extends TestCase
['post/index', ['page' => 1, 'tag' => 'a', 'lang' => 'en'], 'http://en.example.com/post/a'],
],
],
[
'with host info in pattern',
[
'pattern' => 'http://<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://en.example.com/post/a'],
],
],
];
}
......@@ -659,6 +671,18 @@ class UrlRuleTest extends TestCase
['post/1/a', false],
],
],
[
'with host info in pattern',
[
'pattern' => 'http://<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],
],
],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment