Commit 1026b9da by Daniel Schmidt

Tabs vs. spaces

parent 00785d38
...@@ -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;
} }
} }
} }
...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment