-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathJsonExpressionBuilder.php
More file actions
39 lines (32 loc) · 963 Bytes
/
JsonExpressionBuilder.php
File metadata and controls
39 lines (32 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\db;
use yii\helpers\Json;
/**
* Class JsonExpressionBuilder builds [[JsonExpression]] for DBMS that don't provide
* a vendor-specific solution.
*
* @author WarLikeLaux
* @since 2.0.55
*/
class JsonExpressionBuilder implements ExpressionBuilderInterface
{
use ExpressionBuilderTrait;
/**
* {@inheritdoc}
* @param JsonExpression|ExpressionInterface $expression the expression to be built
*/
public function build(ExpressionInterface $expression, array &$params = [])
{
$value = $expression->getValue();
if ($value instanceof Query) {
list($sql, $params) = $this->queryBuilder->build($value, $params);
return "($sql)";
}
return $this->queryBuilder->bindParam(Json::encode($value), $params);
}
}