hydrateOrganizationOrPerson.php
Table of Contents
Functions
- hydrateOrganizationOrPerson() : mixed
- Hydrate an array definition into an Organization or a Person.
Functions
hydrateOrganizationOrPerson()
Hydrate an array definition into an Organization or a Person.
hydrateOrganizationOrPerson([mixed $init = null ][, string $organizationClass = Organization::class ][, string $personClass = Person::class ]) : mixed
Organization|Person is a common Schema.org union (e.g. Order::$customer,
Order::$seller, Invoice::$broker/$provider, Event::$funder...) that
Reflection::hydrate() cannot resolve from the property type alone : the
declared union always resolves to its first class member, so a Person payload
silently comes out as an (empty-ish) Organization. This helper reads the
payload's JSON-LD @type instead : Person gives a Person (or
$personClass), anything else — Organization itself, or one of its many
subtypes (Corporation, LocalBusiness, GovernmentOrganization...) — gives
an Organization (or $organizationClass), which stays the safe default
when @type is absent or unrecognized.
$organizationClass/$personClass let a caller pin the target to a business
subtype instead of the plain Schema.org class — e.g.
xyz\oihana\schema\organizations\Customer (extends Organization) or
xyz\oihana\schema\people\CustomerEmployee (extends Person) — as long as
each stays a subclass of the type it replaces, so the property's declared
union type still holds.
Handles both a single definition and an indexed list of definitions.
Parameters
- $init : mixed = null
-
Single Organization/Person data, a list of such data, or any other value.
- $organizationClass : string = Organization::class
-
The class hydrated when the payload is not a Person. Must extend Organization.
- $personClass : string = Person::class
-
The class hydrated when the payload's
@typesays Person. Must extend Person.