Oihana PHP System

hydrateParcelDelivery.php

Table of Contents

Functions

hydrateParcelDelivery()  : mixed
Hydrate an array definition with the ParcelDelivery class — where the goods go, how they travel, on which round and for when.

Functions

hydrateParcelDelivery()

Hydrate an array definition with the ParcelDelivery class — where the goods go, how they travel, on which round and for when.

hydrateParcelDelivery([mixed $init = null ][, DefinedTerm> $deliveryMethodClass = DeliveryMethodTerm::class ][, DefinedTerm> $deliveryRouteClass = DeliveryRouteTerm::class ]) : mixed

Handles both a single delivery array and an array of them.

The delivery is built through the ParcelDelivery constructor, and its references are resolved one by one afterwards. Reflection::hydrate() would bring nothing here : the class declares no #[HydrateAs] on deliveryAddress, hasDeliveryMethod or hasDeliveryRoute, so reflection would leave the three of them raw while adding its own strictness — it drops whatever the class does not declare, and a delivery read back from a store commonly carries more than Schema.org names.

The two travel terms are parameters rather than hard-wired classes, and that is the reason this helper lives under xyz\oihana while ParcelDelivery is plain org\schema : a thesaurus term belongs to the business layer, and an attribute on the Schema.org class would make the lower layer depend on the upper one. The defaults name the business terms; any DefinedTerm subclass may replace them, which is what the property's own declared type asks for.

provider — the carrier — carries the Organization|Person union that reflection cannot resolve from the property type alone, so it goes through hydrateOrganizationOrPerson(), which reads the payload's @type.

Each resolution happens only when the value is still an array — when there is something to hydrate — and its answer is then written as is, null included : an array that resolves to nothing becomes null, never a leftover raw array.

🔑 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 delivery data or array of delivery data.

$deliveryMethodClass : DefinedTerm> = DeliveryMethodTerm::class

The class the delivery method is hydrated into.

$deliveryRouteClass : DefinedTerm> = DeliveryRouteTerm::class

The class the delivery route is hydrated into.

Tags
throws
HydrationException
ReflectionException
example
$delivery = hydrateParcelDelivery
([
    'deliveryAddress'   => [ 'streetAddress' => '8 Rue Paul Gros' , 'postalCode' => '33270' ] ,
    'hasDeliveryMethod' => [ 'id' => 'F13' , 'name' => 'Franco de port' ] ,
    'hasDeliveryRoute'  => [ 'id' => '54'  , 'name' => 'Libourne / rive droite' ] ,
]) ;

$delivery->deliveryAddress   instanceof PostalAddress      ; // true
$delivery->hasDeliveryMethod instanceof DeliveryMethodTerm ; // true
$delivery->hasDeliveryRoute  instanceof DeliveryRouteTerm  ; // true
On this page

Search results