class CreationContextFactory

Properties

protected ValidationStrategy $validationStrategy
protected bool $mapPropertyNames
protected bool $disableMagicalCreation
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.

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 80
__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 94
CreationContextFactory validationStrategy(ValidationStrategy $validationStrategy)

Set the validation strategy.

Parameters

ValidationStrategy $validationStrategy

Return Value

CreationContextFactory

at line 105
CreationContextFactory withoutValidation()

Disable validation.

Return Value

CreationContextFactory

at line 113
CreationContextFactory onlyValidateRequests()

Validate only Request sources.

Return Value

CreationContextFactory

at line 123
CreationContextFactory alwaysValidate()

Validate every source.

Return Value

CreationContextFactory

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

Enable or disable property-name mapping.

Parameters

bool $withPropertyNameMapping

Return Value

CreationContextFactory

at line 142
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 177
CreationContextFactory ignoreMagicalMethod(string ...$methods)

Ignore named creation methods for this operation.

Parameters

string ...$methods

Return Value

CreationContextFactory

at line 190
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 203
CreationContextFactory withCastCollection(array $casts)

Merge casts for declared base types.

Parameters

array $casts

Return Value

CreationContextFactory

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

Add custom source normalizers.

Parameters

Normalizer|string ...$normalizers

Return Value

CreationContextFactory

at line 227
CreationContextFactory prepareData(Closure $hook)

Add a prepare-data hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 238
CreationContextFactory beforeValidation(Closure $hook)

Add a before-validation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 249
CreationContextFactory beforeRules(Closure $hook)

Add a before-rules hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 260
CreationContextFactory afterRules(Closure $hook)

Add an after-rules hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 271
CreationContextFactory withValidator(Closure $hook)

Add a validator customization hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 282
CreationContextFactory afterValidation(Closure $hook)

Add an after-validation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 293
CreationContextFactory beforeCreation(Closure $hook)

Add a before-creation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

at line 304
CreationContextFactory afterCreation(Closure $hook)

Add an after-creation hook.

Parameters

Closure $hook

Return Value

CreationContextFactory

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

Build immutable options for one root operation.

Parameters

CreationMode $mode

Return Value

CreationContext

at line 356
protected void invalidateCreateContext()

Invalidate the immutable Create context after factory customization.

Return Value

void

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

Create a data object.

Parameters

mixed ...$payloads

Return Value

BaseData

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

Validate a payload without casting or construction.

Parameters

Arrayable|array $payload

Return Value

Arrayable|array

at line 388
array getValidationRules(array $payload)

Get validation rules for a payload.

Parameters

array $payload

Return Value

array

at line 469
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.

at line 486
Enumerable collectItems(mixed $items)

internal  
 

Create typed items without whole-collection factory dispatch.

Parameters

mixed $items

Return Value

Enumerable