class CreationContextFactory

Properties

protected ValidationStrategy $validationStrategy
protected bool $mapPropertyNames
protected bool $disableMagicalCreation
protected bool $useOptionalValues
protected list<string> $ignoredMagicalMethods
protected Cast|Cast>> $casts
protected Normalizer>|Normalizer> $normalizers
protected Closure> $prepareDataHooks
protected Closure> $beforeValidationHooks
protected Closure> $beforeRulesHooks
protected Closure> $afterRulesHooks
protected Closure> $withValidatorHooks
protected Closure> $afterValidationHooks
protected Closure> $beforeCreationHooks
protected Closure> $afterCreationHooks

Methods

__construct(DataCreator $creator, DataConfig $config, string $dataClass, CreationContext|null $createContext = null)

Create a fresh data construction factory.

validationStrategy(ValidationStrategy $validationStrategy)

Set the validation strategy.

onlyValidateRequests()

Validate only Request sources.

alwaysValidate()

Validate every source.

withPropertyNameMapping(bool $withPropertyNameMapping = true)

Enable or disable property-name mapping.

withoutPropertyNameMapping(bool $withoutPropertyNameMapping = true)

Disable or enable property-name mapping.

withoutMagicalCreation(bool $withoutMagicalCreation = true)

Disable or enable named creation methods.

withMagicalCreation(bool $withMagicalCreation = true)

Enable or disable named creation methods.

withOptionalValues(bool $withOptionalValues = true)

Enable or disable Optional values for missing properties.

withoutOptionalValues(bool $withoutOptionalValues = true)

Disable or enable Optional values for missing properties.

ignoreMagicalMethod(string ...$methods)

Ignore named creation methods for this operation.

withCast(string $castable, Cast|string $cast)

Add a cast for a declared base type.

withCastCollection(array $casts)

Merge casts for declared base types.

withNormalizers(Normalizer|string ...$normalizers)

Add custom source normalizers.

prepareData(Closure $hook)

Add a prepare-data hook.

beforeValidation(Closure $hook)

Add a before-validation hook.

beforeRules(Closure $hook)

Add a before-rules hook.

afterRules(Closure $hook)

Add an after-rules hook.

withValidator(Closure $hook)

Add a validator customization hook.

afterValidation(Closure $hook)

Add an after-validation hook.

beforeCreation(Closure $hook)

Add a before-creation hook.

afterCreation(Closure $hook)

Add an after-creation hook.

get(CreationMode $mode = CreationMode::Create)

Build immutable options for one root operation.

void
invalidateCreateContext()

Invalidate the immutable Create context after factory customization.

from(mixed ...$payloads)

Create a data object.

Arrayable|array
validate(Arrayable|array $payload)

Validate a payload without casting or construction.

array
getValidationRules(array $payload)

Get validation rules for a payload.

collectItems(mixed $items)

Create typed items without whole-collection factory dispatch.

Details

at line 82
__construct(DataCreator $creator, DataConfig $config, string $dataClass, CreationContext|null $createContext = null)

Create a fresh data construction factory.

Parameters

DataCreator $creator
DataConfig $config
string $dataClass
CreationContext|null $createContext

at line 96
CreationContextFactory validationStrategy(ValidationStrategy $validationStrategy)

Set the validation strategy.

Parameters

ValidationStrategy $validationStrategy

Return Value

CreationContextFactory

at line 107
CreationContextFactory withoutValidation()

Disable validation.

Return Value

CreationContextFactory

at line 115
CreationContextFactory onlyValidateRequests()

Validate only Request sources.

Return Value

CreationContextFactory

at line 125
CreationContextFactory alwaysValidate()

Validate every source.

Return Value

CreationContextFactory

at line 133
CreationContextFactory withPropertyNameMapping(bool $withPropertyNameMapping = true)

Enable or disable property-name mapping.

Parameters

bool $withPropertyNameMapping

Return Value

CreationContextFactory

at line 144
CreationContextFactory withoutPropertyNameMapping(bool $withoutPropertyNameMapping = true)

Disable or enable property-name mapping.

Parameters

bool $withoutPropertyNameMapping

Return Value

CreationContextFactory

at line 155
CreationContextFactory withoutMagicalCreation(bool $withoutMagicalCreation = true)

Disable or enable named creation methods.

Parameters

bool $withoutMagicalCreation

Return Value

CreationContextFactory

at line 166
CreationContextFactory withMagicalCreation(bool $withMagicalCreation = true)

Enable or disable named creation methods.

Parameters

bool $withMagicalCreation

Return Value

CreationContextFactory

at line 180
CreationContextFactory withOptionalValues(bool $withOptionalValues = true)

Enable or disable Optional values for missing properties.

When disabled, a missing Optional property that also accepts null receives null. One that does not accept null still receives Optional.

Parameters

bool $withOptionalValues

Return Value

CreationContextFactory

at line 191
CreationContextFactory withoutOptionalValues(bool $withoutOptionalValues = true)

Disable or enable Optional values for missing properties.

Parameters

bool $withoutOptionalValues

Return Value

CreationContextFactory

at line 202
CreationContextFactory ignoreMagicalMethod(string ...$methods)

Ignore named creation methods for this operation.

Parameters

string ...$methods

Return Value

CreationContextFactory

at line 215
CreationContextFactory withCast(string $castable, Cast|string $cast)

Add a cast for a declared base type.

Parameters

string $castable
Cast|string $cast

Return Value

CreationContextFactory

at line 228
CreationContextFactory withCastCollection(array $casts)

Merge casts for declared base types.

Parameters

array $casts

Return Value

CreationContextFactory

at line 241
CreationContextFactory withNormalizers(Normalizer|string ...$normalizers)

Add custom source normalizers.

Parameters

Normalizer|string ...$normalizers

Return Value

CreationContextFactory

at line 252
CreationContextFactory prepareData(Closure $hook)

Add a prepare-data hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 263
CreationContextFactory beforeValidation(Closure $hook)

Add a before-validation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 274
CreationContextFactory beforeRules(Closure $hook)

Add a before-rules hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 285
CreationContextFactory afterRules(Closure $hook)

Add an after-rules hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 296
CreationContextFactory withValidator(Closure $hook)

Add a validator customization hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 307
CreationContextFactory afterValidation(Closure $hook)

Add an after-validation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 318
CreationContextFactory beforeCreation(Closure $hook)

Add a before-creation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 329
CreationContextFactory afterCreation(Closure $hook)

Add an after-creation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 342
CreationContext get(CreationMode $mode = CreationMode::Create)

Build immutable options for one root operation.

Parameters

CreationMode $mode

Return Value

CreationContext

at line 382
protected void invalidateCreateContext()

Invalidate the immutable Create context after factory customization.

Return Value

void

at line 392
BaseData from(mixed ...$payloads)

Create a data object.

Parameters

mixed ...$payloads

Return Value

BaseData

at line 400
Arrayable|array validate(Arrayable|array $payload)

Validate a payload without casting or construction.

Parameters

Arrayable|array $payload

Return Value

Arrayable|array

at line 414
array getValidationRules(array $payload)

Get validation rules for a payload.

Parameters

array $payload

Return Value

array

at line 495
array|DataCollection|PaginatedDataCollection|CursorPaginatedDataCollection|Enumerable|AbstractPaginator|Paginator|AbstractCursorPaginator|CursorPaginator|LazyCollection|Collection collect(mixed $items, string|null $into = null)

Collect data objects.

Contract-typed sources retain every possible rebuildable runtime shape.

Parameters

mixed $items

null collects an empty $into target

string|null $into

Return Value

array|DataCollection|PaginatedDataCollection|CursorPaginatedDataCollection|Enumerable|AbstractPaginator|Paginator|AbstractCursorPaginator|CursorPaginator|LazyCollection|Collection )

at line 512
Enumerable collectItems(mixed $items)

internal  
 

Create typed items without whole-collection factory dispatch.

Parameters

mixed $items

Return Value

Enumerable