class Caster implements CasterInterface (View source)

Constants

SHORT_LIMIT

LONG_LIMIT

BYTE_MAX_VALUE

BYTE_MIN_VALUE

MISMATCH_MESSAGE

Properties

protected $value
protected $dateClass
protected $inflector
protected $properties
protected $trueValues
protected $falseValues

Methods

__construct(Hydrator $hydrator, Cached $inflector, mixed $value = null, string $dateClass = '\\DateTime')

Instantiates a new Caster.

boolean
castBoolean()

Casts the given $value to boolean or tries to guess if it's an implicit boolean value, like the string 'true'.

string
castBinary()

Casts the given $value to a binary.

mixed
castByte()

Casts the given $value to a byte.

castDate()

Casts the given $value to a DateTime object.

castDateTime()

Casts the given $value to a DateTime object.

integer
castDecimal()

Casts the internal value to an integer cmprehended between a range of accepted integers.

float
castDouble()

Casts the given $value to a double (well.

mixed
castEmbedded()

Given an embedded record, it uses the manager to hydrate it.

Array
castEmbeddedList()

Casts a list of embedded entities

Array
castEmbeddedMap()

Casts a map (key-value preserved) of embedded entities

Array
castEmbeddedSet()

Casts a set of embedded entities

float
castFloat()

Casts the value to a float.

integer
castInteger()

Casts the value into an integer.

mixed|null
castLink()

No description

Array
castLinkset()

Hydrates multiple objects through a Mapper.

Array
castLinklist()

Hydrates multiple objects through a Mapper.

Array
castLinkmap()

Hydrates multiple objects through a Mapper.

mixed
castLong()

Casts the given $value to a long.

integer
castInBuffer(integer $limit, string $type)

Casts the current value into an integer verifying it belongs to a certain range ( -$limit < $value > + $limit ).

mixed
castNone()

This function is mostly for embedded arrays of mixed type as it is primarily just a way to bypass the caster

string
castString()

Casts the value to string.

mixed
castShort()

Casts the value to a short.

setProperty(string $key, mixed $property)

Defines properties that can be internally used by the caster.

setValue(mixed $value)

Sets the internal value to work with.

assignDateClass(string $class)

Assigns the class used to cast dates and datetimes.

Array
castArrayOf(string $type)

Given a $type, it casts each element of the value array with a method.

Array
castEmbeddedArrays()

Casts embedded arrays, given the $cast property of the internal annotation.

Array|null
castLinkCollection()

Given the internal value of the caster (an array), it iterates over each element of the array and hydrates it.

convertJsonCollectionToArray()

If a JSON value is converted in an object containing other objects to hydrate, this method converts the main object in an array.

string
getDateClass()

Returns the class used to cast date and datetimes.

getHydrator()

Returns the hydrator.

mixed
getProperty(string $key)

Returns a property of the Caster, given its $key.

handleMismatch(Closure $castFunction, $expectedType)

No description

raiseMismatch($expectedType)

Throws an exception whenever $value can not be casted as $expectedType.

Details

__construct(Hydrator $hydrator, Cached $inflector, mixed $value = null, string $dateClass = '\\DateTime')

Instantiates a new Caster.

Parameters

Hydrator $hydrator
Cached $inflector
mixed $value
string $dateClass The class used to cast dates and datetimes

boolean castBoolean()

Casts the given $value to boolean or tries to guess if it's an implicit boolean value, like the string 'true'.

Return Value

boolean

string castBinary()

Casts the given $value to a binary.

Return Value

string

mixed castByte()

Casts the given $value to a byte.

Return Value

mixed

Exceptions

CastingMismatchException

DateTime castDate()

Casts the given $value to a DateTime object.

If the value was stored as a timestamp, it sets the value to the DateTime object via the setTimestamp method.

Return Value

DateTime

DateTime castDateTime()

Casts the given $value to a DateTime object.

Return Value

DateTime

integer castDecimal()

Casts the internal value to an integer cmprehended between a range of accepted integers.

Return Value

integer

float castDouble()

Casts the given $value to a double (well.

.. float).

Return Value

float

mixed castEmbedded()

Given an embedded record, it uses the manager to hydrate it.

Return Value

mixed

Array castEmbeddedList()

Casts a list of embedded entities

Return Value

Array

Array castEmbeddedMap()

Casts a map (key-value preserved) of embedded entities

Return Value

Array

Array castEmbeddedSet()

Casts a set of embedded entities

Return Value

Array

float castFloat()

Casts the value to a float.

Return Value

float

integer castInteger()

Casts the value into an integer.

Return Value

integer

Array castLinkset()

Hydrates multiple objects through a Mapper.

Return Value

Array

Hydrates multiple objects through a Mapper.

Return Value

Array

Array castLinkmap()

Hydrates multiple objects through a Mapper.

A conversion needs to be done because of the non linearity of a JSON collection compared to a PHP array.

Return Value

Array

mixed castLong()

Casts the given $value to a long.

Return Value

mixed

integer castInBuffer(integer $limit, string $type)

Casts the current value into an integer verifying it belongs to a certain range ( -$limit < $value > + $limit ).

Parameters

integer $limit
string $type

Return Value

integer

Exceptions

CastingMismatchException

mixed castNone()

This function is mostly for embedded arrays of mixed type as it is primarily just a way to bypass the caster

Return Value

mixed

string castString()

Casts the value to string.

Return Value

string

mixed castShort()

Casts the value to a short.

Return Value

mixed

setProperty(string $key, mixed $property)

Defines properties that can be internally used by the caster.

Parameters

string $key
mixed $property

setValue(mixed $value)

Sets the internal value to work with.

Parameters

mixed $value

protected assignDateClass(string $class)

Assigns the class used to cast dates and datetimes.

If the $class is a subclass of \DateTime, it uses it, it uses \DateTime otherwise.

Parameters

string $class

protected Array castArrayOf(string $type)

Given a $type, it casts each element of the value array with a method.

Parameters

string $type

Return Value

Array

Array castEmbeddedArrays()

Casts embedded arrays, given the $cast property of the internal annotation.

Return Value

Array

protected Array|null castLinkCollection()

Given the internal value of the caster (an array), it iterates over each element of the array and hydrates it.

Return Value

Array|null

See also

Caster::castLink for more insights

protected convertJsonCollectionToArray()

If a JSON value is converted in an object containing other objects to hydrate, this method converts the main object in an array.

protected string getDateClass()

Returns the class used to cast date and datetimes.

Return Value

string

protected Hydrator getHydrator()

Returns the hydrator.

Return Value

Hydrator

protected mixed getProperty(string $key)

Returns a property of the Caster, given its $key.

Parameters

string $key

Return Value

mixed

protected handleMismatch(Closure $castFunction, $expectedType)

Parameters

Closure $castFunction
$expectedType

protected raiseMismatch($expectedType)

Throws an exception whenever $value can not be casted as $expectedType.

Parameters

$expectedType