hydrateDocumentTotals.php
Table of Contents
Functions
- hydrateDocumentTotals() : mixed
- Hydrate an array definition with the DocumentTotals class.
Functions
hydrateDocumentTotals()
Hydrate an array definition with the DocumentTotals class.
hydrateDocumentTotals([mixed $init = null ]) : mixed
The totals are built through Reflection::hydrate() rather than the
DocumentTotals constructor : only that path honors the #[HydrateAs]
attributes declared on the class, so allowanceTotal, balanceDue,
chargeTotal, prepaidAmount, subtotal, total and totalTax come out as
MonetaryAmount instances instead of staying raw arrays. The
constructor assigns flat, and a flat assignment is exactly what leaves an
amount as [ 'value' => 62.4 , 'currency' => 'EUR' ].
Handles both a single totals array and an array of them — the second shape has no consumer today, and is accepted all the same so the helper answers like every other one of the family rather than being the one that throws a list back at the caller.
An empty array yields null : a document that carries no totals says so with
an absent value, not with an object of empty amounts.
🔑 A bare reference survives inside a list, exactly as it does on its own : a list of unresolved handles comes back as it stands, and only an entry that was an array and resolved to nothing is dropped. The keys stay gap-free — a filtered list left with holes serializes as a JSON object, and a consumer walking the value gets something it cannot walk.
Parameters
- $init : mixed = null
-
Single totals data or array of totals data.