Class yii\db\conditions\HashConditionBuilder

Inheritanceyii\db\conditions\HashConditionBuilder
Implementsyii\db\ExpressionBuilderInterface
Uses Traitsyii\db\ExpressionBuilderTrait
Available since version2.0.14
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/conditions/HashConditionBuilder.php

Class HashConditionBuilder builds objects of yii\db\conditions\HashCondition

Protected Properties

Hide inherited properties

Property Type Description Defined By

Public Methods

Hide inherited methods

Method Description Defined By
__construct() ExpressionBuilderTrait constructor. yii\db\ExpressionBuilderTrait
build() Method builds the raw SQL from the $expression that will not be additionally escaped or quoted. yii\db\conditions\HashConditionBuilder

Method Details

Hide inherited methods

__construct() public method

Defined in: yii\db\ExpressionBuilderTrait::__construct()

ExpressionBuilderTrait constructor.

public void __construct ( yii\db\QueryBuilder $queryBuilder )
$queryBuilder yii\db\QueryBuilder

                public function __construct(QueryBuilder $queryBuilder)
{
    $this->queryBuilder = $queryBuilder;
}

            
build() public method

Method builds the raw SQL from the $expression that will not be additionally escaped or quoted.

public string build ( yii\db\ExpressionInterface $expression, array &$params = [] )
$expression yii\db\ExpressionInterface|yii\db\conditions\HashCondition

The expression to be built.

$params array

The binding parameters.

return string

The raw SQL that will not be additionally escaped or quoted.

                public function build(ExpressionInterface $expression, array &$params = [])
{
    $hash = $expression->getHash();
    $parts = [];
    foreach ($hash as $column => $value) {
        if (ArrayHelper::isTraversable($value) || $value instanceof Query) {
            // IN condition
            $parts[] = $this->queryBuilder->buildCondition(new InCondition($column, 'IN', $value), $params);
        } else {
            if (strpos($column, '(') === false) {
                $column = $this->queryBuilder->db->quoteColumnName($column);
            }
            if ($value === null) {
                $parts[] = "$column IS NULL";
            } elseif ($value instanceof ExpressionInterface) {
                $parts[] = "$column=" . $this->queryBuilder->buildExpression($value, $params);
            } else {
                $phName = $this->queryBuilder->bindParam($value, $params);
                $parts[] = "$column=$phName";
            }
        }
    }
    return count($parts) === 1 ? $parts[0] : '(' . implode(') AND (', $parts) . ')';
}