MetaSql final class
Minn\Query\MetaSql · public/minn/src/Minn/Query/MetaSql.php · 291 lines
The JOIN and WHERE fragments of a meta query in the reference's shape: one meta-table join per clause (the first under the table's own name, then mt1, mt2, ...), INNER joins unless an OR relation or a NOT EXISTS clause needs LEFT ones, and casts by the clause's declared type. Under an OR relation a clause shares an equality-shaped sibling's join.
Constants and properties
| private | COMPATIBLE = array ( 0 => '=', 1 => 'IN', 2 => 'BETWEEN', 3 => 'LIKE', 4 => 'REGEXP', 5 => 'RLIKE', 6 => '>', 7 => '>=', 8 => '<', 9 => '<=', ) | |
| private | OPERATORS = array ( 0 => '=', 1 => '!=', 2 => '>', 3 => '>=', 4 => '<', 5 => '<=', 6 => 'LIKE', 7 => 'NOT LIKE', 8 => 'IN', 9 => 'NOT IN', 10 => 'BETWEEN', 11 => 'NOT BETWEEN', 12 => 'EXISTS', 13 => 'NOT EXISTS', 14 => 'REGEXP', 15 => 'NOT REGEXP', 16 => 'RLIKE', ) | |
| private | array $clauses | |
| private | int $aliasCount | |
| private | ?Closure $aliasFilter | |
| private | readonly string $metaTable | Promoted from the constructor. |
| private | readonly string $objectColumn | Promoted from the constructor. |
| private | readonly string $primaryTable | Promoted from the constructor. |
| private | readonly string $primaryId | Promoted from the constructor. |
Public
| new | __construct(string $metaTable, string $objectColumn, string $primaryTable, string $primaryId)# | |
| static | sanitize(array $queries): array# | Normalises a raw meta_query: clauses get key/value/compare/type defaults, a nested group its relation, and a "relation" key sits on every level. Named clauses keep their names. |
| static | isFirstOrder(array $query): bool# | A clause rather than a group: it names a key or a value. |
| method | build(array $queries): array# | The JOIN and WHERE fragments for a meta query. @return array{join: string, where: string} |
| method | sqlClauses(array $queries): array# | The whole query's JOIN and WHERE (get_sql_clauses), each clause given its alias in place. @return array{join: string, where: string} @return array{join: string, where: string} |
| method | querySql(array $queries, int $depth): array# | A group's JOIN and WHERE (get_sql_for_query), indented for its depth; each clause is given its alias in place, so its siblings can share it. @return array{join: string, where: string} |
| method | clauseSql(array $clause, array $parent, string $key): array# | One clause's JOIN and WHERE pieces (get_sql_for_clause): the clause is settled in place (compare, compare_key, then its alias and cast), its alias shared with a compatible sibling or a new join. @return array{where: list<string>, join: list<string>} |
| method | filterAliasesWith(Closure $filter): self# | Has every clause's shared alias (or false) pass through a filter (WP_Meta_Query hands it meta_query_find_compatible_table_alias). |
| method | compatibleAlias(array $clause, array $parent): string|false# | The alias of a sibling the clause can share (find_compatible_table_alias): under OR, the first sibling already given an alias whose comparison, like the clause's, reads the same join; false otherwise. |
| method | clauses(): array# | The clauses the last build resolved, by name. @return array<string, array{alias: string, cast: string}> clauses seen while building, by name or alias |
| static | hasOr(array $queries): bool# | Whether any level of the query relates two or more clauses by OR. |
| static | cast(string $type): string# | The CAST target for a clause type; CHAR means no cast. |
Internals 7
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | normalized(array $clause): array# | A clause with its compare and compare_key settled: upper case, IN for a list, = for anything unknown. @return array<string, mixed> @return array<string, mixed> |
| private | hasOrWithNotExists(array $queries): bool# | An OR group holding a NOT EXISTS clause makes every join a LEFT one. |
| private | clause(array $clause): string# | A settled clause's WHERE piece, read from its alias. |
| private | keyClause(string $alias, array $clause): string# | |
| private | valueClause(string $compare, mixed $value): string# | |
| private | values(mixed $value): array# | @return list<string> a list, or a comma-separated string split |
| private | newAlias(array $clause): array# | A new alias for a clause, and the join that reads it: LEFT for NOT EXISTS (with the key), INNER otherwise. @return array{0: string, 1: list<string>} @return array{0: string, 1: list<string>} |
Nothing matches.