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
695fd37e
Commit
695fd37e
authored
Feb 25, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/master'
parents
f0676a80
e31fa4ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
9 deletions
+123
-9
Request.php
framework/web/Request.php
+5
-0
UrlManager.php
framework/web/UrlManager.php
+7
-6
UrlManagerTest.php
tests/unit/framework/web/UrlManagerTest.php
+111
-3
No files found.
framework/web/Request.php
View file @
695fd37e
...
...
@@ -409,6 +409,11 @@ class Request extends \yii\base\Request
return
$this
->
_pathInfo
;
}
public
function
setPathInfo
(
$value
)
{
$this
->
_pathInfo
=
trim
(
$value
,
'/'
);
}
/**
* Resolves the path info part of the currently requested URL.
* A path info refers to the part that is after the entry script and before the question mark (query string).
...
...
framework/web/UrlManager.php
View file @
695fd37e
...
...
@@ -10,7 +10,7 @@
namespace
yii\web
;
use
Yii
;
use
\
yii\base\Component
;
use
yii\base\Component
;
/**
* UrlManager handles HTTP request parsing and creation of URLs based on a set of rules.
...
...
@@ -141,8 +141,11 @@ class UrlManager extends Component
return
array
(
$pathInfo
,
array
());
}
else
{
$route
=
(
string
)
$request
->
getParam
(
$this
->
routeVar
);
return
array
(
$route
,
array
());
$route
=
$request
->
getParam
(
$this
->
routeVar
);
if
(
is_array
(
$route
))
{
$route
=
''
;
}
return
array
((
string
)
$route
,
array
());
}
}
...
...
@@ -230,9 +233,7 @@ class UrlManager extends Component
public
function
getHostInfo
()
{
if
(
$this
->
_hostInfo
===
null
)
{
/** @var $request \yii\web\Request */
$request
=
Yii
::
$app
->
getRequest
();
$this
->
_hostInfo
=
$request
->
getHostInfo
();
$this
->
_hostInfo
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
();
}
return
$this
->
_hostInfo
;
}
...
...
tests/unit/framework/web/UrlManagerTest.php
View file @
695fd37e
<?php
namespace
yiiunit\framework\web
;
use
yii\web\
Application
;
use
yii\web\
Request
;
use
yii\web\UrlManager
;
class
UrlManagerTest
extends
\yiiunit\TestCase
{
public
function
testCreateUrl
()
{
new
Application
(
'test'
,
__DIR__
.
'/../..'
);
// default setting with '/' as base url
$manager
=
new
UrlManager
(
array
(
'baseUrl'
=>
'/'
,
...
...
@@ -50,6 +49,7 @@ class UrlManagerTest extends \yiiunit\TestCase
// pretty URL with rules
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
'cacheID'
=>
false
,
'rules'
=>
array
(
array
(
'pattern'
=>
'post/<id>/<title>'
,
...
...
@@ -66,6 +66,7 @@ class UrlManagerTest extends \yiiunit\TestCase
// pretty URL with rules and suffix
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
'cacheID'
=>
false
,
'rules'
=>
array
(
array
(
'pattern'
=>
'post/<id>/<title>'
,
...
...
@@ -83,11 +84,118 @@ class UrlManagerTest extends \yiiunit\TestCase
public
function
testCreateAbsoluteUrl
()
{
$manager
=
new
UrlManager
(
array
(
'baseUrl'
=>
'/'
,
'hostInfo'
=>
'http://www.example.com'
,
));
$url
=
$manager
->
createAbsoluteUrl
(
'post/view'
,
array
(
'id'
=>
1
,
'title'
=>
'sample post'
));
$this
->
assertEquals
(
'http://www.example.com/?r=post/view&id=1&title=sample+post'
,
$url
);
}
public
function
testParseRequest
()
{
$manager
=
new
UrlManager
;
$request
=
new
Request
;
// default setting without 'r' param
unset
(
$_GET
[
'r'
]);
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
''
,
array
()),
$result
);
// default setting with 'r' param
$_GET
[
'r'
]
=
'site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'site/index'
,
array
()),
$result
);
// default setting with 'r' param as an array
$_GET
[
'r'
]
=
array
(
'site/index'
);
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
''
,
array
()),
$result
);
// pretty URL without rules
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
));
// empty pathinfo
$request
->
pathInfo
=
''
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
''
,
array
()),
$result
);
// normal pathinfo
$request
->
pathInfo
=
'site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'site/index'
,
array
()),
$result
);
// pathinfo with module
$request
->
pathInfo
=
'module/site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'module/site/index'
,
array
()),
$result
);
// pathinfo with trailing slashes
$request
->
pathInfo
=
'module/site/index/'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'module/site/index'
,
array
()),
$result
);
// pretty URL rules
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
'cacheID'
=>
false
,
'rules'
=>
array
(
array
(
'pattern'
=>
'post/<id>/<title>'
,
'route'
=>
'post/view'
,
),
),
));
// matching pathinfo
$request
->
pathInfo
=
'post/123/this+is+sample'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'post/view'
,
array
(
'id'
=>
'123'
,
'title'
=>
'this+is+sample'
)),
$result
);
// matching pathinfo with trailing slashes
$request
->
pathInfo
=
'post/123/this+is+sample/'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'post/view'
,
array
(
'id'
=>
'123'
,
'title'
=>
'this+is+sample'
)),
$result
);
// empty pathinfo
$request
->
pathInfo
=
''
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
''
,
array
()),
$result
);
// normal pathinfo
$request
->
pathInfo
=
'site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'site/index'
,
array
()),
$result
);
// pathinfo with module
$request
->
pathInfo
=
'module/site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'module/site/index'
,
array
()),
$result
);
// pretty URL rules
$manager
=
new
UrlManager
(
array
(
'enablePrettyUrl'
=>
true
,
'suffix'
=>
'.html'
,
'cacheID'
=>
false
,
'rules'
=>
array
(
array
(
'pattern'
=>
'post/<id>/<title>'
,
'route'
=>
'post/view'
,
),
),
));
// matching pathinfo
$request
->
pathInfo
=
'post/123/this+is+sample.html'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'post/view'
,
array
(
'id'
=>
'123'
,
'title'
=>
'this+is+sample'
)),
$result
);
// matching pathinfo without suffix
$request
->
pathInfo
=
'post/123/this+is+sample'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertFalse
(
$result
);
// empty pathinfo
$request
->
pathInfo
=
''
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
''
,
array
()),
$result
);
// normal pathinfo
$request
->
pathInfo
=
'site/index.html'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertEquals
(
array
(
'site/index'
,
array
()),
$result
);
// pathinfo without suffix
$request
->
pathInfo
=
'site/index'
;
$result
=
$manager
->
parseRequest
(
$request
);
$this
->
assertFalse
(
$result
);
}
}
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