Oihana PHP System

documents

Table of Contents

Functions

hydrateBusinessDocument()  : mixed
Hydrate an array definition with the BusinessDocument class, or one of its subclasses ({@see \xyz\oihana\schema\business\documents\Quote}, {@see \xyz\oihana\schema\business\documents\PurchaseOrder}, {@see Invoice}, {@see \xyz\oihana\schema\business\documents\CreditNote}, {@see \xyz\oihana\schema\business\documents\DebitNote}, {@see \xyz\oihana\schema\business\documents\DeliveryNote}, {@see \xyz\oihana\schema\business\documents\GoodsReceiptConfirmation}, {@see \xyz\oihana\schema\business\documents\Receipt}, {@see \xyz\oihana\schema\business\documents\RemittanceAdvice}, {@see \xyz\oihana\schema\business\documents\Statement}).
hydrateDocumentLine()  : mixed
Hydrate an array definition with the BusinessDocumentLine class.
hydrateDocumentLineItem()  : mixed
Hydrate an array definition with the product or service class of a document line item.

Functions

hydrateBusinessDocument()

Hydrate an array definition with the BusinessDocument class, or one of its subclasses ({@see \xyz\oihana\schema\business\documents\Quote}, {@see \xyz\oihana\schema\business\documents\PurchaseOrder}, {@see Invoice}, {@see \xyz\oihana\schema\business\documents\CreditNote}, {@see \xyz\oihana\schema\business\documents\DebitNote}, {@see \xyz\oihana\schema\business\documents\DeliveryNote}, {@see \xyz\oihana\schema\business\documents\GoodsReceiptConfirmation}, {@see \xyz\oihana\schema\business\documents\Receipt}, {@see \xyz\oihana\schema\business\documents\RemittanceAdvice}, {@see \xyz\oihana\schema\business\documents\Statement}).

hydrateBusinessDocument([mixed $init = null ][, string $class = BusinessDocument::class ]) : mixed

Handles both a single document array and an array of documents. The document itself is built through Reflection::hydrate(), which honors every #[HydrateAs]/#[HydrateWith] attribute declared across the hierarchy (adjustments, taxes, totals, documentLines...).

customer, seller and author are the exception, on every document class : their Organization|Person union cannot be resolved from the property type alone — reflection always picks Organization, even for a Person payload — so they are re-resolved from the raw payload through hydrateOrganizationOrPerson(). On an Invoice, broker and provider carry the same union and get the same treatment.

The document's ParcelDelivery carries the same union one level down, on its own provider — the carrier. Reflection builds the delivery through #[HydrateAs], so nothing inside it was ever re-resolved : orderDelivery.provider is therefore given the same treatment from the raw payload, once the delivery itself has been hydrated.

Parameters
$init : mixed = null

Single document data or array of document data.

$class : string = BusinessDocument::class

The BusinessDocument subclass to hydrate into. Defaults to BusinessDocument itself.

Tags
throws
HydrationException
ReflectionException
example
hydrateBusinessDocument( $raw ) ;                          // BusinessDocument
hydrateBusinessDocument( $raw , Invoice::class ) ;          // Invoice — also resolves broker/provider
hydrateBusinessDocument( $raw , Quote::class ) ;            // Quote

hydrateDocumentLine()

Hydrate an array definition with the BusinessDocumentLine class.

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

Handles both a single line array and an array of lines — the two shapes a BusinessDocument documentLines payload can take.

The line is built through Reflection::hydrate() rather than the BusinessDocumentLine constructor : only that path honors the #[HydrateAs] / #[HydrateWith] attributes declared on the class, so adjustments, price (and its priceComponent breakdown), quantity, subtotal, taxes and total come out typed instead of staying raw arrays.

The item property is the exception : its Product|Service union cannot be resolved from the property type alone, so it is delegated to hydrateDocumentLineItem() which reads the payload's @type.

Parameters
$init : mixed = null

Single line data or array of line data.

Tags
throws
HydrationException
ReflectionException

hydrateDocumentLineItem()

Hydrate an array definition with the product or service class of a document line item.

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

The item of a BusinessDocumentLine is typed as a Product|Service union, which no property type can resolve on its own : the target class is therefore read from the payload's JSON-LD @type.

  • a @type ending with Service (e.g. Service, FoodService) gives a Service ;
  • anything else gives a Product — the commerce-enriched product of this package, which is a org\schema\Product and so satisfies the line's declared type.
Parameters
$init : mixed = null

Single item data or array of item data.

Tags
throws
HydrationException
ReflectionException
On this page

Search results