1 | <?php |
||
24 | class JsonExpression implements ExpressionInterface, \JsonSerializable |
||
25 | { |
||
26 | const TYPE_JSON = 'json'; |
||
27 | const TYPE_JSONB = 'jsonb'; |
||
28 | |||
29 | /** |
||
30 | * @var mixed the value to be encoded to JSON. |
||
31 | * The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] input requirements. |
||
32 | */ |
||
33 | protected $value; |
||
34 | /** |
||
35 | * @var string|null Type of JSON, expression should be casted to. Defaults to `null`, meaning |
||
36 | * no explicit casting will be performed. |
||
37 | * This property will be encountered only for DBMSs that support different types of JSON. |
||
38 | * For example, PostgreSQL has `json` and `jsonb` types. |
||
39 | */ |
||
40 | protected $type; |
||
41 | |||
42 | |||
43 | /** |
||
44 | * JsonExpression constructor. |
||
45 | * |
||
46 | * @param mixed $value the value to be encoded to JSON. |
||
47 | * The value must be compatible with [\yii\helpers\Json::encode()|Json::encode()]] requirements. |
||
48 | * @param string|null $type the type of the JSON. See [[JsonExpression::type]] |
||
49 | * |
||
50 | * @see type |
||
51 | */ |
||
52 | 9 | public function __construct($value, $type = null) |
|
61 | |||
62 | /** |
||
63 | * @return mixed |
||
64 | * @see value |
||
65 | */ |
||
66 | 34 | public function getValue() |
|
70 | |||
71 | /** |
||
72 | * @return null|string the type of JSON |
||
73 | * @see type |
||
74 | */ |
||
75 | 21 | public function getType() |
|
79 | |||
80 | /** |
||
81 | * Specify data which should be serialized to JSON |
||
82 | * |
||
83 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
84 | * @return mixed data which can be serialized by <b>json_encode</b>, |
||
85 | * which is a value of any type other than a resource. |
||
86 | * @since 2.0.14.1 |
||
87 | * @throws InvalidConfigException when JsonExpression contains QueryInterface object |
||
88 | */ |
||
89 | 2 | public function jsonSerialize() |
|
98 | } |
||
99 |