123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?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;
- }
- }
|