Condition
in package
Structured shorthand condition parser class
Tags
Table of Contents
Constants
- OPERATORS = ['=' => ['method' => 'equalTo', 'arity' => 1], '!=' => ['method' => 'notEqualTo', 'arity' => 1], '>' => ['method' => 'greaterThan', 'arity' => 1], '>=' => ['method' => 'greaterThanOrEqualTo', 'arity' => 1], '<' => ['method' => 'lessThan', 'arity' => 1], '<=' => ['method' => 'lessThanOrEqualTo', 'arity' => 1], 'LIKE' => ['method' => 'like', 'arity' => 1], 'NOT LIKE' => ['method' => 'notLike', 'arity' => 1], 'IN' => ['method' => 'in', 'multi' => true], 'NOT IN' => ['method' => 'notIn', 'multi' => true], 'BETWEEN' => ['method' => 'between', 'arity' => 2], 'NOT BETWEEN' => ['method' => 'notBetween', 'arity' => 2], 'IS NULL' => ['method' => 'isNull', 'arity' => 0], 'IS NOT NULL' => ['method' => 'isNotNull', 'arity' => 0], 'CONTAINS' => ['method' => 'jsonContains', 'arity' => 1]]
- Supported operators, mapped to their PredicateSet method and value arity
Methods
- isNewSyntax() : bool
- Determine if a shorthand column value uses the new structured (operator-tuple) syntax
- isPlainEquality() : bool
- Determine if a shorthand entry is plain equality, i.e. a bare column key carrying no operator suffix paired with a scalar (or null) value
- parse() : PredicateSet
- Parse a shorthand columns array into a PredicateSet
- addParameter() : string
- Register a bound parameter under a tree-unique key and return the dialect-correct placeholder token that refers to it
- callArity0() : void
- Dispatch a no-value ('isNull'/'isNotNull') PredicateSet call
- callArity1() : void
- Dispatch a single-value PredicateSet call whose value is a bound placeholder string
- callArity1Mixed() : void
- Dispatch a single-value PredicateSet call whose value is a nested Sql\Select instance
- callArity2() : void
- Dispatch a two-value ('between'/'notBetween') PredicateSet call
- callMulti() : void
- Dispatch a 2-value ('in'/'notIn') PredicateSet call
- createParameterKey() : string
- Create a tree-unique, bind-safe parameter key for a column
- parseConditions() : PredicateSet
- Parse a shorthand columns array into a PredicateSet, threading the tree-wide parameter-key counter through each level of recursion
- parseGroup() : void
- Parse a reserved 'OR'/'AND' group key into a single combined nested PredicateSet
- parseJsonPathTuple() : void
- Parse a single new-syntax operator tuple whose column key used JSON path access ('column->path')
- parseLegacy() : void
- Parse legacy-shaped shorthand entries via the existing Expression parser, firing a deprecation notice and folding the result into the given PredicateSet
- parseMultiTuple() : void
- Parse a single new-syntax operator tuple for a multi-value ('in'/'notIn') operator
- parseTuple() : void
- Parse a single new-syntax operator tuple onto the given PredicateSet
Constants
OPERATORS
Supported operators, mapped to their PredicateSet method and value arity
protected
array<string|int, mixed>
OPERATORS
= ['=' => ['method' => 'equalTo', 'arity' => 1], '!=' => ['method' => 'notEqualTo', 'arity' => 1], '>' => ['method' => 'greaterThan', 'arity' => 1], '>=' => ['method' => 'greaterThanOrEqualTo', 'arity' => 1], '<' => ['method' => 'lessThan', 'arity' => 1], '<=' => ['method' => 'lessThanOrEqualTo', 'arity' => 1], 'LIKE' => ['method' => 'like', 'arity' => 1], 'NOT LIKE' => ['method' => 'notLike', 'arity' => 1], 'IN' => ['method' => 'in', 'multi' => true], 'NOT IN' => ['method' => 'notIn', 'multi' => true], 'BETWEEN' => ['method' => 'between', 'arity' => 2], 'NOT BETWEEN' => ['method' => 'notBetween', 'arity' => 2], 'IS NULL' => ['method' => 'isNull', 'arity' => 0], 'IS NOT NULL' => ['method' => 'isNotNull', 'arity' => 0], 'CONTAINS' => ['method' => 'jsonContains', 'arity' => 1]]
Methods
isNewSyntax()
Determine if a shorthand column value uses the new structured (operator-tuple) syntax
public
static isNewSyntax(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolisPlainEquality()
Determine if a shorthand entry is plain equality, i.e. a bare column key carrying no operator suffix paired with a scalar (or null) value
public
static isPlainEquality(string $key, mixed $value) : bool
A '(value1, value2)'-shaped string value is excluded: that is the legacy packed BETWEEN shape, which must keep routing through Expression::parseShorthand(). Its documented replacement is the unambiguous ['column' => ['BETWEEN', v1, v2]] tuple.
Parameters
- $key : string
- $value : mixed
Return values
boolparse()
Parse a shorthand columns array into a PredicateSet
public
static parse(array<string|int, mixed> $columns, AbstractSql $sql[, bool $allowLegacy = true ]) : PredicateSet
Parameters
- $columns : array<string|int, mixed>
- $sql : AbstractSql
- $allowLegacy : bool = true
Tags
Return values
PredicateSetaddParameter()
Register a bound parameter under a tree-unique key and return the dialect-correct placeholder token that refers to it
protected
static addParameter(PredicateSet $predicateSet, AbstractSql $sql, string $column, mixed $value, int &$parameterIndex) : string
For ':'-style dialects (SQLite/PDO) the returned token is ':' . the parameter key, so the token in the rendered SQL and the key in the parameter array always match exactly. For '?'-style (MySQL/SQL Server) and '$'-style (PostgreSQL) dialects only the parameter ORDER matters at bind time, but the key must still be unique so that the array_merge() in PredicateSet::getParameters() cannot drop it.
Parameters
- $predicateSet : PredicateSet
- $sql : AbstractSql
- $column : string
- $value : mixed
- $parameterIndex : int
Return values
stringcallArity0()
Dispatch a no-value ('isNull'/'isNotNull') PredicateSet call
protected
static callArity0(PredicateSet $predicateSet, string $method, string $column) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
callArity1()
Dispatch a single-value PredicateSet call whose value is a bound placeholder string
protected
static callArity1(PredicateSet $predicateSet, string $method, string $column, string $value) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
- $value : string
callArity1Mixed()
Dispatch a single-value PredicateSet call whose value is a nested Sql\Select instance
protected
static callArity1Mixed(PredicateSet $predicateSet, string $method, string $column, AbstractSql $value) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
- $value : AbstractSql
callArity2()
Dispatch a two-value ('between'/'notBetween') PredicateSet call
protected
static callArity2(PredicateSet $predicateSet, string $method, string $column, string $value1, string $value2) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
- $value1 : string
- $value2 : string
callMulti()
Dispatch a 2-value ('in'/'notIn') PredicateSet call
protected
static callMulti(PredicateSet $predicateSet, string $method, string $column, mixed $values) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
- $values : mixed
createParameterKey()
Create a tree-unique, bind-safe parameter key for a column
protected
static createParameterKey(string $column, int $parameterIndex) : string
The counter comes FIRST, so every generated key starts with a digit. That is what keeps
these keys from ever colliding with the keys the legacy path emits: the (unmodified)
Expression::parseShorthand() derives its keys straight from the column name, as either
'
Any character that is not valid in a named placeholder (e.g. the '.' of a table-qualified column) is normalized to an underscore.
Parameters
- $column : string
- $parameterIndex : int
Return values
stringparseConditions()
Parse a shorthand columns array into a PredicateSet, threading the tree-wide parameter-key counter through each level of recursion
protected
static parseConditions(array<string|int, mixed> $columns, AbstractSql $sql, bool $allowLegacy, int &$parameterIndex) : PredicateSet
Parameters
- $columns : array<string|int, mixed>
- $sql : AbstractSql
- $allowLegacy : bool
- $parameterIndex : int
Tags
Return values
PredicateSetparseGroup()
Parse a reserved 'OR'/'AND' group key into a single combined nested PredicateSet
protected
static parseGroup(PredicateSet $predicateSet, string $conjunction, mixed $groups, AbstractSql $sql, int &$parameterIndex) : void
Parameters
- $predicateSet : PredicateSet
- $conjunction : string
- $groups : mixed
- $sql : AbstractSql
- $parameterIndex : int
Tags
parseJsonPathTuple()
Parse a single new-syntax operator tuple whose column key used JSON path access ('column->path')
protected
static parseJsonPathTuple(PredicateSet $predicateSet, string $column, string $jsonPath, string $operator, array<string|int, mixed> $tuple, AbstractSql $sql, int &$parameterIndex) : void
Parameters
- $predicateSet : PredicateSet
- $column : string
- $jsonPath : string
- $operator : string
- $tuple : array<string|int, mixed>
- $sql : AbstractSql
- $parameterIndex : int
Tags
parseLegacy()
Parse legacy-shaped shorthand entries via the existing Expression parser, firing a deprecation notice and folding the result into the given PredicateSet
protected
static parseLegacy(PredicateSet $predicateSet, array<string|int, mixed> $legacyColumns, AbstractSql $sql) : void
Parameters
- $predicateSet : PredicateSet
- $legacyColumns : array<string|int, mixed>
- $sql : AbstractSql
parseMultiTuple()
Parse a single new-syntax operator tuple for a multi-value ('in'/'notIn') operator
protected
static parseMultiTuple(PredicateSet $predicateSet, string $method, string $column, string $operator, array<string|int, mixed> $tuple, AbstractSql $sql, int &$parameterIndex) : void
Parameters
- $predicateSet : PredicateSet
- $method : string
- $column : string
- $operator : string
- $tuple : array<string|int, mixed>
- $sql : AbstractSql
- $parameterIndex : int
Tags
parseTuple()
Parse a single new-syntax operator tuple onto the given PredicateSet
protected
static parseTuple(PredicateSet $predicateSet, string $column, array<string|int, mixed> $tuple, AbstractSql $sql, int &$parameterIndex) : void
Parameters
- $predicateSet : PredicateSet
- $column : string
- $tuple : array<string|int, mixed>
- $sql : AbstractSql
- $parameterIndex : int