Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9e948ccd
Commit
9e948ccd
authored
May 16, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added UrlRule::host.
parent
b6fffeb0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
15 deletions
+19
-15
UrlManagerTest.php
tests/unit/framework/web/UrlManagerTest.php
+2
-1
UrlRuleTest.php
tests/unit/framework/web/UrlRuleTest.php
+4
-2
UrlManager.php
yii/web/UrlManager.php
+1
-1
UrlRule.php
yii/web/UrlRule.php
+12
-11
No files found.
tests/unit/framework/web/UrlManagerTest.php
View file @
9e948ccd
...
...
@@ -92,8 +92,9 @@ class UrlManagerTest extends \yiiunit\TestCase
'cache'
=>
null
,
'rules'
=>
array
(
array
(
'pattern'
=>
'
http://<lang:en|fr>.example.com/
post/<id>/<title>'
,
'pattern'
=>
'post/<id>/<title>'
,
'route'
=>
'post/view'
,
'host'
=>
'http://<lang:en|fr>.example.com'
,
),
),
'baseUrl'
=>
'/test'
,
...
...
tests/unit/framework/web/UrlRuleTest.php
View file @
9e948ccd
...
...
@@ -330,9 +330,10 @@ class UrlRuleTest extends \yiiunit\TestCase
array
(
'with host info'
,
array
(
'pattern'
=>
'
http://<lang:(en|fr)>.example.com/
post/<page:\d+>/<tag>'
,
'pattern'
=>
'post/<page:\d+>/<tag>'
,
'route'
=>
'post/index'
,
'defaults'
=>
array
(
'page'
=>
1
),
'host'
=>
'http://<lang:en|fr>.example.com'
,
),
array
(
array
(
'post/index'
,
array
(
'page'
=>
1
,
'tag'
=>
'a'
),
false
),
...
...
@@ -625,8 +626,9 @@ class UrlRuleTest extends \yiiunit\TestCase
array
(
'with host info'
,
array
(
'pattern'
=>
'
http://<lang:en|fr>.example.com/
post/<page:\d+>'
,
'pattern'
=>
'post/<page:\d+>'
,
'route'
=>
'post/index'
,
'host'
=>
'http://<lang:en|fr>.example.com'
,
),
array
(
array
(
'post/1'
,
'post/index'
,
array
(
'page'
=>
'1'
,
'lang'
=>
'en'
)),
...
...
yii/web/UrlManager.php
View file @
9e948ccd
...
...
@@ -183,7 +183,7 @@ class UrlManager extends Component
/** @var $rule UrlRule */
foreach
(
$this
->
rules
as
$rule
)
{
if
((
$url
=
$rule
->
createUrl
(
$this
,
$route
,
$params
))
!==
false
)
{
if
(
$rule
->
h
asHostInfo
)
{
if
(
$rule
->
h
ost
!==
null
)
{
if
(
$baseUrl
!==
''
&&
(
$pos
=
strpos
(
$url
,
'/'
,
8
))
!==
false
)
{
return
substr
(
$url
,
0
,
$pos
)
.
$baseUrl
.
substr
(
$url
,
$pos
);
}
else
{
...
...
yii/web/UrlRule.php
View file @
9e948ccd
...
...
@@ -28,10 +28,16 @@ class UrlRule extends Object
const
CREATION_ONLY
=
2
;
/**
* @var string the pattern used to parse and create URLs.
* @var string the pattern used to parse and create the path info part of a URL.
* @see host
*/
public
$pattern
;
/**
* @var string the pattern used to parse and create the host info part of a URL.
* @see pattern
*/
public
$host
;
/**
* @var string the route to the controller action
*/
public
$route
;
...
...
@@ -62,11 +68,6 @@ class UrlRule extends Object
* If it is [[CREATION_ONLY]], the rule is for URL creation only.
*/
public
$mode
;
/**
* @var boolean whether this URL rule contains the host info part.
* This property is set after the URL rule is parsed.
*/
public
$hasHostInfo
;
/**
* @var string the template for generating a new URL. This is derived from [[pattern]] and is used in generating URL.
...
...
@@ -108,9 +109,9 @@ class UrlRule extends Object
$this
->
pattern
=
trim
(
$this
->
pattern
,
'/'
);
$this
->
hasHostInfo
=
!
strncasecmp
(
$this
->
pattern
,
'http://'
,
7
)
||
!
strncasecmp
(
$this
->
pattern
,
'https://'
,
8
);
if
(
$this
->
pattern
===
''
)
{
if
(
$this
->
host
!==
null
)
{
$this
->
pattern
=
rtrim
(
$this
->
host
,
'/'
)
.
rtrim
(
'/'
.
$this
->
pattern
,
'/'
)
.
'/'
;
}
else
if
(
$this
->
pattern
===
''
)
{
$this
->
_template
=
''
;
$this
->
pattern
=
'#^$#u'
;
return
;
...
...
@@ -190,7 +191,7 @@ class UrlRule extends Object
}
}
if
(
$this
->
h
asHostInfo
)
{
if
(
$this
->
h
ost
!==
null
)
{
$pathInfo
=
strtolower
(
$request
->
getHostInfo
())
.
'/'
.
$pathInfo
;
}
...
...
@@ -279,7 +280,7 @@ class UrlRule extends Object
}
$url
=
trim
(
strtr
(
$this
->
_template
,
$tr
),
'/'
);
if
(
$this
->
h
asHostInfo
)
{
if
(
$this
->
h
ost
!==
null
)
{
$pos
=
strpos
(
$url
,
'/'
,
8
);
if
(
$pos
!==
false
)
{
$url
=
substr
(
$url
,
0
,
$pos
)
.
preg_replace
(
'#/+#'
,
'/'
,
substr
(
$url
,
$pos
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment