API / Minn\Query / TaxSql

TaxSql final class

Minn\Query\TaxSql · public/minn/src/Minn/Query/TaxSql.php · 197 lines

The JOIN and WHERE fragments of a taxonomy query in the reference's shape: IN clauses join term_relationships (the first under the table's own name, then tt1, tt2, ..., shared between IN siblings under OR), NOT IN and AND read subqueries, EXISTS checks the taxonomy, and a term nobody has yields "0 = 1".

Constants and properties

privateint $aliasCount
privatereadonly string $relationships

Promoted from the constructor.

privatereadonly string $termTaxonomy

Promoted from the constructor.

privatereadonly string $primaryTable

Promoted from the constructor.

privatereadonly string $primaryId

Promoted from the constructor.

privatereadonly Closure $termTaxonomyIds

Promoted from the constructor.

Public

new__construct(string $relationships, string $termTaxonomy, string $primaryTable, string $primaryId, Closure $termTaxonomyIds)#
$termTaxonomyIdsClosure(string, string, list<mixed>, bool): list<int>taxonomy, field, terms, include children
staticsanitize(array $queries): array#

The query as the reference keeps it: each clause merged over the defaults (taxonomy, terms as a list, field term_id, operator IN, children included), a nested group given relation AND when it has none, an empty group dropped. The top level keeps a relation only when one was given.

$queriesarray<array-key, mixed>
@return array<array-key, mixed>
staticisFirstOrder(mixed $query): bool#

Whether a query part is a clause (it names a clause key, or is empty) rather than a group.

staticqueried(array $queries, array $queried = array ( )): array#

The terms a sanitized query asks for, by taxonomy: the first terms and the first field each taxonomy's clauses give, NOT IN clauses aside.

$queriesarray<array-key, mixed>
@return array<string, array{terms?: list<mixed>, field?: string}>
methodbuild(array $queries): array#

The JOIN and WHERE fragments for a taxonomy query.

@return array{join: string, where: string}
methodsqlClauses(array $queries): array#

The whole query's JOIN and WHERE (get_sql_clauses), each clause settled in place. @return array{join: string, where: string}

@return array{join: string, where: string}
methodquerySql(array $queries, int $depth): array#

A group's JOIN and WHERE (get_sql_for_query), indented for its depth. @return array{join: string, where: string}

@return array{join: string, where: string}
methodclauseSql(array $clause, array $parent): array#

One clause's JOIN and WHERE pieces (get_sql_for_clause). Its terms are turned into term_taxonomy_ids in place; an IN clause reads term_relationships under an alias it shares with a compatible sibling or joins anew, and keeps that alias. A term nobody has yields "0 = 1" (nothing at all for NOT IN).

@return array{where: list<string>, join: list<string>}
methodcompatibleAlias(array $clause, array $parent): string|false#

The alias of an IN sibling the clause can share under OR (find_compatible_table_alias), or false.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateoperator(array $clause): string#
privateinClause(array $clause, array $parent, string $list): array#
@return array{where: list<string>, join: list<string>}