class ModelCastHelper

Methods

__construct(ReflectionProvider $reflectionProvider, Parser $parser, bool $parseModelCastsMethod, ScopeFactory $scopeFactory, DeclarationDependencyTracker $declarationDependencyTracker, ModelHelper $modelHelper)

Create a new model cast helper instance.

Type
getReadableType(string $cast, Type $originalType)

Get the type a cast attribute reads as.

Type
getWriteableType(string $cast, Type $originalType)

Get the type a cast attribute accepts.

Type
getDateType()

Get the type a date attribute reads as.

Type
getDateWriteableType()

Get the type a date attribute accepts, which fromDateTime() converts.

bool
hasCastForProperty(ClassReflection $modelClassReflection, string $propertyName)

Determine whether the model casts the property, including with a cast that cannot be determined.

bool
hasCastEntry(ClassReflection $modelClassReflection, string $propertyName)

Determine whether the model's casts name the property, which makes it an attribute even without a column.

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.

ClassReflection|null
getCastClass(string $cast)

Get the class a cast names, as HasAttributes::isClassCastable() reads it, or null for a primitive cast type.

ClassReflection|null
getCaster(string $cast)

Get the caster whose get() and set() methods type a class cast, which run even for null values.

bool
readsEmptyStringAsNull(string $cast)

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.

Parameters

ReflectionProvider $reflectionProvider
Parser $parser
bool $parseModelCastsMethod
ScopeFactory $scopeFactory
DeclarationDependencyTracker $declarationDependencyTracker
ModelHelper $modelHelper

at line 119
Type getReadableType(string $cast, Type $originalType)

Get the type a cast attribute reads as.

Parameters

string $cast
Type $originalType

Return Value

Type

at line 178
Type getWriteableType(string $cast, Type $originalType)

Get the type a cast attribute accepts.

Parameters

string $cast
Type $originalType

Return Value

Type

at line 307
Type getDateType()

Get the type a date attribute reads as.

Return Value

Type

at line 317
Type getDateWriteableType()

Get the type a date attribute accepts, which fromDateTime() converts.

Return Value

Type

at line 365
bool hasCastForProperty(ClassReflection $modelClassReflection, string $propertyName)

Determine whether the model casts the property, including with a cast that cannot be determined.

Parameters

ClassReflection $modelClassReflection
string $propertyName

Return Value

bool

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.

Parameters

ClassReflection $modelClassReflection
string $propertyName

Return Value

bool

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.

Parameters

ClassReflection $modelClassReflection
string $propertyName

Return Value

string|null

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.

Parameters

string $cast

Return Value

ClassReflection|null

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.

Parameters

string $cast

Return Value

ClassReflection|null

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().

Parameters

string $cast

Return Value

bool