0 follower

Final Class Yiisoft\Db\Expression\Value\Builder\ArrayValueBuilder

InheritanceYiisoft\Db\Expression\Value\Builder\ArrayValueBuilder » Yiisoft\Db\Expression\Value\Builder\AbstractArrayValueBuilder
ImplementsYiisoft\Db\Expression\ExpressionBuilderInterface

Default expression builder for {@see ArrayValue}. Builds an expression as a JSON.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Expression\Value\Builder\AbstractArrayValueBuilder
build() The Method builds the raw SQL from the $expression that won't be additionally escaped or quoted. Yiisoft\Db\Expression\Value\Builder\AbstractArrayValueBuilder

Method Details

Hide inherited methods

__construct() public method
public mixed __construct ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $queryBuilder )
$queryBuilder Yiisoft\Db\QueryBuilder\QueryBuilderInterface

                public function __construct(protected readonly QueryBuilderInterface $queryBuilder) {}

            
build() public method

Defined in: Yiisoft\Db\Expression\Value\Builder\AbstractArrayValueBuilder::build()

The Method builds the raw SQL from the $expression that won't be additionally escaped or quoted.

public string build ( Yiisoft\Db\Expression\Value\ArrayValue $expression, array &$params = [] )
$expression Yiisoft\Db\Expression\Value\ArrayValue

The expression to build.

$params array

The binding parameters.

return string

The raw SQL that won't be additionally escaped or quoted.

                public function build(ExpressionInterface $expression, array &$params = []): string
{
    $value = $expression->value;
    if ($value === null) {
        return 'NULL';
    }
    if ($value instanceof LazyArrayInterface) {
        $value = $this->getLazyArrayValue($value);
    }
    if (is_string($value)) {
        return $this->buildStringValue($value, $expression, $params);
    }
    if ($value instanceof QueryInterface) {
        return $this->buildSubquery($value, $expression, $params);
    }
    return $this->buildValue($value, $expression, $params);
}

            
buildStringValue() protected method

protected string buildStringValue ( string $value, Yiisoft\Db\Expression\Value\ArrayValue $expression, array &$params )
$value string
$expression Yiisoft\Db\Expression\Value\ArrayValue
$params array

                protected function buildStringValue(string $value, ArrayValue $expression, array &$params): string
{
    $param = new Param($value, DataType::STRING);
    return $this->queryBuilder->bindParam($param, $params);
}

            
buildSubquery() protected method

protected string buildSubquery ( Yiisoft\Db\Query\QueryInterface $query, Yiisoft\Db\Expression\Value\ArrayValue $expression, array &$params )
$query Yiisoft\Db\Query\QueryInterface
$expression Yiisoft\Db\Expression\Value\ArrayValue
$params array

                protected function buildSubquery(QueryInterface $query, ArrayValue $expression, array &$params): string
{
    [$sql, $params] = $this->queryBuilder->build($query, $params);
    return "($sql)";
}

            
buildValue() protected method

protected string buildValue ( iterable $value, Yiisoft\Db\Expression\Value\ArrayValue $expression, array &$params )
$value iterable
$expression Yiisoft\Db\Expression\Value\ArrayValue
$params array

                protected function buildValue(iterable $value, ArrayValue $expression, array &$params): string
{
    if (!is_array($value)) {
        $value = iterator_to_array($value, false);
    }
    return $this->buildStringValue(json_encode($value, JSON_THROW_ON_ERROR), $expression, $params);
}

            
getLazyArrayValue() protected method

protected array|string getLazyArrayValue ( Yiisoft\Db\Schema\Data\LazyArrayInterface $value )
$value Yiisoft\Db\Schema\Data\LazyArrayInterface

                protected function getLazyArrayValue(LazyArrayInterface $value): array|string
{
    return match ($value::class) {
        LazyArray::class, JsonLazyArray::class, StructuredLazyArray::class => $value->getRawValue(),
        default => $value->getValue(),
    };
}