class DataTransformer

Properties

protected DateTimeZone|null $dateTimezone
protected TransformationContext $defaultContext
protected TransformationContext $allContext
protected TransformationContext $persistenceContext

Methods

__construct(Container $container, DataClassRepository $dataClasses, DataConfig $config)

Create a data transformer.

defaultContext(object $data)

Get the default root context.

allContext(object $data)

Get the non-transforming root context.

persistenceContext()

Get the immutable constructable persistence context.

array
transform(BaseData|TransformableData|BaseDataCollectable|TransformableData $data, TransformationContext $context)

Transform one data object through the fixed metadata path.

array
transformForResourceResponse(BaseData|TransformableData|BaseDataCollectable|TransformableData $data, TransformationContext $context, Collection|null $rootItems = null)

Transform the root payload for Hypervel's resource response pipeline.

array
transformData(BaseData&TransformableData $data, TransformationContext $context, array $extensions, bool $resourceRoot = false)

Transform a nested data object within the current root operation.

array
transformCollectable(BaseDataCollectable&TransformableData $data, TransformationContext $context, array $extensions, bool $resourceRoot = false, Collection|null $rootItems = null)

Transform a data collection within the current root operation.

bool
reachedMaxDepth(TransformationContext $context)

Determine whether a data value lies at the maximum depth, throwing when configured to.

transformNested(BaseData|BaseDataCollectable $value, TransformationContext $context, array $extensions)

Transform a reached data value within the current root operation.

array
transformPaginatorCollectable(PaginatedDataCollection|CursorPaginatedDataCollection $data, array $items)

Transform a paginated data collection with its pagination links and metadata.

array
transformPaginator(AbstractPaginator|AbstractCursorPaginator $paginator, array $items, string|null $wrapKey)

Transform a paginator into its wrapped items, links, and metadata.

array
paginationInformation(AbstractPaginator|AbstractCursorPaginator $paginator, array $items)

Get the links and metadata describing a paginator's current page.

iterable
collectableItems(BaseDataCollectable $data)

Get collection items without triggering public transformation behavior.

array
finalizeTransformation(BaseData $data, TransformationContext $context, array $transformed, bool $resourceRoot)

Apply wrapping and resolved top-level data.

array
transformBulkCopy(BaseData $data, DataClass $dataClass)

Copy values for metadata proven to need no property transformation.

array
transformUsingRecipe(BaseData $data, DataTransformationRecipe $recipe, TransformationContext $context, array $extensions)

Transform values through immutable class metadata.

bool
includesLazy(Lazy $lazy, DataProperty $property, TransformationContext $context)

Determine if a lazy property is visible for this transformation.

mixed
transformPropertyValue(DataProperty $property, mixed $value, TransformationContext $context, array $extensions)

Transform one visible property value.

WrapExecutionType
resolveWrapExecutionType(BaseData|BaseDataCollectable $value, TransformationContext $context)

Resolve wrapping behavior for a nested transformable value.

void
ensureNestedPartialsExist(DataClass $dataClass, TransformationContext $context)

Ensure every nested partial path starts with a visible property of the data class.

mergeInstancePartials(BaseData|BaseDataCollectable $value, TransformationContext $context)

Merge a reached data instance's partials into its local context.

propertyTransformer(DataProperty $property, mixed $value, TransformationContext $context, array $extensions)

Get a custom transformer for a property value.

runtimeTransformer(mixed $value, TransformationContext $context, array $extensions)

Get an operation transformer matching a runtime value.

bool
matchesTransformable(string $transformable, mixed $value)

Determine if a transformer key matches a runtime value.

resolveTransformer(Transformer|string $transformer, array $extensions)

Resolve one transformer once for the current root operation.

NamedType|null
iterableTypeForValue(DataProperty $property, mixed $value)

Get the declared iterable type, with item metadata, that receives the runtime value.

array
transformIterable(DataProperty $property, iterable $items, Type $itemType, TransformationContext $context, array $extensions)

Transform typed iterable items while preserving supported containers.

mixed
transformIterableItem(DataProperty $property, mixed $value, Type $type, TransformationContext $context, array $extensions)

Transform one typed iterable item.

mixed
transformBuiltIn(mixed $value)

Transform one fixed built-in value.

void
propagatePartials(BaseData|BaseDataCollectable $value, TransformationContext $context, string $property)

Apply resolved partials to an unchanged nested data value.

void
propagateIterablePartials(iterable $items, TransformationContext $context, string $property)

Apply resolved partials to unchanged data items in a typed iterable.

array
filterArray(array $value, PartialTree|null $only, PartialTree|null $except)

Apply only and except selections to a plain array value.

Details

at line 59
__construct(Container $container, DataClassRepository $dataClasses, DataConfig $config)

Create a data transformer.

Parameters

Container $container
DataClassRepository $dataClasses
DataConfig $config

at line 86
TransformationContext defaultContext(object $data)

Get the default root context.

Temporary instance partials are consumed when present.

Parameters

object $data

Return Value

TransformationContext

at line 100
TransformationContext allContext(object $data)

Get the non-transforming root context.

Temporary instance partials are consumed when present.

Parameters

object $data

Return Value

TransformationContext

at line 114
TransformationContext persistenceContext()

Get the immutable constructable persistence context.

Return Value

TransformationContext

at line 122
array transform(BaseData|TransformableData|BaseDataCollectable|TransformableData $data, TransformationContext $context)

Transform one data object through the fixed metadata path.

at line 138
array transformForResourceResponse(BaseData|TransformableData|BaseDataCollectable|TransformableData $data, TransformationContext $context, Collection|null $rootItems = null)

Transform the root payload for Hypervel's resource response pipeline.

The resource wraps the root and adds its additional and pagination data, so the root leaves them out.

Parameters

BaseData|TransformableData|BaseDataCollectable|TransformableData $data
TransformationContext $context
Collection|null $rootItems

Return Value

array

at line 162
protected array transformData(BaseData&TransformableData $data, TransformationContext $context, array $extensions, bool $resourceRoot = false)

Transform a nested data object within the current root operation.

Parameters

BaseData&TransformableData $data
TransformationContext $context
array $extensions
bool $resourceRoot

Return Value

array

at line 273
protected array transformCollectable(BaseDataCollectable&TransformableData $data, TransformationContext $context, array $extensions, bool $resourceRoot = false, Collection|null $rootItems = null)

Transform a data collection within the current root operation.

Parameters

BaseDataCollectable&TransformableData $data
TransformationContext $context
array $extensions
bool $resourceRoot
Collection|null $rootItems

Return Value

array

at line 326
protected bool reachedMaxDepth(TransformationContext $context)

Determine whether a data value lies at the maximum depth, throwing when configured to.

Parameters

TransformationContext $context

Return Value

bool

at line 345
protected array|BaseData|BaseDataCollectable transformNested(BaseData|BaseDataCollectable $value, TransformationContext $context, array $extensions)

Transform a reached data value within the current root operation.

Parameters

BaseData|BaseDataCollectable $value
TransformationContext $context
array $extensions

Return Value

array|BaseData|BaseDataCollectable

at line 367
protected array transformPaginatorCollectable(PaginatedDataCollection|CursorPaginatedDataCollection $data, array $items)

Transform a paginated data collection with its pagination links and metadata.

Parameters

PaginatedDataCollection|CursorPaginatedDataCollection $data
array $items

Return Value

array

at line 384
protected array transformPaginator(AbstractPaginator|AbstractCursorPaginator $paginator, array $items, string|null $wrapKey)

Transform a paginator into its wrapped items, links, and metadata.

Parameters

AbstractPaginator|AbstractCursorPaginator $paginator
array $items
string|null $wrapKey

Return Value

array

at line 401
array paginationInformation(AbstractPaginator|AbstractCursorPaginator $paginator, array $items)

Get the links and metadata describing a paginator's current page.

Parameters

AbstractPaginator|AbstractCursorPaginator $paginator
array $items

the transformed items of the current page

Return Value

array

at line 454
protected iterable collectableItems(BaseDataCollectable $data)

Get collection items without triggering public transformation behavior.

Parameters

BaseDataCollectable $data

Return Value

iterable

at line 467
protected array finalizeTransformation(BaseData $data, TransformationContext $context, array $transformed, bool $resourceRoot)

Apply wrapping and resolved top-level data.

Parameters

BaseData $data
TransformationContext $context
array $transformed
bool $resourceRoot

Return Value

array

at line 499
protected array transformBulkCopy(BaseData $data, DataClass $dataClass)

Copy values for metadata proven to need no property transformation.

Parameters

BaseData $data
DataClass $dataClass

Return Value

array

at line 519
protected array transformUsingRecipe(BaseData $data, DataTransformationRecipe $recipe, TransformationContext $context, array $extensions)

Transform values through immutable class metadata.

Parameters

BaseData $data
DataTransformationRecipe $recipe
TransformationContext $context
array $extensions

Return Value

array

at line 568
protected bool includesLazy(Lazy $lazy, DataProperty $property, TransformationContext $context)

Determine if a lazy property is visible for this transformation.

Parameters

Lazy $lazy
DataProperty $property
TransformationContext $context

Return Value

bool

at line 600
protected mixed transformPropertyValue(DataProperty $property, mixed $value, TransformationContext $context, array $extensions)

Transform one visible property value.

Parameters

DataProperty $property
mixed $value
TransformationContext $context
array $extensions

Return Value

mixed

at line 691
protected WrapExecutionType resolveWrapExecutionType(BaseData|BaseDataCollectable $value, TransformationContext $context)

Resolve wrapping behavior for a nested transformable value.

Parameters

BaseData|BaseDataCollectable $value
TransformationContext $context

Return Value

WrapExecutionType

at line 713
protected void ensureNestedPartialsExist(DataClass $dataClass, TransformationContext $context)

Ensure every nested partial path starts with a visible property of the data class.

Flat selections of unknown names select nothing, as upstream allows.

Parameters

DataClass $dataClass
TransformationContext $context

Return Value

void

at line 738
protected TransformationContext mergeInstancePartials(BaseData|BaseDataCollectable $value, TransformationContext $context)

Merge a reached data instance's partials into its local context.

at line 760
protected Transformer|null propertyTransformer(DataProperty $property, mixed $value, TransformationContext $context, array $extensions)

Get a custom transformer for a property value.

Parameters

DataProperty $property
mixed $value
TransformationContext $context
array $extensions

Return Value

Transformer|null

at line 795
protected Transformer|null runtimeTransformer(mixed $value, TransformationContext $context, array $extensions)

Get an operation transformer matching a runtime value.

Parameters

mixed $value
TransformationContext $context
array $extensions

Return Value

Transformer|null

at line 814
protected bool matchesTransformable(string $transformable, mixed $value)

Determine if a transformer key matches a runtime value.

Parameters

string $transformable
mixed $value

Return Value

bool

at line 829
protected Transformer resolveTransformer(Transformer|string $transformer, array $extensions)

Resolve one transformer once for the current root operation.

Parameters

Transformer|string $transformer
array $extensions

Return Value

Transformer

at line 846
protected NamedType|null iterableTypeForValue(DataProperty $property, mixed $value)

Get the declared iterable type, with item metadata, that receives the runtime value.

Parameters

DataProperty $property
mixed $value

Return Value

NamedType|null

at line 864
protected array transformIterable(DataProperty $property, iterable $items, Type $itemType, TransformationContext $context, array $extensions)

Transform typed iterable items while preserving supported containers.

Parameters

DataProperty $property
iterable $items
Type $itemType
TransformationContext $context
array $extensions

Return Value

array

at line 891
protected mixed transformIterableItem(DataProperty $property, mixed $value, Type $type, TransformationContext $context, array $extensions)

Transform one typed iterable item.

Parameters

DataProperty $property
mixed $value
Type $type
TransformationContext $context
array $extensions

Return Value

mixed

at line 936
protected mixed transformBuiltIn(mixed $value)

Transform one fixed built-in value.

Parameters

mixed $value

Return Value

mixed

at line 961
protected void propagatePartials(BaseData|BaseDataCollectable $value, TransformationContext $context, string $property)

Apply resolved partials to an unchanged nested data value.

Parameters

BaseData|BaseDataCollectable $value
TransformationContext $context
string $property

Return Value

void

at line 982
protected void propagateIterablePartials(iterable $items, TransformationContext $context, string $property)

Apply resolved partials to unchanged data items in a typed iterable.

Parameters

iterable $items
TransformationContext $context
string $property

Return Value

void

at line 1010
protected array filterArray(array $value, PartialTree|null $only, PartialTree|null $except)

Apply only and except selections to a plain array value.

Parameters

array $value
PartialTree|null $only
PartialTree|null $except

Return Value

array