hydrateOffer.php
Table of Contents
Functions
- hydrateOffer() : mixed
- Hydrate an array definition with the bare {@see Offer} class.
Functions
hydrateOffer()
Hydrate an array definition with the bare {@see Offer} class.
hydrateOffer([mixed $init = null ][, string $productClass = Product::class ]) : mixed
The two offer helpers this package already carries answer narrower questions :
hydrateOfferPurchase() only ever builds an OfferForPurchase, and
hydrateAggregateOffer() an aggregate. A plain
Offer — what Organization::$makesOffer carries, and with it every
property that lists bare offers — had none.
Handles both a single offer array and an array of offers. The offer itself is built
through Reflection::hydrate(), which honors the #[HydrateAs] attributes the
class declares — eligibleQuantity comes out a QuantitativeValue, priceSpecification
a PriceSpecification, its union naming a single class that reflection resolves on its
own.
itemOffered is the exception : its CreativeWork|Event|Product|Service union cannot be
resolved from the property type alone, so the target class is read from the payload's
JSON-LD @type, exactly as hydrateDocumentLineItem()
does for a document line :
- a
@typeending withService(e.g.Service,FoodService) gives a Service ; - anything else gives
$productClass.
🔑 $productClass is what keeps this helper in org\schema. The commerce-enriched
product of this package lives in xyz\oihana\schema\products and org knows nothing of
xyz — so the default is the plain Schema.org Product, and a caller on the
business side passes its own, as long as it stays a subclass so the declared union still
holds.
Anything that is not an array — an unresolved string reference, an already typed instance — is left untouched.
🔑 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 offer data, a list of offer data, or any other value.
- $productClass : string = Product::class
-
The class hydrated when the item offered is not a service. Must extend Product.