API / Minn\Runtime / TermQuery

TermQuery final readonly class

Minn\Runtime\TermQuery · public/minn/src/Minn/Runtime/TermQuery.php · 376 lines

Term reads in the shapes plugin code asks for: get_terms() arguments to rows, the tree filters (child_of, exclude_tree), the fields shapes, and the single-term lookups. Behaviour pinned by contracts/fixtures/api/content.json.

Used by 1

Constants and properties

constDEFAULTS = array ( 'taxonomy' => NULL, 'object_ids' => NULL, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'include' => array ( ), 'exclude' => array ( ), 'exclude_tree' => array ( ), 'number' => '', 'offset' => '', 'fields' => 'all', 'count' => false, 'name' => '', 'slug' => '', 'term_taxonomy_id' => '', 'hierarchical' => true, 'search' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'get' => '', 'child_of' => 0, 'parent' => '', 'childless' => false, 'cache_domain' => 'core', 'update_term_meta_cache' => true, 'meta_query' => '', 'meta_key' => '', 'meta_value' => '', )
privateCOLUMNS = 't.term_id, t.name, t.slug, t.term_group, tt.term_taxonomy_id, tt.taxonomy, tt.description, tt.parent, tt.count'
privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Closure $slug

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Closure $slug)#
$slugClosure(string): stringthe slug sanitiser, so the reference's filters apply
methodrow(int $termId, ?string $taxonomy): ?array#

A term row joined with its taxonomy row, by id (and taxonomy when known). @return array<string, mixed>|null

@return array<string, mixed>|null
methodfind(string $field, mixed $value, ?string $taxonomy): ?array#

The term id and taxonomy a field value names; null when nothing matches or the field is not one a term can be found by.

@return array{term_id: int, taxonomy: string}|null
methodexists(string|int $term, ?string $taxonomy, ?int $parent): ?array#

Whether a term (by id, or by slug or name) exists, optionally under a taxonomy and parent; the ids when it does.

@return array{term_id: int, term_taxonomy_id: int}|null
methodlookup(string $field, string $value, ?string $taxonomy, ?int $parent): ?array#

The term whose slug or name (as stored) is exactly the value, optionally in a taxonomy and under a parent (0 for the top level).

@return array{term_id: int, term_taxonomy_id: int}|null
methodhasChildren(int $parent, ?array $taxonomies): bool#

Whether any term in the taxonomies (any taxonomy for null) sits under the parent: the reference answers a lookup under a childless parent with nothing before it looks.

$taxonomieslist<string>|null
methodslugTaken(string $slug, int $exceptTermId): bool#

Whether a term other than the one named holds the slug, in any taxonomy.

methodnormalise(array $args): array#

get_terms() arguments normalised: the "get all" shortcut, integer lists, sanitised slugs.

methodrows(array $args, ?array $taxonomies): array#

The term rows the arguments match, ordered and paged, with the tree filters applied.

$taxonomieslist<string>|null
@return list<array<string, mixed>>
methodhierarchy(string $taxonomy): array#

Every parent in a taxonomy that has children, mapped to its children's ids. A taxonomy nobody nested reads as an empty map.

@return array<int, list<int>>
methodchildren(int $termId, string $taxonomy): array#

Every term id under a term, however deep. @return list<int>

@return list<int>
methodobjectsIn(array $termIds, array $taxonomies, string $order): array#

The object ids attached to any of the terms in any of the taxonomies. @param list<int> $termIds @param list<string> $taxonomies @return list<int>

$termIdslist<int>@param list<string> $taxonomies @return list<int>

Internals 7

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

privatereadRow(int $termId, ?string $taxonomy): ?array#
@return array<string, mixed>|null
privateidList(mixed $value): array#

A comma list, array, or blank as positive ids. @return list<int>

@return list<int>
privatedescendants(array $rows, int $root): array#

The rows under a term, however deep, in source order. @param list<array<string, mixed>> $rows @return list<array<string, mixed>>

$rowslist<array<string, mixed>>@return list<array<string, mixed>>
privatewhere(array $args, ?array $taxonomies): array#
@return array{0: string, 1: string, 2: list<mixed>} the join, the WHERE clause, its parameters
privatemetaClauses(array $args): array#
@return list<array{key: string, value?: mixed}>
privateids(mixed $list): array#
@return list<int>
privatelike(string $needle): string#