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
0d669f5e
Commit
0d669f5e
authored
Jan 21, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored params methods in Request
issue #2043
parent
65179b10
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
91 additions
and
116 deletions
+91
-116
DbPanel.php
extensions/debug/panels/DbPanel.php
+1
-1
LogPanel.php
extensions/debug/panels/LogPanel.php
+1
-1
ProfilingPanel.php
extensions/debug/panels/ProfilingPanel.php
+1
-1
CHANGELOG.md
framework/CHANGELOG.md
+3
-1
Pagination.php
framework/data/Pagination.php
+2
-2
Sort.php
framework/data/Sort.php
+2
-2
BaseHtml.php
framework/helpers/BaseHtml.php
+1
-1
Request.php
framework/web/Request.php
+79
-106
UrlManager.php
framework/web/UrlManager.php
+1
-1
No files found.
extensions/debug/panels/DbPanel.php
View file @
0d669f5e
...
@@ -53,7 +53,7 @@ class DbPanel extends Panel
...
@@ -53,7 +53,7 @@ class DbPanel extends Panel
public
function
getDetail
()
public
function
getDetail
()
{
{
$searchModel
=
new
Db
();
$searchModel
=
new
Db
();
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
(),
$this
->
getModels
());
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
QueryParams
(),
$this
->
getModels
());
return
Yii
::
$app
->
view
->
render
(
'panels/db/detail'
,
[
return
Yii
::
$app
->
view
->
render
(
'panels/db/detail'
,
[
'panel'
=>
$this
,
'panel'
=>
$this
,
...
...
extensions/debug/panels/LogPanel.php
View file @
0d669f5e
...
@@ -39,7 +39,7 @@ class LogPanel extends Panel
...
@@ -39,7 +39,7 @@ class LogPanel extends Panel
public
function
getDetail
()
public
function
getDetail
()
{
{
$searchModel
=
new
Log
();
$searchModel
=
new
Log
();
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
(),
$this
->
getModels
());
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
QueryParams
(),
$this
->
getModels
());
return
Yii
::
$app
->
view
->
render
(
'panels/log/detail'
,
[
return
Yii
::
$app
->
view
->
render
(
'panels/log/detail'
,
[
'dataProvider'
=>
$dataProvider
,
'dataProvider'
=>
$dataProvider
,
...
...
extensions/debug/panels/ProfilingPanel.php
View file @
0d669f5e
...
@@ -42,7 +42,7 @@ class ProfilingPanel extends Panel
...
@@ -42,7 +42,7 @@ class ProfilingPanel extends Panel
public
function
getDetail
()
public
function
getDetail
()
{
{
$searchModel
=
new
Profile
();
$searchModel
=
new
Profile
();
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
(),
$this
->
getModels
());
$dataProvider
=
$searchModel
->
search
(
Yii
::
$app
->
request
->
get
QueryParams
(),
$this
->
getModels
());
return
Yii
::
$app
->
view
->
render
(
'panels/profile/detail'
,
[
return
Yii
::
$app
->
view
->
render
(
'panels/profile/detail'
,
[
'panel'
=>
$this
,
'panel'
=>
$this
,
...
...
framework/CHANGELOG.md
View file @
0d669f5e
...
@@ -96,6 +96,9 @@ Yii Framework 2 Change Log
...
@@ -96,6 +96,9 @@ Yii Framework 2 Change Log
-
Chg #1821: Changed default values for yii
\d
b
\C
onnection username and password to null (cebe)
-
Chg #1821: Changed default values for yii
\d
b
\C
onnection username and password to null (cebe)
-
Chg #1844:
`Response::sendFile()`
and other file sending methods will not send the response (qiangxue)
-
Chg #1844:
`Response::sendFile()`
and other file sending methods will not send the response (qiangxue)
-
Chg #1852: DbConnection::tablePrefix default value now 'tbl_' (creocoder)
-
Chg #1852: DbConnection::tablePrefix default value now 'tbl_' (creocoder)
-
Chg #2043: Renamed
`yii\web\Request::acceptedLanguages`
to
`acceptableLanguages`
(qiangxue)
-
Chg #2043: Removed
`yii\web\Request::getPut()`
,
`getDelete()`
,
`getPatch()`
in favor of
`getBodyParam()`
(cebe)
-
Chg #2043: Renamed
`yii\web\Request::get()`
to
`getQueryParams()`
and
`getRestParams()`
to
`getBodyParams()`
(cebe)
-
Chg #2057: AutoTimestamp attributes defaults changed from
`create_time`
and
`update_time`
to
`created_at`
and
`updated_at`
(creocoder)
-
Chg #2057: AutoTimestamp attributes defaults changed from
`create_time`
and
`update_time`
to
`created_at`
and
`updated_at`
(creocoder)
-
Chg #2063: Removed
`yii\web\Request::acceptTypes`
and renamed
`yii\web\Request::acceptedContentTypes`
to
`acceptableContentTypes`
(qiangxue)
-
Chg #2063: Removed
`yii\web\Request::acceptTypes`
and renamed
`yii\web\Request::acceptedContentTypes`
to
`acceptableContentTypes`
(qiangxue)
-
Chg: Renamed
`yii\jui\Widget::clientEventsMap`
to
`clientEventMap`
(qiangxue)
-
Chg: Renamed
`yii\jui\Widget::clientEventsMap`
to
`clientEventMap`
(qiangxue)
...
@@ -108,7 +111,6 @@ Yii Framework 2 Change Log
...
@@ -108,7 +111,6 @@ Yii Framework 2 Change Log
-
Chg: Changed the directory structure according to PSR-4. You have to update your application
`index.php`
,
-
Chg: Changed the directory structure according to PSR-4. You have to update your application
`index.php`
,
`index-test.php`
and
`yii`
files to point to the new location of
`Yii.php`
(qiangxue, cebe)
`index-test.php`
and
`yii`
files to point to the new location of
`Yii.php`
(qiangxue, cebe)
-
Chg: Advanced app template: moved database connection DSN, login and password to
`-local`
config not to expose it to VCS (samdark)
-
Chg: Advanced app template: moved database connection DSN, login and password to
`-local`
config not to expose it to VCS (samdark)
-
Chg: Renamed
`yii\web\Request::acceptedLanguages`
to
`acceptableLanguages`
(qiangxue)
-
New #66:
[
Auth client library
](
https://github.com/yiisoft/yii2-authclient
)
OpenId, OAuth1, OAuth2 clients (klimov-paul)
-
New #66:
[
Auth client library
](
https://github.com/yiisoft/yii2-authclient
)
OpenId, OAuth1, OAuth2 clients (klimov-paul)
-
New #1393:
[
Codeception testing framework integration
](
https://github.com/yiisoft/yii2-codeception
)
(
Ragazzo
)
-
New #1393:
[
Codeception testing framework integration
](
https://github.com/yiisoft/yii2-codeception
)
(
Ragazzo
)
-
New #1438:
[
MongoDB integration
](
https://github.com/yiisoft/yii2-mongodb
)
ActiveRecord and Query (klimov-paul)
-
New #1438:
[
MongoDB integration
](
https://github.com/yiisoft/yii2-mongodb
)
ActiveRecord and Query (klimov-paul)
...
...
framework/data/Pagination.php
View file @
0d669f5e
...
@@ -141,7 +141,7 @@ class Pagination extends Object
...
@@ -141,7 +141,7 @@ class Pagination extends Object
if
(
$this
->
_page
===
null
||
$recalculate
)
{
if
(
$this
->
_page
===
null
||
$recalculate
)
{
if
((
$params
=
$this
->
params
)
===
null
)
{
if
((
$params
=
$this
->
params
)
===
null
)
{
$request
=
Yii
::
$app
->
getRequest
();
$request
=
Yii
::
$app
->
getRequest
();
$params
=
$request
instanceof
Request
?
$request
->
get
()
:
[];
$params
=
$request
instanceof
Request
?
$request
->
get
QueryParams
()
:
[];
}
}
if
(
isset
(
$params
[
$this
->
pageVar
])
&&
is_scalar
(
$params
[
$this
->
pageVar
]))
{
if
(
isset
(
$params
[
$this
->
pageVar
])
&&
is_scalar
(
$params
[
$this
->
pageVar
]))
{
$this
->
_page
=
(
int
)
$params
[
$this
->
pageVar
]
-
1
;
$this
->
_page
=
(
int
)
$params
[
$this
->
pageVar
]
-
1
;
...
@@ -183,7 +183,7 @@ class Pagination extends Object
...
@@ -183,7 +183,7 @@ class Pagination extends Object
{
{
if
((
$params
=
$this
->
params
)
===
null
)
{
if
((
$params
=
$this
->
params
)
===
null
)
{
$request
=
Yii
::
$app
->
getRequest
();
$request
=
Yii
::
$app
->
getRequest
();
$params
=
$request
instanceof
Request
?
$request
->
get
()
:
[];
$params
=
$request
instanceof
Request
?
$request
->
get
QueryParams
()
:
[];
}
}
if
(
$page
>
0
||
$page
>=
0
&&
$this
->
forcePageVar
)
{
if
(
$page
>
0
||
$page
>=
0
&&
$this
->
forcePageVar
)
{
$params
[
$this
->
pageVar
]
=
$page
+
1
;
$params
[
$this
->
pageVar
]
=
$page
+
1
;
...
...
framework/data/Sort.php
View file @
0d669f5e
...
@@ -245,7 +245,7 @@ class Sort extends Object
...
@@ -245,7 +245,7 @@ class Sort extends Object
$this
->
_attributeOrders
=
[];
$this
->
_attributeOrders
=
[];
if
((
$params
=
$this
->
params
)
===
null
)
{
if
((
$params
=
$this
->
params
)
===
null
)
{
$request
=
Yii
::
$app
->
getRequest
();
$request
=
Yii
::
$app
->
getRequest
();
$params
=
$request
instanceof
Request
?
$request
->
get
()
:
[];
$params
=
$request
instanceof
Request
?
$request
->
get
QueryParams
()
:
[];
}
}
if
(
isset
(
$params
[
$this
->
sortVar
])
&&
is_scalar
(
$params
[
$this
->
sortVar
]))
{
if
(
isset
(
$params
[
$this
->
sortVar
])
&&
is_scalar
(
$params
[
$this
->
sortVar
]))
{
$attributes
=
explode
(
$this
->
separators
[
0
],
$params
[
$this
->
sortVar
]);
$attributes
=
explode
(
$this
->
separators
[
0
],
$params
[
$this
->
sortVar
]);
...
@@ -341,7 +341,7 @@ class Sort extends Object
...
@@ -341,7 +341,7 @@ class Sort extends Object
{
{
if
((
$params
=
$this
->
params
)
===
null
)
{
if
((
$params
=
$this
->
params
)
===
null
)
{
$request
=
Yii
::
$app
->
getRequest
();
$request
=
Yii
::
$app
->
getRequest
();
$params
=
$request
instanceof
Request
?
$request
->
get
()
:
[];
$params
=
$request
instanceof
Request
?
$request
->
get
QueryParams
()
:
[];
}
}
$params
[
$this
->
sortVar
]
=
$this
->
createSortVar
(
$attribute
);
$params
[
$this
->
sortVar
]
=
$this
->
createSortVar
(
$attribute
);
$route
=
$this
->
route
===
null
?
Yii
::
$app
->
controller
->
getRoute
()
:
$this
->
route
;
$route
=
$this
->
route
===
null
?
Yii
::
$app
->
controller
->
getRoute
()
:
$this
->
route
;
...
...
framework/helpers/BaseHtml.php
View file @
0d669f5e
...
@@ -237,7 +237,7 @@ class BaseHtml
...
@@ -237,7 +237,7 @@ class BaseHtml
if
(
$request
instanceof
Request
)
{
if
(
$request
instanceof
Request
)
{
if
(
strcasecmp
(
$method
,
'get'
)
&&
strcasecmp
(
$method
,
'post'
))
{
if
(
strcasecmp
(
$method
,
'get'
)
&&
strcasecmp
(
$method
,
'post'
))
{
// simulate PUT, DELETE, etc. via POST
// simulate PUT, DELETE, etc. via POST
$hiddenInputs
[]
=
static
::
hiddenInput
(
$request
->
rest
Var
,
$method
);
$hiddenInputs
[]
=
static
::
hiddenInput
(
$request
->
method
Var
,
$method
);
$method
=
'post'
;
$method
=
'post'
;
}
}
if
(
$request
->
enableCsrfValidation
&&
!
strcasecmp
(
$method
,
'post'
))
{
if
(
$request
->
enableCsrfValidation
&&
!
strcasecmp
(
$method
,
'post'
))
{
...
...
framework/web/Request.php
View file @
0d669f5e
...
@@ -9,8 +9,6 @@ namespace yii\web;
...
@@ -9,8 +9,6 @@ namespace yii\web;
use
Yii
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidParamException
;
use
yii\helpers\Json
;
use
yii\helpers\Security
;
use
yii\helpers\Security
;
use
yii\helpers\StringHelper
;
use
yii\helpers\StringHelper
;
...
@@ -125,11 +123,11 @@ class Request extends \yii\base\Request
...
@@ -125,11 +123,11 @@ class Request extends \yii\base\Request
* @var string|boolean the name of the POST parameter that is used to indicate if a request is a PUT, PATCH or DELETE
* @var string|boolean the name of the POST parameter that is used to indicate if a request is a PUT, PATCH or DELETE
* request tunneled through POST. Default to '_method'.
* request tunneled through POST. Default to '_method'.
* @see getMethod()
* @see getMethod()
* @see get
Rest
Params()
* @see get
Body
Params()
*/
*/
public
$
rest
Var
=
'_method'
;
public
$
method
Var
=
'_method'
;
/**
/**
* @var array the parsers for converting the raw HTTP request body into [[
rest
Params]].
* @var array the parsers for converting the raw HTTP request body into [[
body
Params]].
* The array keys are the request `Content-Types`, and the array values are the
* The array keys are the request `Content-Types`, and the array values are the
* corresponding configurations for [[Yii::createObject|creating the parser objects]].
* corresponding configurations for [[Yii::createObject|creating the parser objects]].
* A parser must implement the [[RequestParserInterface]].
* A parser must implement the [[RequestParserInterface]].
...
@@ -145,7 +143,7 @@ class Request extends \yii\base\Request
...
@@ -145,7 +143,7 @@ class Request extends \yii\base\Request
* To register a parser for parsing all request types you can use `'*'` as the array key.
* To register a parser for parsing all request types you can use `'*'` as the array key.
* This one will be used as a fallback in case no other types match.
* This one will be used as a fallback in case no other types match.
*
*
* @see get
Rest
Params()
* @see get
Body
Params()
*/
*/
public
$parsers
=
[];
public
$parsers
=
[];
...
@@ -176,8 +174,8 @@ class Request extends \yii\base\Request
...
@@ -176,8 +174,8 @@ class Request extends \yii\base\Request
*/
*/
public
function
getMethod
()
public
function
getMethod
()
{
{
if
(
isset
(
$_POST
[
$this
->
rest
Var
]))
{
if
(
isset
(
$_POST
[
$this
->
method
Var
]))
{
return
strtoupper
(
$_POST
[
$this
->
rest
Var
]);
return
strtoupper
(
$_POST
[
$this
->
method
Var
]);
}
else
{
}
else
{
return
isset
(
$_SERVER
[
'REQUEST_METHOD'
])
?
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
])
:
'GET'
;
return
isset
(
$_SERVER
[
'REQUEST_METHOD'
])
?
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
])
:
'GET'
;
}
}
...
@@ -265,78 +263,112 @@ class Request extends \yii\base\Request
...
@@ -265,78 +263,112 @@ class Request extends \yii\base\Request
(
stripos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'Shockwave'
)
!==
false
||
stripos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'Flash'
)
!==
false
);
(
stripos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'Shockwave'
)
!==
false
||
stripos
(
$_SERVER
[
'HTTP_USER_AGENT'
],
'Flash'
)
!==
false
);
}
}
private
$_restParams
;
private
$_rawBody
;
/**
* Returns the raw HTTP request body.
* @return string the request body
*/
public
function
getRawBody
()
{
if
(
$this
->
_rawBody
===
null
)
{
$this
->
_rawBody
=
file_get_contents
(
'php://input'
);
}
return
$this
->
_rawBody
;
}
private
$_bodyParams
;
/**
/**
* Returns the request parameters
for the RESTful request
.
* Returns the request parameters
given in the request body
.
*
*
* Request parameters are determined using the parsers configured in [[parsers]] property.
* Request parameters are determined using the parsers configured in [[parsers]] property.
* If no parsers are configured for the current [[contentType]] it uses the PHP function [[mb_parse_str()]]
* If no parsers are configured for the current [[contentType]] it uses the PHP function [[mb_parse_str()]]
* to parse the [[rawBody|request body]].
* to parse the [[rawBody|request body]].
* @return array the
RESTful request parameters
* @return array the
request parameters given in the request body.
* @throws \yii\base\InvalidConfigException if a registered parser does not implement the [[RequestParserInterface]].
* @throws \yii\base\InvalidConfigException if a registered parser does not implement the [[RequestParserInterface]].
* @see getMethod()
* @see getMethod()
* @see getBodyParam()
* @see setBodyParams()
*/
*/
public
function
get
Rest
Params
()
public
function
get
Body
Params
()
{
{
if
(
$this
->
_
rest
Params
===
null
)
{
if
(
$this
->
_
body
Params
===
null
)
{
$contentType
=
$this
->
getContentType
();
$contentType
=
$this
->
getContentType
();
if
(
isset
(
$_POST
[
$this
->
rest
Var
]))
{
if
(
isset
(
$_POST
[
$this
->
method
Var
]))
{
$this
->
_
rest
Params
=
$_POST
;
$this
->
_
body
Params
=
$_POST
;
unset
(
$this
->
_
restParams
[
$this
->
rest
Var
]);
unset
(
$this
->
_
bodyParams
[
$this
->
method
Var
]);
}
elseif
(
isset
(
$this
->
parsers
[
$contentType
]))
{
}
elseif
(
isset
(
$this
->
parsers
[
$contentType
]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$contentType
]);
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$contentType
]);
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
throw
new
InvalidConfigException
(
"The '
$contentType
' request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
throw
new
InvalidConfigException
(
"The '
$contentType
' request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
}
}
$this
->
_
rest
Params
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
$this
->
_
body
Params
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
}
elseif
(
isset
(
$this
->
parsers
[
'*'
]))
{
}
elseif
(
isset
(
$this
->
parsers
[
'*'
]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
'*'
]);
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
'*'
]);
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
throw
new
InvalidConfigException
(
"The fallback request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
throw
new
InvalidConfigException
(
"The fallback request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
}
}
$this
->
_
rest
Params
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
$this
->
_
body
Params
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
}
else
{
}
else
{
$this
->
_
rest
Params
=
[];
$this
->
_
body
Params
=
[];
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_
rest
Params
);
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_
body
Params
);
}
}
}
}
return
$this
->
_
rest
Params
;
return
$this
->
_
body
Params
;
}
}
private
$_rawBody
;
/**
/**
* Returns the raw HTTP request body.
* Sets the request body parameters.
* @return string the request body
* @param array $values the request body parameters (name-value pairs)
* @see getBodyParam()
* @see getBodyParams()
*/
*/
public
function
getRawBody
(
)
public
function
setBodyParams
(
$values
)
{
{
if
(
$this
->
_rawBody
===
null
)
{
$this
->
_bodyParams
=
$values
;
$this
->
_rawBody
=
file_get_contents
(
'php://input'
);
}
}
return
$this
->
_rawBody
;
/**
* Returns the named request body parameter value.
* @param string $name the parameter name
* @param mixed $defaultValue the default parameter value if the parameter does not exist.
* @return mixed the parameter value
* @see getBodyParams()
* @see setBodyParams()
*/
public
function
getBodyParam
(
$name
,
$defaultValue
=
null
)
{
$params
=
$this
->
getBodyParams
();
return
isset
(
$params
[
$name
])
?
$params
[
$name
]
:
$defaultValue
;
}
}
private
$_queryParams
;
/**
/**
* Sets the RESTful parameters.
* Returns the request parameters given in the [[queryString]].
* @param array $values the RESTful parameters (name-value pairs)
*
* This method will return the contents of `$_GET` if params where not explicitly set.
* @return array the request GET parameter values.
* @see setQueryParams()
*/
*/
public
function
setRestParams
(
$values
)
public
function
getQueryParams
(
)
{
{
$this
->
_restParams
=
$values
;
if
(
$this
->
_queryParams
===
null
)
{
return
$_GET
;
}
return
$this
->
_queryParams
;
}
}
/**
/**
*
Returns the named RESTful parameter value
.
*
Sets the request [[queryString]] parameters
.
* @param
string $name the parameter name
* @param
array $values the request query parameters (name-value pairs)
* @
param mixed $defaultValue the default parameter value if the parameter does not exist.
* @
see getQueryParam()
* @
return mixed the parameter value
* @
see getQueryParams()
*/
*/
public
function
getRestParam
(
$name
,
$defaultValue
=
null
)
public
function
setQueryParams
(
$values
)
{
{
$params
=
$this
->
getRestParams
();
$this
->
_queryParams
=
$values
;
return
isset
(
$params
[
$name
])
?
$params
[
$name
]
:
$defaultValue
;
}
}
/**
/**
...
@@ -347,12 +379,10 @@ class Request extends \yii\base\Request
...
@@ -347,12 +379,10 @@ class Request extends \yii\base\Request
* @return mixed the GET parameter value
* @return mixed the GET parameter value
* @see getPost()
* @see getPost()
*/
*/
public
function
get
(
$name
=
null
,
$defaultValue
=
null
)
public
function
get
QueryParam
(
$name
,
$defaultValue
=
null
)
{
{
if
(
$name
===
null
)
{
$params
=
$this
->
getQueryParams
();
return
$_GET
;
return
isset
(
$params
[
$name
])
?
$params
[
$name
]
:
$defaultValue
;
}
return
isset
(
$_GET
[
$name
])
?
$_GET
[
$name
]
:
$defaultValue
;
}
}
/**
/**
...
@@ -364,7 +394,7 @@ class Request extends \yii\base\Request
...
@@ -364,7 +394,7 @@ class Request extends \yii\base\Request
* @return mixed the POST parameter value
* @return mixed the POST parameter value
* @see get()
* @see get()
*/
*/
public
function
getPost
(
$name
=
null
,
$defaultValue
=
null
)
public
function
getPost
Param
(
$name
=
null
,
$defaultValue
=
null
)
{
{
if
(
$name
===
null
)
{
if
(
$name
===
null
)
{
return
$_POST
;
return
$_POST
;
...
@@ -372,51 +402,6 @@ class Request extends \yii\base\Request
...
@@ -372,51 +402,6 @@ class Request extends \yii\base\Request
return
isset
(
$_POST
[
$name
])
?
$_POST
[
$name
]
:
$defaultValue
;
return
isset
(
$_POST
[
$name
])
?
$_POST
[
$name
]
:
$defaultValue
;
}
}
/**
* Returns the named DELETE parameter value.
* @param string $name the DELETE parameter name. If not specified, an array of DELETE parameters is returned.
* @param mixed $defaultValue the default parameter value if the DELETE parameter does not exist.
* @property array the DELETE request parameter values
* @return mixed the DELETE parameter value
*/
public
function
getDelete
(
$name
=
null
,
$defaultValue
=
null
)
{
if
(
$name
===
null
)
{
return
$this
->
getRestParams
();
}
return
$this
->
getIsDelete
()
?
$this
->
getRestParam
(
$name
,
$defaultValue
)
:
null
;
}
/**
* Returns the named PUT parameter value.
* @param string $name the PUT parameter name. If not specified, an array of PUT parameters is returned.
* @param mixed $defaultValue the default parameter value if the PUT parameter does not exist.
* @property array the PUT request parameter values
* @return mixed the PUT parameter value
*/
public
function
getPut
(
$name
=
null
,
$defaultValue
=
null
)
{
if
(
$name
===
null
)
{
return
$this
->
getRestParams
();
}
return
$this
->
getIsPut
()
?
$this
->
getRestParam
(
$name
,
$defaultValue
)
:
null
;
}
/**
* Returns the named PATCH parameter value.
* @param string $name the PATCH parameter name. If not specified, an array of PATCH parameters is returned.
* @param mixed $defaultValue the default parameter value if the PATCH parameter does not exist.
* @property array the PATCH request parameter values
* @return mixed the PATCH parameter value
*/
public
function
getPatch
(
$name
=
null
,
$defaultValue
=
null
)
{
if
(
$name
===
null
)
{
return
$this
->
getRestParams
();
}
return
$this
->
getIsPatch
()
?
$this
->
getRestParam
(
$name
,
$defaultValue
)
:
null
;
}
private
$_hostInfo
;
private
$_hostInfo
;
/**
/**
...
@@ -1151,24 +1136,12 @@ class Request extends \yii\base\Request
...
@@ -1151,24 +1136,12 @@ class Request extends \yii\base\Request
public
function
validateCsrfToken
()
public
function
validateCsrfToken
()
{
{
$method
=
$this
->
getMethod
();
$method
=
$this
->
getMethod
();
if
(
!
$this
->
enableCsrfValidation
||
!
in_array
(
$method
,
[
'POST'
,
'PUT'
,
'PATCH'
,
'DELETE'
],
true
))
{
// only validate CSRF token on "safe" methods http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1
if
(
!
$this
->
enableCsrfValidation
||
in_array
(
$method
,
[
'GET'
,
'HEAD'
,
'OPTIONS'
],
true
))
{
return
true
;
return
true
;
}
}
$trueToken
=
$this
->
getCookies
()
->
getValue
(
$this
->
csrfVar
);
$trueToken
=
$this
->
getCookies
()
->
getValue
(
$this
->
csrfVar
);
switch
(
$method
)
{
$token
=
$this
->
getBodyParam
(
$this
->
csrfVar
);
case
'PUT'
:
$token
=
$this
->
getPut
(
$this
->
csrfVar
);
break
;
case
'PATCH'
:
$token
=
$this
->
getPatch
(
$this
->
csrfVar
);
break
;
case
'DELETE'
:
$token
=
$this
->
getDelete
(
$this
->
csrfVar
);
break
;
default
:
$token
=
$this
->
getPost
(
$this
->
csrfVar
);
break
;
}
return
$this
->
validateCsrfTokenInternal
(
$token
,
$trueToken
)
return
$this
->
validateCsrfTokenInternal
(
$token
,
$trueToken
)
||
$this
->
validateCsrfTokenInternal
(
$this
->
getCsrfTokenFromHeader
(),
$trueToken
);
||
$this
->
validateCsrfTokenInternal
(
$this
->
getCsrfTokenFromHeader
(),
$trueToken
);
}
}
...
...
framework/web/UrlManager.php
View file @
0d669f5e
...
@@ -217,7 +217,7 @@ class UrlManager extends Component
...
@@ -217,7 +217,7 @@ class UrlManager extends Component
return
[
$pathInfo
,
[]];
return
[
$pathInfo
,
[]];
}
else
{
}
else
{
Yii
::
trace
(
'Pretty URL not enabled. Using default URL parsing logic.'
,
__METHOD__
);
Yii
::
trace
(
'Pretty URL not enabled. Using default URL parsing logic.'
,
__METHOD__
);
$route
=
$request
->
get
(
$this
->
routeVar
);
$route
=
$request
->
get
QueryParam
(
$this
->
routeVar
,
''
);
if
(
is_array
(
$route
))
{
if
(
is_array
(
$route
))
{
$route
=
''
;
$route
=
''
;
}
}
...
...
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