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
1026b9da
Commit
1026b9da
authored
Jan 19, 2014
by
Daniel Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tabs vs. spaces
parent
00785d38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
33 deletions
+33
-33
JsonParser.php
framework/web/JsonParser.php
+22
-22
Request.php
framework/web/Request.php
+11
-11
No files found.
framework/web/JsonParser.php
View file @
1026b9da
...
...
@@ -18,29 +18,29 @@ use yii\helpers\Json;
*/
class
JsonParser
implements
RequestParserInterface
{
/**
* @var boolean whether to return objects in terms of associative arrays.
*/
public
$asArray
=
true
;
/**
* @var boolean whether to return objects in terms of associative arrays.
*/
public
$asArray
=
true
;
/**
* @var boolean whether to throw an exception if the body is invalid json
*/
public
$throwException
=
false
;
/**
* @var boolean whether to throw an exception if the body is invalid json
*/
public
$throwException
=
false
;
/**
* @param string $rawBody the raw HTTP request body
* @return array parameters parsed from the request body
*/
/**
* @param string $rawBody the raw HTTP request body
* @return array parameters parsed from the request body
*/
public
function
parse
(
$rawBody
)
{
try
{
return
Json
::
encode
(
$rawBody
,
$this
->
asArray
);
}
catch
(
InvalidParamException
$e
)
{
if
(
$this
->
throwException
)
{
throw
$e
;
}
return
null
;
}
}
{
try
{
return
Json
::
encode
(
$rawBody
,
$this
->
asArray
);
}
catch
(
InvalidParamException
$e
)
{
if
(
$this
->
throwException
)
{
throw
$e
;
}
return
null
;
}
}
}
framework/web/Request.php
View file @
1026b9da
...
...
@@ -128,13 +128,13 @@ class Request extends \yii\base\Request
* @see getRestParams()
*/
public
$restVar
=
'_method'
;
/**
* @var array the parsers for converting the raw request body into [[restParams]]
* The array keys are the request content-types, and the array values are the
* corresponding configurations for creating the parser objects.
* @see getRestParams()
*/
public
$parsers
=
[];
/**
* @var array the parsers for converting the raw request body into [[restParams]]
* The array keys are the request content-types, and the array values are the
* corresponding configurations for creating the parser objects.
* @see getRestParams()
*/
public
$parsers
=
[];
private
$_cookies
;
...
...
@@ -266,10 +266,10 @@ class Request extends \yii\base\Request
$this
->
_restParams
=
$_POST
;
}
else
if
(
isset
(
$this
->
parsers
[
$this
->
getContentType
()]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$this
->
getContentType
()]);
if
(
!
$parser
instanceof
RequestParserInterface
)
{
throw
new
InvalidConfigException
(
"The '
{
$this
->
contentType
}
' request parser is invalid. It must implement the RequestParserInterface."
);
}
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
());
if
(
!
$parser
instanceof
RequestParserInterface
)
{
throw
new
InvalidConfigException
(
"The '
{
$this
->
contentType
}
' request parser is invalid. It must implement the RequestParserInterface."
);
}
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
());
}
else
{
$this
->
_restParams
=
[];
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_restParams
);
...
...
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