Model
Model
This is an abstract class that implements the \jsonSerializable interface.
It serves as a base class for models in the Hazaar framework.
Properties
eventHooks
Legacy property rules that can be replaced with PHP 8.4+ style property hooks.
private array $eventHooksThis array will still be used to store property rules for PHP 8.3 and below as well as user defined property hooks that can be triggered with the trigger() method.
propertyAttributes
private array $propertyAttributesobjectHooks
private array $objectHooks = array (
0 => 'populate',
1 => 'populated',
2 => 'extend',
3 => 'extended',
4 => 'serialize',
5 => 'serialized',
6 => 'json',
)propertyNames
private array $propertyNamesuserProperties
private array $userPropertiesallowTypes
private array $allowTypes = array (
0 => 'bool',
1 => 'boolean',
2 => 'int',
3 => 'integer',
4 => 'float',
5 => 'double',
6 => 'string',
7 => 'array',
8 => 'object',
9 => 'null',
10 => 'mixed',
)Methods
__construct
public __construct(\stdClass $data, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | \stdClass | |
$args | mixed |
__destruct
public __destruct(): void__get
public __get(string $propertyName): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string |
__set
public __set(string $propertyName, mixed $propertyValue): voidParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | |
$propertyValue | mixed |
__isset
Checks if a property is set.
public __isset(string $propertyName): boolParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to check |
__unset
Unsets a specific property of the model.
public __unset(string $propertyName): voidThis magic method is called when an unset operation is performed on an inaccessible property of the model. It allows you to unset a specific property by its name.
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to unset |
__serialize
public __serialize(): void__unserialize
public __unserialize(array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | array |
get
Magic method called when reading inaccessible properties.
public get(string $propertyName): voidParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | The name of the property being accessed |
set
Sets the value of a property dynamically.
public set(string $propertyName, mixed $propertyValue): voidParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property |
$propertyValue | mixed | the value to set for the property |
populate
(re)Populates the model with data from an array or object.
public populate(object $data): voidThis method is used to populate the model with data from an array or object. If the object already has data, it will be overwritten by the new data. This includes any setting properties to null if they are not present in the new data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | object | the data to populate the model with |
extend
Extends the model with additional data.
public extend(object $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | object | the data to extend the model with |
count
public count(): intkeys
Returns the keys of the model object.
public keys(): voidtoArray
Converts the object to an array representation.
public toArray(?string $context, int $depth = 256): voidParameters
| Parameter | Type | Description |
|---|---|---|
$context | string | |
$depth | int |
jsonSerialize
Returns the object data as a JSON serializable array.
public jsonSerialize(): voidcurrent
public current(): mixednext
public next(): voidkey
public key(): mixedvalid
public valid(): boolrewind
public rewind(): voidtoJSON
Converts the model object to a JSON string.
public toJSON(int $flags, int $depth = 512): stringParameters
| Parameter | Type | Description |
|---|---|---|
$flags | int | |
$depth | int |
fromJSONString
Creates a new instance of the model class from a JSON string.
public fromJSONString(string $json): voidParameters
| Parameter | Type | Description |
|---|---|---|
$json | string | the JSON string to parse |
has
public has(string $propertyName): boolParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string |
defineProperty
Defines a new user property for the model.
public defineProperty(string $propertyType, string $propertyName, mixed $propertyValue): boolParameters
| Parameter | Type | Description |
|---|---|---|
$propertyType | string | the type of the property |
$propertyName | string | the name of the property |
$propertyValue | mixed | The value of the property. Default is null. |
defineRule
Defines a rule for a property in the model.
public defineRule(string $rule, string $propertyNames, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$rule | string | the name of the rule |
$propertyNames | string | the name of one or more properties |
$args | mixed |
defineEventHook
Defines an event hook for the model.
public defineEventHook(string $hookName, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$hookName | string | the name of the hook |
$args | mixed |
trigger
Triggers an event hook if it exists.
public trigger(string $hookName, mixed $args): voidThis method checks if an event hook with the given name exists in the $eventHooks array. If it does, it calls the hook with the provided arguments.
Parameters
| Parameter | Type | Description |
|---|---|---|
$hookName | string | the name of the event hook to trigger |
$args | mixed |
construct
Constroctor placeholder method.
protected construct(array $data): voidThis method is called before the model has been constructed and the data has been populated.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array |
destruct
Destructor placeholder method.
protected destruct(): voidThis method is called when the model is being destructed.
constructed
Constructed placeholder method.
protected constructed(): voidThis method is called after the model has been constructed and the data has been populated.
modelArrayToArray
Convert an array of model objects to an array of arrays.
private modelArrayToArray(array $array, ?string $context): voidThis method is used to convert an array of model objects to an array of arrays.
Parameters
| Parameter | Type | Description |
|---|---|---|
$array | array | the array of model objects to convert |
$context | string |
setUserProperty
Sets the value of a user-defined property.
private setUserProperty(string $propertyName, mixed $propertyValue): voidParameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to set |
$propertyValue | mixed | the value to set for the property |
convertPropertyValueDataType
Converts the data type of a property value based on its reflection.
private convertPropertyValueDataType(\ReflectionProperty $reflectionProperty, mixed $propertyValue): voidParameters
| Parameter | Type | Description |
|---|---|---|
$reflectionProperty | \ReflectionProperty | the reflection of the property |
$propertyValue | mixed |
convertValueDataType
Converts the value of a property to the specified data type.
private convertValueDataType(string $propertyType, mixed $propertyValue): voidParameters
| Parameter | Type | Description |
|---|---|---|
$propertyType | string | the type to which the property value should be converted |
$propertyValue | mixed | The value of the property to be converted. This value is passed by reference. |
getFullClassName
private getFullClassName(string $className, \ReflectionProperty $reflectionProperty): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$className | string | |
$reflectionProperty | \ReflectionProperty |
execPropertyAttributes
Executes the property rules for a given property.
private execPropertyAttributes(mixed $value, \ReflectionProperty $property, array $rules): boolParameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | |
$property | \ReflectionProperty | |
$rules | array | the array of rules to be applied |
initialize
Model initializer.
private initialize(\stdClass $data, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | \stdClass | the data to initialize the model with |
$args | mixed |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000