0 follower

Final Class Yiisoft\Db\Expression\Function\Builder\GreatestBuilder

InheritanceYiisoft\Db\Expression\Function\Builder\GreatestBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder
ImplementsYiisoft\Db\Expression\ExpressionBuilderInterface

Builds SQL GREATEST() function expressions for {@see Greatest} objects.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder
build() Builds a SQL multi-operand function expression from the given {@see MultiOperandFunction} instance. Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

Protected Methods

Hide inherited methods

Method Description Defined By
buildFromExpression() Builds a SQL GREATEST() function expression from the given {@see Greatest} object. Yiisoft\Db\Expression\Function\Builder\GreatestBuilder
buildOperand() Builds an operand expression of the multi-operand function. Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

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\Function\Builder\MultiOperandFunctionBuilder::build()

Builds a SQL multi-operand function expression from the given {@see MultiOperandFunction} instance.

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

The expression to build.

$params array

The parameters to be bound to the query.

return string

SQL multi-operand function expression.

                public function build(ExpressionInterface $expression, array &$params = []): string
{
    $operands = $expression->getOperands();
    if (empty($operands)) {
        throw new InvalidArgumentException(
            'The ' . $expression::class . ' expression must have at least one operand.',
        );
    }
    if (count($operands) === 1) {
        return '(' . $this->buildOperand($operands[0], $params) . ')';
    }
    return $this->buildFromExpression($expression, $params);
}

            
buildFromExpression() protected method

Builds a SQL GREATEST() function expression from the given {@see Greatest} object.

protected string buildFromExpression ( Yiisoft\Db\Expression\Function\Greatest $expression, array &$params )
$expression Yiisoft\Db\Expression\Function\Greatest

The expression to build.

$params array

The parameters to bind.

return string

The SQL GREATEST() function expression.

                protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
    $builtOperands = [];
    foreach ($expression->getOperands() as $operand) {
        $builtOperands[] = $this->buildOperand($operand, $params);
    }
    return 'GREATEST(' . implode(', ', $builtOperands) . ')';
}

            
buildOperand() protected method

Defined in: Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder::buildOperand()

Builds an operand expression of the multi-operand function.

protected string buildOperand ( mixed $operand, array &$params )
$operand mixed
$params array

                protected function buildOperand(mixed $operand, array &$params): string
{
    if (is_string($operand)) {
        return $this->queryBuilder->getQuoter()->quoteColumnName($operand);
    }
    return $this->queryBuilder->buildValue($operand, $params);
}