1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace yii\db;
- use yii\base\InvalidConfigException;
- class JsonExpression implements ExpressionInterface, \JsonSerializable
- {
- const TYPE_JSON = 'json';
- const TYPE_JSONB = 'jsonb';
-
- protected $value;
-
- protected $type;
-
- public function __construct($value, $type = null)
- {
- if ($value instanceof self) {
- $value = $value->getValue();
- }
- $this->value = $value;
- $this->type = $type;
- }
-
- public function getValue()
- {
- return $this->value;
- }
-
- public function getType()
- {
- return $this->type;
- }
-
- public function jsonSerialize()
- {
- $value = $this->getValue();
- if ($value instanceof QueryInterface) {
- throw new InvalidConfigException('The JsonExpression class can not be serialized to JSON when the value is a QueryInterface object');
- }
- return $value;
- }
- }
|