API / Minn\Runtime / Meta

Meta final readonly class

Minn\Runtime\Meta · public/minn/src/Minn/Runtime/Meta.php · 242 lines

The four meta tables behind get_metadata and friends: reads by object, and the row-level writes the update and delete rules need.

Constants and properties

privateTABLES = array ( 'post' => array ( 0 => 'postmeta', 1 => 'post_id', 2 => 'meta_id', ), 'user' => array ( 0 => 'usermeta', 1 => 'user_id', 2 => 'umeta_id', ), 'term' => array ( 0 => 'termmeta', 1 => 'term_id', 2 => 'meta_id', ), 'comment' => array ( 0 => 'commentmeta', 1 => 'comment_id', 2 => 'meta_id', ), )
privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
staticknows(string $type): bool#

Whether an object type has a meta table.

staticclausesFromQueryVars(array $queryVars): array#

The meta query in flat query vars (meta_key, meta_value, the compare and type variants) as one clause, AND'd ahead of an explicit meta_query as its own group, as WP_Meta_Query::parse_query_vars reads them. An empty meta_value is no value.

$queryVarsarray<string, mixed>
@return array<array-key, mixed>
methodall(string $type, int $objectId): array#

Every row of an object's meta, values as stored, grouped by key in id order. @return array<string, list<string>>

@return array<string, list<string>>
methodprime(string $type, array $objectIds): array#

update_meta_cache: each object's meta as all() gives it, the cached ones from the object cache and the rest read in one query and cached; an object with none has an empty list.

$objectIdslist<int>
@return array<int, array<string, list<string>>>
methodkeys(string $type): array#

Every meta key an object type uses, once each, in key order. @return list<string>

@return list<string>
methodlisting(string $type, int $objectId): array#

Every row of an object's meta by key, then id, as the post meta box lists them: the key, the value, the row's id and the object's, all as stored (strings).

@return list<array<string, string>>
methodrowsOf(string $type, int $objectId): array#

Every row of an object's meta in id order, for removing them one by one. @return list<array{meta_id: int, meta_key: string, meta_value: string}>

@return list<array{meta_id: int, meta_key: string, meta_value: string}>
methodbyId(string $type, int $metaId): ?array#

One meta row by its id, under the table's own column names, values as stored; null when there is none. @return array<string, string>|null

@return array<string, string>|null
methodcolumns(string $type): array#

The column holding the object's id, and the one holding the row's: post_id and meta_id, user_id and umeta_id. @return array{0: string, 1: string}

@return array{0: string, 1: string}
methodrewrite(string $type, int $metaId, string $key, string $stored): void#

Sets one row's key and stored value.

methodadd(string $type, int $objectId, string $key, string $stored): int#

Inserts a meta row and returns its id.

methodmatching(string $type, int $objectId, string $key): array#

The rows of one key on one object, in id order. @return list<array{meta_id: int, meta_value: string}>

@return list<array{meta_id: int, meta_value: string}>
staticidsToUpdate(array $rows, string $stored, ?string $previous): array#

Which of a key's rows an update touches: none when no previous value was named and the first row already holds the value, all of them when no previous value was named, otherwise only the rows holding it.

$rowslist<array<string, mixed>>
@return list<int>
methodupdateRows(string $type, array $ids, string $stored): void#

Sets the value of the given meta rows.

methodfind(string $type, ?int $objectId, string $key, ?string $stored): array#

The rows a delete would take: by key, for one object or all, optionally only a stored value. @return list<array{meta_id: int, object_id: int}>

@return list<array{meta_id: int, object_id: int}>
methodobjectsBelow(string $type, string $key, int $bound): array#

The objects whose value under the key is a number below the bound, lowest id first. @return list<int>

@return list<int>
methoddeleteRows(string $type, array $ids): void#

Deletes the given meta rows.

$idslist<int>

Internals 1

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

privatespec(string $type): array#

The table, object column, and row id column of a meta type. @return array{0: string, 1: string, 2: string}

@return array{0: string, 1: string, 2: string}