0 follower

Abstract Class Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

InheritanceYiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder
ImplementsYiisoft\Db\Expression\ExpressionBuilderInterface
SubclassesYiisoft\Db\Expression\Function\Builder\GreatestBuilder, Yiisoft\Db\Expression\Function\Builder\LeastBuilder, Yiisoft\Db\Expression\Function\Builder\LongestBuilder, Yiisoft\Db\Expression\Function\Builder\ShortestBuilder

Base class for building SQL representation of multi-operand function expressions.

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 multi-operand function expression from the given {@see MultiOperandFunction} instance. Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder
buildOperand() Builds an operand expression of the multi-operand function. Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

Property Details

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

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 abstract method

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

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

The expression to build from.

$params array

The parameters to be bound to the query.

return string

SQL multi-operand function expression.

                abstract protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string;

            
buildOperand() protected method

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);
}