Oihana PHP System

hydrateEventStatus.php

Table of Contents

Functions

hydrateEventStatus()  : mixed
Hydrate an array definition with the member class of {@see EventStatusType} it names.

Functions

hydrateEventStatus()

Hydrate an array definition with the member class of {@see EventStatusType} it names.

hydrateEventStatus([mixed $init = null ]) : mixed

A status is written one of two ways : the bare constant, when there is nothing more to say, or the member class, when there is — new EventCancelled([ 'description' => '…' ]) says why an event was called off, and a string cannot. Stored and read back, the second form comes back as a plain array like any other object, and this helper turns it into the member class again.

🔑 The bare constant comes back untouched. It is not an array, so it falls through the first guard — which is the whole point : a consumer must be able to hand this helper whichever form was stored without knowing which one it was.

The member is resolved by findEnumerationMember(), from the payload's additionalType — the URI every member states of itself since 1.5.0 — then from its @type, which carries the short name. Nothing recognized gives an EventStatusType : the status is unknown to this vocabulary, and answering null would throw away the reason it carried.

⚠️ A status is single-valued. An indexed array is still read as a list, for consistency with the rest of the family, and answers null when nothing in it resolves.

🔑 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 status data, a list of such data, or any other value.

Tags
throws
ReflectionException
example
hydrateEventStatus( EventStatusType::CANCELLED ) ;                        // the string, untouched
hydrateEventStatus( [ '@type' => 'EventCancelled' ] ) ;                    // EventCancelled
hydrateEventStatus( [ 'additionalType' => EventStatusType::POSTPONED ] ) ; // EventPostponed
On this page

Search results