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
a095d383
Commit
a095d383
authored
Feb 27, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored url management.
parent
de19d33d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
Application.php
framework/web/Application.php
+1
-1
UrlManager.php
framework/web/UrlManager.php
+1
-1
UrlRule.php
framework/web/UrlRule.php
+8
-7
UrlRuleTest.php
tests/unit/framework/web/UrlRuleTest.php
+7
-5
No files found.
framework/web/Application.php
View file @
a095d383
...
@@ -32,7 +32,7 @@ class Application extends \yii\base\Application
...
@@ -32,7 +32,7 @@ class Application extends \yii\base\Application
*/
*/
public
function
processRequest
()
public
function
processRequest
()
{
{
$route
=
$this
->
getUrlManager
()
->
parse
Url
(
$this
->
getRequest
());
$route
=
$this
->
getUrlManager
()
->
parse
Request
(
$this
->
getRequest
());
return
$this
->
runAction
(
$route
,
$_GET
);
return
$this
->
runAction
(
$route
,
$_GET
);
}
}
...
...
framework/web/UrlManager.php
View file @
a095d383
...
@@ -119,7 +119,7 @@ class UrlManager extends Component
...
@@ -119,7 +119,7 @@ class UrlManager extends Component
$pathInfo
=
$request
->
pathInfo
;
$pathInfo
=
$request
->
pathInfo
;
/** @var $rule UrlRule */
/** @var $rule UrlRule */
foreach
(
$this
->
rules
as
$rule
)
{
foreach
(
$this
->
rules
as
$rule
)
{
if
((
$result
=
$rule
->
parse
Url
(
$this
,
$pathInfo
))
!==
false
)
{
if
((
$result
=
$rule
->
parse
Request
(
$this
,
$request
))
!==
false
)
{
return
$result
;
return
$result
;
}
}
}
}
...
...
framework/web/UrlRule.php
View file @
a095d383
...
@@ -57,10 +57,10 @@ class UrlRule extends Object
...
@@ -57,10 +57,10 @@ class UrlRule extends Object
*/
*/
public
$verb
;
public
$verb
;
/**
/**
* @var integer a value indicating if this rule should be used for both
URL parsing and
creation,
* @var integer a value indicating if this rule should be used for both
request parsing and URL
creation,
* parsing only, or creation only.
* parsing only, or creation only.
* If not set
, it means the rule is both URL parsing and
creation.
* If not set
or 0, it means the rule is both request parsing and URL
creation.
* If it is [[PARSING_ONLY]], the rule is for
URL
parsing only.
* If it is [[PARSING_ONLY]], the rule is for
request
parsing only.
* If it is [[CREATION_ONLY]], the rule is for URL creation only.
* If it is [[CREATION_ONLY]], the rule is for URL creation only.
*/
*/
public
$mode
;
public
$mode
;
...
@@ -152,22 +152,23 @@ class UrlRule extends Object
...
@@ -152,22 +152,23 @@ class UrlRule extends Object
}
}
/**
/**
* Parses the given
path info
and returns the corresponding route and parameters.
* Parses the given
request
and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param UrlManager $manager the URL manager
* @param
string $pathInfo the path info to be parsed. It should not have slashes at the beginning or the end.
* @param
Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
* If false, it means this rule cannot be used to parse this path info.
*/
*/
public
function
parse
Url
(
$manager
,
$pathInfo
)
public
function
parse
Request
(
$manager
,
$request
)
{
{
if
(
$this
->
mode
===
self
::
CREATION_ONLY
)
{
if
(
$this
->
mode
===
self
::
CREATION_ONLY
)
{
return
false
;
return
false
;
}
}
if
(
$this
->
verb
!==
null
&&
!
in_array
(
\Yii
::
$app
->
getRequest
()
->
verb
,
$this
->
verb
,
true
))
{
if
(
$this
->
verb
!==
null
&&
!
in_array
(
$request
->
verb
,
$this
->
verb
,
true
))
{
return
false
;
return
false
;
}
}
$pathInfo
=
$request
->
pathInfo
;
$suffix
=
(
string
)(
$this
->
suffix
===
null
?
$manager
->
suffix
:
$this
->
suffix
);
$suffix
=
(
string
)(
$this
->
suffix
===
null
?
$manager
->
suffix
:
$this
->
suffix
);
if
(
$suffix
!==
''
&&
$pathInfo
!==
''
)
{
if
(
$suffix
!==
''
&&
$pathInfo
!==
''
)
{
$n
=
strlen
(
$suffix
);
$n
=
strlen
(
$suffix
);
...
...
tests/unit/framework/web/UrlRuleTest.php
View file @
a095d383
...
@@ -4,6 +4,7 @@ namespace yiiunit\framework\web;
...
@@ -4,6 +4,7 @@ namespace yiiunit\framework\web;
use
yii\web\UrlManager
;
use
yii\web\UrlManager
;
use
yii\web\UrlRule
;
use
yii\web\UrlRule
;
use
yii\web\Request
;
class
UrlRuleTest
extends
\yiiunit\TestCase
class
UrlRuleTest
extends
\yiiunit\TestCase
{
{
...
@@ -22,18 +23,19 @@ class UrlRuleTest extends \yiiunit\TestCase
...
@@ -22,18 +23,19 @@ class UrlRuleTest extends \yiiunit\TestCase
}
}
}
}
public
function
testParse
Url
()
public
function
testParse
Request
()
{
{
$manager
=
new
UrlManager
;
$manager
=
new
UrlManager
;
$suites
=
$this
->
getTestsForParseUrl
();
$request
=
new
Request
;
$suites
=
$this
->
getTestsForParseRequest
();
foreach
(
$suites
as
$i
=>
$suite
)
{
foreach
(
$suites
as
$i
=>
$suite
)
{
list
(
$name
,
$config
,
$tests
)
=
$suite
;
list
(
$name
,
$config
,
$tests
)
=
$suite
;
$rule
=
new
UrlRule
(
$config
);
$rule
=
new
UrlRule
(
$config
);
foreach
(
$tests
as
$j
=>
$test
)
{
foreach
(
$tests
as
$j
=>
$test
)
{
$pathInfo
=
$test
[
0
];
$
request
->
pathInfo
=
$test
[
0
];
$route
=
$test
[
1
];
$route
=
$test
[
1
];
$params
=
isset
(
$test
[
2
])
?
$test
[
2
]
:
array
();
$params
=
isset
(
$test
[
2
])
?
$test
[
2
]
:
array
();
$result
=
$rule
->
parse
Url
(
$manager
,
$pathInfo
);
$result
=
$rule
->
parse
Request
(
$manager
,
$request
);
if
(
$route
===
false
)
{
if
(
$route
===
false
)
{
$this
->
assertFalse
(
$result
,
"Test#
$i
-
$j
:
$name
"
);
$this
->
assertFalse
(
$result
,
"Test#
$i
-
$j
:
$name
"
);
}
else
{
}
else
{
...
@@ -328,7 +330,7 @@ class UrlRuleTest extends \yiiunit\TestCase
...
@@ -328,7 +330,7 @@ class UrlRuleTest extends \yiiunit\TestCase
);
);
}
}
protected
function
getTestsForParse
Url
()
protected
function
getTestsForParse
Request
()
{
{
// structure of each test
// structure of each test
// message for the test
// message for the test
...
...
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