NoraLib Utils API Documentation

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
throws
RuntimeException

キャストに失敗した場合

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
bool

toArray()

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
bool

toDateTime()

DateTime型へのキャスト

private toDateTime(mixed $value) : DateTime
Parameters
$value : mixed
Return values
DateTime

toDateTimeImmutable()

DateTimeImmutable型へのキャスト

private toDateTimeImmutable(mixed $value) : DateTimeImmutable
Parameters
$value : mixed
Return values
DateTimeImmutable

toFloat()

float型へのキャスト

private toFloat(mixed $value) : float
Parameters
$value : mixed
Return values
float

toInt()

int型へのキャスト

private toInt(mixed $value) : int
Parameters
$value : mixed
Return values
int

toObject()

オブジェクト型へのキャスト

private toObject(mixed $value, string $className) : mixed
Parameters
$value : mixed
$className : string

toString()

string型へのキャスト

private toString(mixed $value) : string
Parameters
$value : mixed
Return values
string

        
On this page

Search results