hydrateApplicableResource.php
Table of Contents
Functions
- hydrateApplicableResource() : ApplicableResource|null
- Hydrate an array definition with the ApplicableResource class, down to the resource it points at.
Functions
hydrateApplicableResource()
Hydrate an array definition with the ApplicableResource class, down to the resource it points at.
hydrateApplicableResource([mixed $init = null ]) : ApplicableResource|null
A link is read for two things at once — the flag, to know whether it applies,
and the resource, to know what applies — so typing the head alone would leave
a consumer reading ->appliedByDefault on the link and ['id'] on the
resource beside it.
⚠️ Only the constructor path needs this. Reflection::hydrate() types the
entries on its own, Product::$hasApplicableResource
declaring the attribute for it. The two doors have to agree, which is what
this function is for.
🔑 item is typed as a Product, because that is what an applicable
resource is today : a record of the catalogue like any other. The day the
payload's own @type has to decide — a Service beside a Product — this
becomes a hydrateProductOrService() on the model of
hydrateOrganizationOrPerson(). Guessing
from a declared union instead is exactly the mistake that pattern exists to
prevent.
Use it in the 'products' definition in the DI container.
Parameters
- $init : mixed = null
-
The definition to hydrate.
Tags
Return values
ApplicableResource|null —The link, or null when there is nothing to build.