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 $includeAdditionalData = true)

Transform a nested data object within the current root operation.

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

Transform a data collection within the current root operation.

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 paginator while retaining its native metadata.

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

Serialize a paginator clone with replacement items while retaining native metadata.

iterable
collectableItems(BaseDataCollectable $data)

Get collection items without triggering public transformation behavior.

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

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.

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.

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

Get iterable item metadata accepted by 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 55
__construct(Container $container, DataClassRepository $dataClasses, DataConfig $config)

Create a data transformer.

Parameters

Container $container
DataClassRepository $dataClasses
DataConfig $config

at line 80
TransformationContext defaultContext(object $data)

Get the default root context.

Temporary instance partials are consumed when present.

Parameters

object $data

Return Value

TransformationContext

at line 94
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 108
TransformationContext persistenceContext()

Get the immutable constructable persistence context.

Return Value

TransformationContext

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

Transform one data object through the fixed metadata path.

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

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

Parameters

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

Return Value

array

at line 154
protected array transformData(BaseData&TransformableData $data, TransformationContext $context, array $extensions, bool $includeAdditionalData = true)

Transform a nested data object within the current root operation.

Parameters

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

Return Value

array

at line 256
protected array transformCollectable(BaseDataCollectable&TransformableData $data, TransformationContext $context, array $extensions, bool $includePaginationData = true, Collection|null $rootItems = null)

Transform a data collection within the current root operation.

Parameters

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

Return Value

array

at line 310
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 332
protected array transformPaginatorCollectable(PaginatedDataCollection|CursorPaginatedDataCollection $data, array $items)

Transform a paginator while retaining its native metadata.

Parameters

PaginatedDataCollection|CursorPaginatedDataCollection $data
array $items

Return Value

array

at line 355
protected array transformPaginator(AbstractPaginator|AbstractCursorPaginator $paginator, array $items)

Serialize a paginator clone with replacement items while retaining native metadata.

Parameters

AbstractPaginator|AbstractCursorPaginator $paginator
array $items

Return Value

array

at line 369
protected iterable collectableItems(BaseDataCollectable $data)

Get collection items without triggering public transformation behavior.

Parameters

BaseDataCollectable $data

Return Value

iterable

at line 379
protected array finalizeTransformation(BaseData $data, TransformationContext $context, array $transformed, bool $includeAdditionalData)

Apply wrapping and resolved top-level data.

Parameters

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

Return Value

array

at line 408
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 428
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 477
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 509
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 586
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 606
protected TransformationContext mergeInstancePartials(BaseData|BaseDataCollectable $value, TransformationContext $context)

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

at line 628
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 663
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 682
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 697
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 714
protected Type|null iterableTypeForValue(DataProperty $property, mixed $value)

Get iterable item metadata accepted by the runtime value.

Parameters

DataProperty $property
mixed $value

Return Value

Type|null

at line 730
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 757
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 802
protected mixed transformBuiltIn(mixed $value)

Transform one fixed built-in value.

Parameters

mixed $value

Return Value

mixed

at line 827
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 848
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 889
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