API / Minn\Rest / Fields

Fields final readonly class

Minn\Rest\Fields · public/minn/src/Minn/Rest/Fields.php · 106 lines

The _fields response filter. Dot paths descend ("title.rendered"); the object's own key order is kept. Applied per item on list responses and to the whole payload otherwise, which is why _fields on the associative types response strips every key and yields [] over HTTP, a reference quirk the engine reproduces by construction.

Constants and properties

propreadonly array $paths

Promoted from the constructor.

propreadonly bool $deferred

Promoted from the constructor.

Public

new__construct(array $paths, bool $deferred = false)#

embedded first and filtered by Embed afterwards

$pathslist<string>
$deferredbooltrue when _embed rides along: a single object is
staticfromQuery(array $query): ?self#

The _fields selection a query carries, or null for everything.

$queryarray<string, mixed>
methodwithLinksForEmbedded(): self#

The same paths plus _links whenever _embedded is among them: the reference's single-object rule under _embed.

methodwants(string $field): bool#

Whether a top-level field is among the selection: named whole, below one of its paths (title.rendered), or above one (a path into it).

methodapply(array $object): array#

The object with only the selected fields.

staticselect(array $available, array $requested): array#

The fields a response keeps when a caller names some: known fields as given, dotted paths whose root is known, and `id` whenever it exists.

$availablelist<string>
$requestedlist<string>the parsed `_fields` list
@return list<string>

Internals 1

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

privatefilter(array $object, array $paths): array#