ModelCastHelper
class ModelCastHelper
Methods
Create a new model cast helper instance.
Get the type a cast attribute reads as.
Get the type a cast attribute accepts.
Get the type a date attribute reads as.
Get the type a date attribute accepts, which fromDateTime() converts.
Determine whether the model casts the property, including with a cast that cannot be determined.
Determine whether the model's casts name the property, which makes it an attribute even without a column.
Get the model's cast for the property, or null when it has none or its cast cannot be determined.
Get the class a cast names, as HasAttributes::isClassCastable() reads it, or null for a primitive cast type.
Get the caster whose get() and set() methods type a class cast, which run even for null values.
Determine whether a cast reads an empty string as null, as the JSON casts do through HasAttributes::fromJson().
Details
at line 103
__construct(ReflectionProvider $reflectionProvider, Parser $parser, bool $parseModelCastsMethod, ScopeFactory $scopeFactory, DeclarationDependencyTracker $declarationDependencyTracker, ModelHelper $modelHelper)
Create a new model cast helper instance.
at line 119
Type
getReadableType(string $cast, Type $originalType)
Get the type a cast attribute reads as.
at line 178
Type
getWriteableType(string $cast, Type $originalType)
Get the type a cast attribute accepts.
at line 307
Type
getDateType()
Get the type a date attribute reads as.
at line 317
Type
getDateWriteableType()
Get the type a date attribute accepts, which fromDateTime() converts.
at line 365
bool
hasCastForProperty(ClassReflection $modelClassReflection, string $propertyName)
Determine whether the model casts the property, including with a cast that cannot be determined.
at line 375
bool
hasCastEntry(ClassReflection $modelClassReflection, string $propertyName)
Determine whether the model's casts name the property, which makes it an attribute even without a column.
at line 383
string|null
getCastForProperty(ClassReflection $modelClassReflection, string $propertyName)
Get the model's cast for the property, or null when it has none or its cast cannot be determined.
at line 393
ClassReflection|null
getCastClass(string $cast)
Get the class a cast names, as HasAttributes::isClassCastable() reads it, or null for a primitive cast type.
Class names are case-insensitive, so a primitive type such as datetime would otherwise name DateTime.
at line 410
ClassReflection|null
getCaster(string $cast)
Get the caster whose get() and set() methods type a class cast, which run even for null values.
Returns null for primitive, enum and built-in object casts, which are typed here directly, and for a Castable whose caster cannot be determined.
at line 437
bool
readsEmptyStringAsNull(string $cast)
Determine whether a cast reads an empty string as null, as the JSON casts do through HasAttributes::fromJson().