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
13c6b998
Commit
13c6b998
authored
Nov 26, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1331: Added support for using '*' to specify verb filters for all actions.
parent
1d0bc00c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
8 deletions
+31
-8
VerbFilter.php
framework/yii/web/VerbFilter.php
+31
-8
No files found.
framework/yii/web/VerbFilter.php
View file @
13c6b998
...
...
@@ -51,6 +51,20 @@ class VerbFilter extends Behavior
* you add an entry with the action id as array key and an array of
* allowed methods (e.g. GET, HEAD, PUT) as the value.
* If an action is not listed all request methods are considered allowed.
*
* You can use '*' to stand for all actions. When an action is explicitly
* specified, it takes precedence over the specification given by '*'.
*
* For example,
*
* ~~~
* [
* 'create' => ['get', 'post'],
* 'update' => ['get', 'put', 'post'],
* 'delete' => ['post', 'delete'],
* '*' => ['get'],
* ]
* ~~~
*/
public
$actions
=
[];
...
...
@@ -73,15 +87,24 @@ class VerbFilter extends Behavior
{
$action
=
$event
->
action
->
id
;
if
(
isset
(
$this
->
actions
[
$action
]))
{
$verb
=
Yii
::
$app
->
getRequest
()
->
getMethod
();
$allowed
=
array_map
(
'strtoupper'
,
$this
->
actions
[
$action
]);
if
(
!
in_array
(
$verb
,
$allowed
))
{
$event
->
isValid
=
false
;
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7
Yii
::
$app
->
getResponse
()
->
getHeaders
()
->
set
(
'Allow'
,
implode
(
', '
,
$allowed
));
throw
new
HttpException
(
405
,
'Method Not Allowed. This url can only handle the following request methods: '
.
implode
(
', '
,
$allowed
));
}
$verbs
=
$this
->
actions
[
$action
];
}
elseif
(
isset
(
$this
->
actions
[
'*'
]))
{
$verbs
=
$this
->
actions
[
'*'
];
}
else
{
return
$event
->
isValid
;
}
$verb
=
Yii
::
$app
->
getRequest
()
->
getMethod
();
$allowed
=
array_map
(
'strtoupper'
,
$verbs
);
if
(
!
in_array
(
$verb
,
array_map
(
'strtoupper'
,
$verbs
)))
{
$event
->
isValid
=
false
;
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7
Yii
::
$app
->
getResponse
()
->
getHeaders
()
->
set
(
'Allow'
,
implode
(
', '
,
$allowed
));
throw
new
HttpException
(
405
,
Yii
::
t
(
'yii'
,
'Method Not Allowed. This url can only handle the following request methods: {methods}.'
,
[
'methods'
=>
implode
(
', '
,
$allowed
),
]));
}
return
$event
->
isValid
;
}
}
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