16-05-1994T00:00:00+00 could be cast into a Carbon object.
Cast Interface
Implement theCast interface:
Parameters
- property -
DataPropertyobject representing the property being cast (read more) - value - The value to be cast
- properties - Array of current properties for creating the data object
- creationContext - Context containing:
dataClass- The data class being createdvalidationStrategy- The validation strategy in usemapPropertyNames- Whether property names should be mappeddisableMagicalCreation- Whether to use magical creation methodsignoredMagicalMethods- Which magical methods are ignoredcasts- Collection of global casts
Return Value
Return the casted value, or anUncastable object if the cast cannot be performed.
Handling Null
Casts never receive
null values. The package keeps null as null to avoid creating values out of thin air. Use magic methods if you need to replace null values.Castables
Allow value objects to define their own casting logic:Castable with Arguments
Pass arguments to the castable:Castable Implementation
Implement theCastable interface:
Casting Iterable Values
Cast items in arrays or Collections by implementingIterableItemCast:
castIterableItem method is called for each item. Check $property->type->iterableItemType to get the target type.
Combining Casts and Transformers
Create a class that both casts and transforms:WithCastAndTransformer attribute: