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
3a75c69b
Commit
3a75c69b
authored
Jan 20, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
parents
1fd7dc66
65179b10
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
124 additions
and
4 deletions
+124
-4
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Pagination.php
framework/data/Pagination.php
+2
-0
Sort.php
framework/data/Sort.php
+2
-0
ActiveFixture.php
framework/test/ActiveFixture.php
+1
-0
DbFixture.php
framework/test/DbFixture.php
+1
-0
Fixture.php
framework/test/Fixture.php
+1
-0
FixtureTrait.php
framework/test/FixtureTrait.php
+1
-0
InitDbFixture.php
framework/test/InitDbFixture.php
+1
-1
JsonParser.php
framework/web/JsonParser.php
+49
-0
Request.php
framework/web/Request.php
+40
-3
RequestParserInterface.php
framework/web/RequestParserInterface.php
+25
-0
No files found.
framework/CHANGELOG.md
View file @
3a75c69b
...
...
@@ -73,6 +73,7 @@ Yii Framework 2 Change Log
-
Enh #1973:
`yii message/extract`
is now able to generate
`.po`
files (SergeiKutanov, samdark)
-
Enh #1984: ActionFilter will now mark event as handled when action run is aborted (cebe)
-
Enh #2003: Added
`filter`
property to
`ExistValidator`
and
`UniqueValidator`
to support adding additional filtering conditions (qiangxue)
-
Enh #2043: Added support for custom request body parsers (danschmidt5189, cebe)
-
Enh #2051: Do not save null data into database when using RBAC (qiangxue)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to default application templates (samdark)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
...
...
framework/data/Pagination.php
View file @
3a75c69b
...
...
@@ -86,6 +86,8 @@ class Pagination extends Object
* @var array parameters (name => value) that should be used to obtain the current page number
* and to create new pagination URLs. If not set, all parameters from $_GET will be used instead.
*
* In order to add hash to all links use `array_merge($_GET, ['#' => 'my-hash'])`.
*
* The array element indexed by [[pageVar]] is considered to be the current page number.
* If the element does not exist, the current page number is considered 0.
*/
...
...
framework/data/Sort.php
View file @
3a75c69b
...
...
@@ -168,6 +168,8 @@ class Sort extends Object
* @var array parameters (name => value) that should be used to obtain the current sort directions
* and to create new sort URLs. If not set, $_GET will be used instead.
*
* In order to add hash to all links use `array_merge($_GET, ['#' => 'my-hash'])`.
*
* The array element indexed by [[sortVar]] is considered to be the current sort directions.
* If the element does not exist, the [[defaults|default order]] will be used.
*
...
...
framework/test/ActiveFixture.php
View file @
3a75c69b
...
...
@@ -47,6 +47,7 @@ class ActiveFixture extends BaseActiveFixture
*/
private
$_table
;
/**
* @inheritdoc
*/
...
...
framework/test/DbFixture.php
View file @
3a75c69b
...
...
@@ -28,6 +28,7 @@ abstract class DbFixture extends Fixture
*/
public
$db
=
'db'
;
/**
* @inheritdoc
*/
...
...
framework/test/Fixture.php
View file @
3a75c69b
...
...
@@ -35,6 +35,7 @@ class Fixture extends Component
*/
public
$depends
=
[];
/**
* Loads the fixture.
* This method is called before performing every test method.
...
...
framework/test/FixtureTrait.php
View file @
3a75c69b
...
...
@@ -38,6 +38,7 @@ trait FixtureTrait
*/
private
$_fixtureAliases
;
/**
* Returns the value of an object property.
*
...
...
framework/test/InitDbFixture.php
View file @
3a75c69b
...
...
@@ -34,7 +34,7 @@ class InitDbFixture extends DbFixture
public
$initScript
=
'@app/tests/fixtures/initdb.php'
;
/**
* @var array list of database schemas that the test tables may reside in. Defaults to
*
['']
, meaning using the default schema (an empty string refers to the
*
`['']`
, meaning using the default schema (an empty string refers to the
* default schema). This property is mainly used when turning on and off integrity checks
* so that fixture data can be populated into the database without causing problem.
*/
...
...
framework/web/JsonParser.php
0 → 100644
View file @
3a75c69b
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
use
yii\base\InvalidParamException
;
use
yii\helpers\Json
;
/**
* Parses a raw HTTP request using [[yii\helpers\Json::decode()]]
*
* @author Dan Schmidt <danschmidt5189@gmail.com>
* @since 2.0
*/
class
JsonParser
implements
RequestParserInterface
{
/**
* @var boolean whether to return objects in terms of associative arrays.
*/
public
$asArray
=
true
;
/**
* @var boolean whether to throw a [[BadRequestHttpException]] if the body is invalid json
*/
public
$throwException
=
true
;
/**
* Parses a HTTP request body.
* @param string $rawBody the raw HTTP request body.
* @param string $contentType the content type specified for the request body.
* @return array parameters parsed from the request body
* @throws BadRequestHttpException if the body contains invalid json and [[throwException]] is `true`.
*/
public
function
parse
(
$rawBody
,
$contentType
)
{
try
{
return
Json
::
decode
(
$rawBody
,
$this
->
asArray
);
}
catch
(
InvalidParamException
$e
)
{
if
(
$this
->
throwException
)
{
throw
new
BadRequestHttpException
(
'Invalid JSON data in request body: '
.
$e
->
getMessage
(),
0
,
$e
);
}
return
null
;
}
}
}
framework/web/Request.php
View file @
3a75c69b
...
...
@@ -128,6 +128,26 @@ class Request extends \yii\base\Request
* @see getRestParams()
*/
public
$restVar
=
'_method'
;
/**
* @var array the parsers for converting the raw HTTP request body into [[restParams]].
* The array keys are the request `Content-Types`, and the array values are the
* corresponding configurations for [[Yii::createObject|creating the parser objects]].
* A parser must implement the [[RequestParserInterface]].
*
* To enable parsing for JSON requests you can use the [[JsonParser]] class like in the following example:
*
* ```
* [
* 'application/json' => 'yii\web\JsonParser',
* ]
* ```
*
* 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.
*
* @see getRestParams()
*/
public
$parsers
=
[];
private
$_cookies
;
...
...
@@ -249,16 +269,33 @@ class Request extends \yii\base\Request
/**
* Returns the request parameters for the RESTful request.
*
* 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()]]
* to parse the [[rawBody|request body]].
* @return array the RESTful request parameters
* @throws \yii\base\InvalidConfigException if a registered parser does not implement the [[RequestParserInterface]].
* @see getMethod()
*/
public
function
getRestParams
()
{
if
(
$this
->
_restParams
===
null
)
{
$contentType
=
$this
->
getContentType
();
if
(
isset
(
$_POST
[
$this
->
restVar
]))
{
$this
->
_restParams
=
$_POST
;
}
elseif
(
strncmp
(
$this
->
getContentType
(),
'application/json'
,
16
)
===
0
)
{
$this
->
_restParams
=
Json
::
decode
(
$this
->
getRawBody
(),
true
);
unset
(
$this
->
_restParams
[
$this
->
restVar
]);
}
elseif
(
isset
(
$this
->
parsers
[
$contentType
]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
$contentType
]);
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
throw
new
InvalidConfigException
(
"The '
$contentType
' request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
}
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
}
elseif
(
isset
(
$this
->
parsers
[
'*'
]))
{
$parser
=
Yii
::
createObject
(
$this
->
parsers
[
'*'
]);
if
(
!
(
$parser
instanceof
RequestParserInterface
))
{
throw
new
InvalidConfigException
(
"The fallback request parser is invalid. It must implement the yii
\\
web
\\
RequestParserInterface."
);
}
$this
->
_restParams
=
$parser
->
parse
(
$this
->
getRawBody
(),
$contentType
);
}
else
{
$this
->
_restParams
=
[];
mb_parse_str
(
$this
->
getRawBody
(),
$this
->
_restParams
);
...
...
@@ -824,7 +861,7 @@ class Request extends \yii\base\Request
}
/**
*
Returns request content-type
* Returns request content-type
* The Content-Type header field indicates the MIME type of the data
* contained in [[getRawBody()]] or, in the case of the HEAD method, the
* media type that would have been sent had the request been a GET.
...
...
framework/web/RequestParserInterface.php
0 → 100644
View file @
3a75c69b
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\web
;
/**
* Interface for classes that parse the raw request body into a parameters array.
*
* @author Dan Schmidt <danschmidt5189@gmail.com>
* @since 2.0
*/
interface
RequestParserInterface
{
/**
* Parses a HTTP request body.
* @param string $rawBody the raw HTTP request body.
* @param string $contentType the content type specified for the request body.
* @return array parameters parsed from the request body
*/
public
function
parse
(
$rawBody
,
$contentType
);
}
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