TypeCaster
in package
型キャストユーティリティ
Reflection型情報を使って、値を指定された型に自動変換します。
Table of Contents
Methods
- cast() : mixed
- 値を指定された型にキャストする
- castForNamedType() : mixed
- Named型へのキャスト
- castForUnionType() : mixed
- Union型へのキャスト
- isCorrectType() : bool
- 値が指定された型に既に一致しているかチェック
- toArray() : array<string|int, mixed>
- array型へのキャスト
- toBool() : bool
- bool型へのキャスト
- toDateTime() : DateTime
- DateTime型へのキャスト
- toDateTimeImmutable() : DateTimeImmutable
- DateTimeImmutable型へのキャスト
- toFloat() : float
- float型へのキャスト
- toInt() : int
- int型へのキャスト
- toObject() : mixed
- オブジェクト型へのキャスト
- toString() : string
- string型へのキャスト
Methods
cast()
値を指定された型にキャストする
public
cast(mixed $value, ReflectionType|null $type[, bool $allowsNull = false ]) : mixed
Parameters
- $value : mixed
-
キャスト対象の値
- $type : ReflectionType|null
-
目標の型情報
- $allowsNull : bool = false
-
nullを許容するか
Tags
Return values
mixed —キャストされた値
castForNamedType()
Named型へのキャスト
private
castForNamedType(mixed $value, ReflectionNamedType $type) : mixed
Parameters
- $value : mixed
- $type : ReflectionNamedType
castForUnionType()
Union型へのキャスト
private
castForUnionType(mixed $value, ReflectionUnionType $type) : mixed
Parameters
- $value : mixed
- $type : ReflectionUnionType
isCorrectType()
値が指定された型に既に一致しているかチェック
private
isCorrectType(mixed $value, string $typeName) : bool
Parameters
- $value : mixed
- $typeName : string
Return values
booltoArray()
array型へのキャスト
private
toArray(mixed $value) : array<string|int, mixed>
Parameters
- $value : mixed
Return values
array<string|int, mixed>toBool()
bool型へのキャスト
private
toBool(mixed $value) : bool
Parameters
- $value : mixed
Return values
booltoDateTime()
DateTime型へのキャスト
private
toDateTime(mixed $value) : DateTime
Parameters
- $value : mixed
Return values
DateTimetoDateTimeImmutable()
DateTimeImmutable型へのキャスト
private
toDateTimeImmutable(mixed $value) : DateTimeImmutable
Parameters
- $value : mixed
Return values
DateTimeImmutabletoFloat()
float型へのキャスト
private
toFloat(mixed $value) : float
Parameters
- $value : mixed
Return values
floattoInt()
int型へのキャスト
private
toInt(mixed $value) : int
Parameters
- $value : mixed
Return values
inttoObject()
オブジェクト型へのキャスト
private
toObject(mixed $value, string $className) : mixed
Parameters
- $value : mixed
- $className : string
toString()
string型へのキャスト
private
toString(mixed $value) : string
Parameters
- $value : mixed