0 follower

Final Class Yiisoft\Db\QueryBuilder\Condition\Like

InheritanceYiisoft\Db\QueryBuilder\Condition\Like » Yiisoft\Db\QueryBuilder\Condition\AbstractLike
ImplementsYiisoft\Db\QueryBuilder\Condition\ConditionInterface

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\QueryBuilder\Condition\AbstractLike
fromArrayDefinition() Creates a condition based on the given operator and operands. Yiisoft\Db\QueryBuilder\Condition\AbstractLike

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_CONJUNCTION \Yiisoft\Db\QueryBuilder\Condition\LikeConjunction::And Yiisoft\Db\QueryBuilder\Condition\AbstractLike
DEFAULT_ESCAPE true Yiisoft\Db\QueryBuilder\Condition\AbstractLike
DEFAULT_MODE \Yiisoft\Db\QueryBuilder\Condition\LikeMode::Contains Yiisoft\Db\QueryBuilder\Condition\AbstractLike

Method Details

Hide inherited methods

__construct() public method
public mixed __construct ( Yiisoft\Db\Expression\ExpressionInterface|string $column, Yiisoft\Db\Expression\ExpressionInterface|integer|iterable|string|\Stringable|null $value, boolean|null $caseSensitive null, boolean $escape self::DEFAULT_ESCAPE, \Yiisoft\Db\QueryBuilder\Condition\LikeMode $mode self::DEFAULT_MODE, \Yiisoft\Db\QueryBuilder\Condition\LikeConjunction $conjunction self::DEFAULT_CONJUNCTION )
$column Yiisoft\Db\Expression\ExpressionInterface|string

The column name.

$value Yiisoft\Db\Expression\ExpressionInterface|integer|iterable|string|\Stringable|null

The value to the right of operator.

$caseSensitive boolean|null

Whether the comparison is case-sensitive. null means using the default behavior.

$escape boolean

Whether to escape the value. Defaults to true. If false, the value will be used as is without escaping.

$mode \Yiisoft\Db\QueryBuilder\Condition\LikeMode

The mode for the LIKE operation (contains, starts with, ends with or custom pattern).

$conjunction \Yiisoft\Db\QueryBuilder\Condition\LikeConjunction

The conjunction to use for combining multiple LIKE conditions.

                final public function __construct(
    public readonly string|ExpressionInterface $column,
    public readonly iterable|int|string|Stringable|ExpressionInterface|null $value,
    public readonly ?bool $caseSensitive = null,
    public readonly bool $escape = self::DEFAULT_ESCAPE,
    public readonly LikeMode $mode = self::DEFAULT_MODE,
    public readonly LikeConjunction $conjunction = self::DEFAULT_CONJUNCTION,
) {}

            
fromArrayDefinition() public static method

Defined in: Yiisoft\Db\QueryBuilder\Condition\AbstractLike::fromArrayDefinition()

Creates a condition based on the given operator and operands.

public static Yiisoft\Db\QueryBuilder\Condition\Like fromArrayDefinition ( string $operator, array $operands )
$operator string
$operands array
throws InvalidArgumentException

If the number of operands isn't 2.

                final public static function fromArrayDefinition(string $operator, array $operands): static
{
    if (!isset($operands[0], $operands[1])) {
        throw new InvalidArgumentException("Operator '$operator' requires two operands.");
    }
    if (isset($operands['mode'])) {
        $mode = $operands['mode'];
        if (!$mode instanceof LikeMode) {
            throw new InvalidArgumentException(
                sprintf(
                    'Operator "%s" requires "mode" to be an instance of %s. Got %s.',
                    $operator,
                    LikeMode::class,
                    get_debug_type($mode),
                ),
            );
        }
    } else {
        $mode = self::DEFAULT_MODE;
    }
    if (isset($operands['conjunction'])) {
        $conjunction = $operands['conjunction'];
        if (!$conjunction instanceof LikeConjunction) {
            throw new InvalidArgumentException(
                sprintf(
                    'Operator "%s" requires "conjunction" to be an instance of %s. Got %s.',
                    $operator,
                    LikeConjunction::class,
                    get_debug_type($conjunction),
                ),
            );
        }
    } else {
        $conjunction = self::DEFAULT_CONJUNCTION;
    }
    return new static(
        self::validateColumn($operator, $operands[0]),
        self::validateValue($operator, $operands[1]),
        isset($operands['caseSensitive']) ? (bool) $operands['caseSensitive'] : null,
        isset($operands['escape']) ? (bool) $operands['escape'] : self::DEFAULT_ESCAPE,
        $mode,
        $conjunction,
    );
}