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;
...
@@ -18,29 +18,29 @@ use yii\helpers\Json;
*/
*/
class
JsonParser
implements
RequestParserInterface
class
JsonParser
implements
RequestParserInterface
{
{
/**
/**
* @var boolean whether to return objects in terms of associative arrays.
* @var boolean whether to return objects in terms of associative arrays.
*/
*/
public
$asArray
=
true
;
public
$asArray
=
true
;
/**
/**
* @var boolean whether to throw an exception if the body is invalid json
* @var boolean whether to throw an exception if the body is invalid json
*/
*/
public
$throwException
=
false
;
public
$throwException
=
false
;
/**
/**
* @param string $rawBody the raw HTTP request body
* @param string $rawBody the raw HTTP request body
* @return array parameters parsed from the request body
* @return array parameters parsed from the request body
*/
*/
public
function
parse
(
$rawBody
)
public
function
parse
(
$rawBody
)
{
{
try
{
try
{
return
Json
::
encode
(
$rawBody
,
$this
->
asArray
);
return
Json
::
encode
(
$rawBody
,
$this
->
asArray
);
}
catch
(
InvalidParamException
$e
)
{
}
catch
(
InvalidParamException
$e
)
{
if
(
$this
->
throwException
)
{
if
(
$this
->
throwException
)
{
throw
$e
;
throw
$e
;
}
}
return
null
;
return
null
;
}
}
}
}
}
}
framework/web/Request.php
View file @
1026b9da
...
@@ -128,13 +128,13 @@ class Request extends \yii\base\Request
...
@@ -128,13 +128,13 @@ class Request extends \yii\base\Request
* @see getRestParams()
* @see getRestParams()
*/
*/
public
$restVar
=
'_method'
;
public
$restVar
=
'_method'
;
/**
/**
* @var array the parsers for converting the raw request body into [[restParams]]
* @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
* The array keys are the request content-types, and the array values are the
* corresponding configurations for creating the parser objects.
* corresponding configurations for creating the parser objects.
* @see getRestParams()
* @see getRestParams()
*/
*/
public
$parsers
=
[];
public
$parsers
=
[];
private
$_cookies
;
private
$_cookies
;
...
@@ -266,10 +266,10 @@ class Request extends \yii\base\Request
...
@@ -266,10 +266,10 @@ class Request extends \yii\base\Request
$this
->
_restParams
=
$_POST
;
$this
->
_restParams
=
$_POST
;
}
else
if
(
isset
(
$this
->
parsers
[
$this
->
getContentType
()]))
{
}
else
if
(
isset
(
$this
->
parsers
[
$this
->
getContentType
()]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$this
->
getContentType
()]);
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$this
->
getContentType
()]);
if
(
!
$parser
instanceof
RequestParserInterface
)
{
if
(
!
$parser
instanceof
RequestParserInterface
)
{
throw
new
InvalidConfigException
(
"The '
{
$this
->
contentType
}
' request parser is invalid. It must implement the RequestParserInterface."
);
throw
new
InvalidConfigException
(
"The '
{
$this
->
contentType
}
' request parser is invalid. It must implement the RequestParserInterface."
);
}
}
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
());
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
());
}
else
{
}
else
{
$this
->
_restParams
=
[];
$this
->
_restParams
=
[];
mb_parse_str
(
$this
->
getRawBody
(),
$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