Skip to content
PHP Ecosystem
Explore

TypeCollector

API reference › Model › TypeCollector

final classUIAwesome\Model\TypeCollector
Sourcesrc/TypeCollector.php

Collects and manages model property types and values.

MethodDescriptionDefined by
__construct()Collects property metadata for the supplied model.TypeCollector
add()Adds a new property to the list of properties types.TypeCollector
getTypes()Returns the list of properties types indexed by property name.TypeCollector
getValue()Returns the value of a property.TypeCollector
has()Checks whether a property exists.TypeCollector
isForModel()Checks whether this collector is bound to the exact model instance.TypeCollector
isType()Checks whether a property supports the specified type.TypeCollector
phpTypeCast()Converts the value of an property to the type specified by type hinting in the PHPDoc.TypeCollector
setValue()Sets a value for one property.TypeCollector
setValues()Sets values for multiple properties at once.TypeCollector
toArray()Returns an array representation of the model properties and their values.TypeCollector
withModel()Copies collector state for the same model class without collecting metadata or assigning values again.TypeCollector
public function __construct(UIAwesome\Model\ModelInterface $model)

Collects property metadata for the supplied model.

Parameters

ParameterTypeDescription
$modelModelInterfaceModel whose properties are collected and assigned.
public function add(string $property, array|string $type): void

Adds a new property to the list of properties types.

Parameters

ParameterTypeDescription
$propertystringName of the property.
$typearray|stringType of the property.
public function getTypes(): array

Returns the list of properties types indexed by property name.

Returns

array: List of properties types indexed by property name.

public function getValue(string $property): mixed

Returns the value of a property.

Dot notation is supported for nested models, for example profile.email.

Parameters

ParameterTypeDescription
$propertystringProperty name.

Returns

mixed: Value of the property.

public function has(string $property): bool

Checks whether a property exists.

Dot notation is supported for nested models, for example profile.email.

Parameters

ParameterTypeDescription
$propertystringProperty name.

Returns

bool: true if the property exists, false otherwise.

public function isForModel(UIAwesome\Model\ModelInterface $model): bool

Checks whether this collector is bound to the exact model instance.

Parameters

ParameterTypeDescription
$modelModelInterface

Returns

bool

public function isType(string $property, string $type): bool

Checks whether a property supports the specified type.

Parameters

ParameterTypeDescription
$propertystringProperty name.
$typestringType name.

Returns

bool: true if the property supports the specified type, false otherwise.

public function phpTypeCast(string $property, mixed $value): mixed

Converts the value of an property to the type specified by type hinting in the PHPDoc.

Parameters

ParameterTypeDescription
$propertystringProperty name.
$valuemixedValue to be converted.

Returns

mixed: Value of the property converted to the type specified by PHPDoc.

public function setValue(string $property, mixed $value): void

Sets a value for one property.

Dot notation is supported for nested models, for example profile.email.`

Parameters

ParameterTypeDescription
$propertystringThe property name.
$valuemixedThe value to assign.
public function setValues(array $data, array $except = []): void

Sets values for multiple properties at once.

Parameters

ParameterTypeDescription
$dataarray
$exceptarray
public function toArray(bool $snakeCase, array $exceptProperties = []): array

Returns an array representation of the model properties and their values.

Parameters

ParameterTypeDescription
$snakeCaseboolWhether to convert property names to snake_case.
$exceptPropertiesarrayCamelCase property names to exclude from the resulting array.

Returns

array: An array representation of the model properties and their values.

public function withModel(UIAwesome\Model\ModelInterface $model): self

Copies collector state for the same model class without collecting metadata or assigning values again.

Parameters

ParameterTypeDescription
$modelModelInterface

Returns

self

Throws