yii\mongodb\QueryBuilder::buildInCondition PHP Метод

buildInCondition() публичный Метод

Creates an Mongo condition with the IN operator.
public buildInCondition ( string $operator, array $operands ) : array
$operator string the operator to use (e.g. `IN` or `NOT IN`)
$operands array the first operand is the column name. If it is an array a composite IN condition will be generated. The second operand is an array of values that column value should be among.
Результат array the generated Mongo condition.
    public function buildInCondition($operator, $operands)
    {
        if (!isset($operands[0], $operands[1])) {
            throw new InvalidParamException("Operator '{$operator}' requires two operands.");
        }
        list($column, $values) = $operands;
        $values = (array) $values;
        $operator = $this->normalizeConditionKeyword($operator);
        if (!is_array($column)) {
            $columns = [$column];
            $values = [$column => $values];
        } elseif (count($column) > 1) {
            return $this->buildCompositeInCondition($operator, $column, $values);
        } else {
            $columns = $column;
            $values = [$column[0] => $values];
        }
        $result = [];
        foreach ($columns as $column) {
            if ($column == '_id') {
                $inValues = $this->ensureMongoId($values[$column]);
            } else {
                $inValues = $values[$column];
            }
            $inValues = array_values($inValues);
            if (count($inValues) === 1 && $operator === '$in') {
                $result[$column] = $inValues[0];
            } else {
                $result[$column][$operator] = $inValues;
            }
        }
        return $result;
    }