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
9af15ac8
Commit
9af15ac8
authored
Apr 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored UrlManager.
parent
32ba5122
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
AccessControl.php
framework/web/AccessControl.php
+3
-4
UrlManager.php
framework/web/UrlManager.php
+15
-10
No files found.
framework/web/AccessControl.php
View file @
9af15ac8
...
...
@@ -41,8 +41,8 @@ class AccessControl extends ActionFilter
);
/**
* @var array a list of access rule objects or configuration arrays for creating the rule objects.
* If a rule is specified via a configuration array, it will be merged with [[ruleConfig]]
before
* it is used for creating the rule object.
* If a rule is specified via a configuration array, it will be merged with [[ruleConfig]]
first
*
before
it is used for creating the rule object.
* @see ruleConfig
*/
public
$rules
=
array
();
...
...
@@ -55,8 +55,7 @@ class AccessControl extends ActionFilter
parent
::
init
();
foreach
(
$this
->
rules
as
$i
=>
$rule
)
{
if
(
is_array
(
$rule
))
{
$rule
=
array_merge
(
$this
->
ruleConfig
,
$rule
);
$this
->
rules
[
$i
]
=
Yii
::
createObject
(
$rule
);
$this
->
rules
[
$i
]
=
Yii
::
createObject
(
array_merge
(
$this
->
ruleConfig
,
$rule
));
}
}
}
...
...
framework/web/UrlManager.php
View file @
9af15ac8
...
...
@@ -29,8 +29,15 @@ class UrlManager extends Component
/**
* @var array the rules for creating and parsing URLs when [[enablePrettyUrl]] is true.
* This property is used only if [[enablePrettyUrl]] is true. Each element in the array
* is the configuration of creating a single URL rule whose class by default is [[defaultRuleClass]].
* If you modify this property after the UrlManager object is created, make sure
* is the configuration array for creating a single URL rule. The configuration will
* be merged with [[ruleConfig]] first before it is used for creating the rule object.
*
* A special shortcut format can be used if a rule only specifies [[UrlRule::pattern|pattern]]
* and [[UrlRule::route|route]]: `'pattern' => 'route'`. That is, instead of using a configuration
* array, one can use the key to represent the pattern and the value the corresponding route.
* For example, `'post/<id:\d+>' => 'post/view'`.
*
* Note that if you modify this property after the UrlManager object is created, make sure
* you populate the array with rule objects instead of rule configurations.
*/
public
$rules
=
array
();
...
...
@@ -59,15 +66,16 @@ class UrlManager extends Component
*/
public
$cache
=
'cache'
;
/**
* @var
string the default class name for creating URL rule instance
s
*
when it is not specified in [[rules]]
.
* @var
array the default configuration of URL rules. Individual rule configuration
s
*
specified via [[rules]] will take precedence when the same property of the rule is configured
.
*/
public
$defaultRuleClass
=
'yii\web\UrlRule'
;
public
$ruleConfig
=
array
(
'class'
=>
'yii\web\UrlRule'
,
);
private
$_baseUrl
;
private
$_hostInfo
;
/**
* Initializes UrlManager.
*/
...
...
@@ -101,14 +109,11 @@ class UrlManager extends Component
foreach
(
$this
->
rules
as
$key
=>
$rule
)
{
if
(
!
is_array
(
$rule
))
{
$rule
=
array
(
'class'
=>
$this
->
defaultRuleClass
,
'pattern'
=>
$key
,
'route'
=>
$rule
,
);
}
elseif
(
!
isset
(
$rule
[
'class'
]))
{
$rule
[
'class'
]
=
$this
->
defaultRuleClass
;
}
$rules
[]
=
Yii
::
createObject
(
$rule
);
$rules
[]
=
Yii
::
createObject
(
array_merge
(
$this
->
ruleConfig
,
$rule
)
);
}
$this
->
rules
=
$rules
;
...
...
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