class ToClass extends Mutator (View source)

Converts a value to a class instance using the given class' constructor.

If the value is already an instance of the given class, it will be returned as-is. If the value is an array, it can be spread into the constructor by setting $spread to true.

Methods

__construct(string $class, bool $spread = false)

No description

mixed
__invoke(mixed $value)

Mutate the input value.

from  Mutator
static ToClass
make(string $class, bool $spread = false)

No description

mixed
mutate(mixed $value)

Mutate the input value.

Details

__construct(string $class, bool $spread = false)

No description

Parameters

string $class

The class to convert to

bool $spread

Whether to spread an array into the constructor or not (default: false)

final mixed __invoke(mixed $value)

Mutate the input value.

Parameters

mixed $value

Return Value

mixed

static ToClass make(string $class, bool $spread = false)

No description

Parameters

string $class

The class to convert to

bool $spread

Whether to spread an array into the constructor or not (default: false)

Return Value

ToClass

mixed mutate(mixed $value)

Mutate the input value.

Parameters

mixed $value

Return Value

mixed