JsonExpression
in package
implements
ExpressionInterface, JsonSerializable
Class JsonExpression represents data that should be encoded to JSON.
For example:
new JsonExpression(['a' => 1, 'b' => 2]); // will be encoded to '{"a": 1, "b": 2}'
Tags
Table of Contents
Interfaces
- ExpressionInterface
- Interface ExpressionInterface should be used to mark classes, that should be built in a special way.
- JsonSerializable
Constants
- TYPE_JSON = 'json'
- TYPE_JSONB = 'jsonb'
Properties
Methods
- __construct() : mixed
- JsonExpression constructor.
- getType() : string|null
- getValue() : mixed
- jsonSerialize() : mixed
- Specify data which should be serialized to JSON
Constants
TYPE_JSON
public
mixed
TYPE_JSON
= 'json'
TYPE_JSONB
public
mixed
TYPE_JSONB
= 'jsonb'
Properties
$type
protected
string|null
$type
Type of JSON, expression should be casted to. Defaults to null
, meaning
no explicit casting will be performed.
This property will be encountered only for DBMSs that support different types of JSON.
For example, PostgreSQL has json
and jsonb
types.
$value
protected
mixed
$value
the value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] input requirements.
Methods
__construct()
JsonExpression constructor.
public
__construct(mixed $value[, string|null $type = null ]) : mixed
Parameters
- $value : mixed
-
the value to be encoded to JSON. The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] requirements.
- $type : string|null = null
-
the type of the JSON. See [[JsonExpression::type]]
Tags
getType()
public
getType() : string|null
Tags
Return values
string|null —the type of JSON
getValue()
public
getValue() : mixed
Tags
jsonSerialize()
Specify data which should be serialized to JSON
public
jsonSerialize() : mixed
Tags
Attributes
Return values
mixed —data which can be serialized by json_encode, which is a value of any type other than a resource.