TypeCollector
API reference › Model › TypeCollector
Collects and manages model property types and values.
Methods
Section titled “Methods”| Method | Description | Defined 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(UIAwesome\Model\ModelInterface $model)Collects property metadata for the supplied model.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | ModelInterface | Model whose properties are collected and assigned. |
add()
Section titled “add() ”public function add(string $property, array|string $type): voidAdds a new property to the list of properties types.
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | Name of the property. |
$type | array| | Type of the property. |
getTypes()
Section titled “getTypes() ”public function getTypes(): arrayReturns the list of properties types indexed by property name.
Returns
array: List of properties types indexed by property name.
getValue()
Section titled “getValue() ”public function getValue(string $property): mixedReturns the value of a property.
Dot notation is supported for nested models, for example profile.email.
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | Property name. |
Returns
mixed: Value of the property.
has()
Section titled “has() ”public function has(string $property): boolChecks whether a property exists.
Dot notation is supported for nested models, for example profile.email.
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | Property name. |
Returns
bool: true if the property exists, false otherwise.
isForModel()
Section titled “isForModel() ”public function isForModel(UIAwesome\Model\ModelInterface $model): boolChecks whether this collector is bound to the exact model instance.
isType()
Section titled “isType() ”public function isType(string $property, string $type): boolChecks whether a property supports the specified type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | Property name. |
$type | string | Type name. |
Returns
bool: true if the property supports the specified type, false otherwise.
phpTypeCast()
Section titled “phpTypeCast() ”public function phpTypeCast(string $property, mixed $value): mixedConverts the value of an property to the type specified by type hinting in the PHPDoc.
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | Property name. |
$value | mixed | Value to be converted. |
Returns
mixed: Value of the property converted to the type specified by PHPDoc.
setValue()
Section titled “setValue() ”public function setValue(string $property, mixed $value): voidSets a value for one property.
Dot notation is supported for nested models, for example profile.email.`
Parameters
| Parameter | Type | Description |
|---|---|---|
$property | string | The property name. |
$value | mixed | The value to assign. |
setValues()
Section titled “setValues() ”public function setValues(array $data, array $except = []): voidSets values for multiple properties at once.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | |
$except | array |
toArray()
Section titled “toArray() ”public function toArray(bool $snakeCase, array $exceptProperties = []): arrayReturns an array representation of the model properties and their values.
Parameters
| Parameter | Type | Description |
|---|---|---|
$snakeCase | bool | Whether to convert property names to snake_case. |
$exceptProperties | array | CamelCase property names to exclude from the resulting array. |
Returns
array: An array representation of the model properties and their values.
withModel()
Section titled “withModel() ”public function withModel(UIAwesome\Model\ModelInterface $model): selfCopies collector state for the same model class without collecting metadata or assigning values again.
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | ModelInterface |
Returns
self
Throws
InvalidArgumentException: if the target model has a different concrete class.