Browse Source

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

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
65bfd1633b
  1. 1
      framework/CHANGELOG.md
  2. 6
      framework/web/UrlRule.php
  3. 24
      tests/unit/framework/web/UrlRuleTest.php

1
framework/CHANGELOG.md

@ -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)

6
framework/web/UrlRule.php

@ -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 . '/';
}

24
tests/unit/framework/web/UrlRuleTest.php

@ -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],
],
],
];
}
}

Loading…
Cancel
Save