Class yii\httpclient\JsonFormatter
Inheritance | yii\httpclient\JsonFormatter » yii\base\BaseObject |
---|---|
Implements | yii\httpclient\FormatterInterface |
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-httpclient/blob/master/src/JsonFormatter.php |
JsonFormatter formats HTTP message as JSON.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$encodeOptions | integer | The encoding options. | yii\httpclient\JsonFormatter |
Public Methods
Method | Description | Defined By |
---|---|---|
format() | Formats given HTTP request message. | yii\httpclient\JsonFormatter |
Property Details
The encoding options. For more details please refer to http://www.php.net/manual/en/function.json-encode.php.
Method Details
Formats given HTTP request message.
public yii\httpclient\Request format ( yii\httpclient\Request $request ) | ||
$request | yii\httpclient\Request |
HTTP request instance. |
return | yii\httpclient\Request |
Formatted request. |
---|
public function format(Request $request)
{
$request->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
if (($data = $request->getData()) !== null) {
$request->setContent(Json::encode($request->getData(), $this->encodeOptions));
}
return $request;
}