class TypeConversion (View source)

Type conversion utility class

Methods

static 
to(mixed $value, string $type, callable $fallback)

No description

static array
toArray(mixed $value, callable $fallback = null)

Convert value to POD array

toDateTime(mixed $value, DateTimeZone $timezone = null, callable $fallback = null)

Convert value to DateTime

static integer
toInteger(mixed $value, callable $fallback = null)

Convert value to integer

static float
toFloat(mixed $value, callable $fallback = null)

Convert value to float

static string
toString(mixed $value, callable $fallback = null)

Convert value to string

static boolean
toBoolean(mixed $value)

Convert value to boolean

Details

static to(mixed $value, string $type, callable $fallback)

Parameters

mixed $value Value to convert
string $type Target type.
callable $fallback A cacallback to invoke if the method is nuable to convert the value e

Exceptions

BadMethodCallException

static array toArray(mixed $value, callable $fallback = null)

Convert value to POD array

Parameters

mixed $value Value to convert
callable $fallback A cacallback to invoke if the method is nuable to convert the value e

Return Value

array

Exceptions

TypeConversionException

static DateTimeInterface toDateTime(mixed $value, DateTimeZone $timezone = null, callable $fallback = null)

Convert value to DateTime

Parameters

mixed $value Value to convert
DateTimeZone $timezone Time zone of constructed DateTime.
callable $fallback A cacallback to invoke if the method is nuable to convert the value e

Return Value

DateTimeInterface A DateTime with the given time zone.

Exceptions

TypeConversionException

static integer toInteger(mixed $value, callable $fallback = null)

Convert value to integer

Parameters

mixed $value Value to convert
callable $fallback A cacallback to invoke if the method is nuable to convert the value e

Return Value

integer

Exceptions

TypeConversionException

static float toFloat(mixed $value, callable $fallback = null)

Convert value to float

Parameters

mixed $value Value to convert
callable $fallback A cacallback to invoke if the method is nuable to convert the value e

Return Value

float

Exceptions

TypeConversionException

static string toString(mixed $value, callable $fallback = null)

Convert value to string

Parameters

mixed $value Value to convert to string
callable $fallback This callable will be invoked if there is no straigntforward conversion. The callable must accept one argument (the value) and return a string or FALSE if it is unable to convert the value to string.

Return Value

string

Exceptions

TypeConversionException

static boolean toBoolean(mixed $value)

Convert value to boolean

Parameters

mixed $value Value to convert

Return Value

boolean