Struct
Struct
This is an abstract class that implements the \jsonSerializable interface.
class Struct implements \jsonSerializable , \Iterator , \ArrayAccess , \Countable , \Hazaar\DBI\Interface\InsertableImplements: jsonSerializable, Iterator, ArrayAccess, Countable, Hazaar\DBI\Interface\Insertable
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 $eventHooksType: array
This 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 $propertyAttributesType: array
objectHooks
private array $objectHooks = array (
0 => 'populate',
1 => 'populated',
2 => 'extend',
3 => 'extended',
4 => 'serialize',
5 => 'serialized',
6 => 'json',
)Type: array
propertyNames
private array $propertyNamesType: array
userProperties
private array $userPropertiesType: array
allowTypes
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',
)Type: array
Methods
__construct
Model constructor.
public __construct(mixed $data, mixed $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | the data to initialize the model with |
$args | mixed |
__destruct
public __destruct(): void__get
Magic getter for accessing properties dynamically.
public __get(string $propertyName): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to get |
__set
Magic setter for setting properties dynamically.
public __set(string $propertyName, mixed $propertyValue): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to set |
$propertyValue | mixed | the value to set for the property |
__isset
Checks if a property is set.
public __isset(string $propertyName): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to check |
__unset
Unsets a specific property of the model.
public __unset(string $propertyName): voidReturns: void
This 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
Magic method for serializing the object.
public __serialize(): arrayReturns: array
__unserialize
public __unserialize(array $data): voidReturns: void
Parameters
| 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): voidReturns: void
Parameters
| 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(array|object $data): voidReturns: void
This 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 | array | object |
extend
Extends the model with additional data.
public extend(array|object $data): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | object |
count
Returns the number of property names in the struct.
public count(): intReturns: int
keys
Returns the keys of the model object.
public keys(?array $context): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$context | array | the context(s) in which to get the keys, if any |
toArray
Converts the object to an array representation.
public toArray(array|string|null $context, int $depth = 256): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$context | array | string |
$depth | int |
jsonSerialize
Returns the object data as a JSON serializable array.
public jsonSerialize(): arrayReturns: array
current
Returns the current element in the iterator.
public current(): mixedReturns: mixed
next
Moves the iterator to the next element.
public next(): voidReturns: void
key
Returns the key of the current element in the iterator.
public key(): mixedReturns: mixed
valid
Checks if the current iterator position is valid.
public valid(): boolReturns: bool
rewind
Rewinds the iterator to the first element.
public rewind(): voidReturns: void
toJSON
Converts the model object to a JSON string.
public toJSON(?string $context, int $flags, int $depth = 512): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$context | string | the context for serialization |
$flags | int | JSON encoding options |
$depth | int | maximum depth for JSON encoding |
has
Checks if a property with the given name exists in the struct.
public has(string $propertyName): boolReturns: bool
This method verifies whether the specified property name is present either in the predefined property names or in the user-defined properties.
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyName | string | the name of the property to check |
defineProperty
Defines a new user property for the model.
public defineProperty(string $propertyType, string $propertyName, mixed $propertyValue): boolReturns: bool
Parameters
| 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, array|string $propertyNames, mixed $args): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$rule | string | the name of the rule |
$propertyNames | array | string |
$args | mixed |
defineEventHook
Defines an event hook for the model.
public defineEventHook(string $hookName, mixed $args): voidReturns: void
Parameters
| 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): voidReturns: void
This 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 |
offsetExists
public offsetExists(mixed $offset): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetGet
public offsetGet(mixed $offset): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetSet
public offsetSet(mixed $offset, mixed $value): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset(mixed $offset): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
initialise
Struct initializer.
public initialise(mixed $data, mixed $constructorArgs): voidReturns: void
Errors during initialization will throw PropertyException exceptions immediately.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | the data to initialize the model with |
$constructorArgs | mixed |
parseArrayElementType
Parses the @var (or, for a method, @return) docblock of an array-typed property/return
public parseArrayElementType(false|string $docComment, \ReflectionMethod|\ReflectionProperty $reflectionMember, string $tag = 'var'): ?arrayReturns: array
value to determine its declared element type.
Supports the array<ValueType> / array<KeyType, ValueType> generic form (including nested array<...> value types) and the ValueType[] shorthand, tolerant of whitespace and of a trailing description after the type. Any other syntax (e.g. PHPStan array-shape syntax like array{name: string}) is left alone: this returns null so no per-element conversion is attempted, the same as when there's no recognized type at all.
Parameters
| Parameter | Type | Description |
|---|---|---|
$docComment | false | string |
$reflectionMember | ReflectionMethod | ReflectionProperty |
$tag | string | the docblock tag to read (var or return) |
setReflectionPropertyValue
Sets the value of a reflection property.
protected setReflectionPropertyValue(\ReflectionProperty $reflectionProperty, array $data): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$reflectionProperty | ReflectionProperty | the reflection property to set |
$data | array | the data to set the property value |
initialiseUserProperties
Initializes user-defined properties.
protected initialiseUserProperties(array $data): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | the data to initialize the user properties with |
construct
Constructor placeholder method.
protected construct(mixed $data): voidReturns: void
This method is called before the model has been constructed and the data has been populated. This allows for data to be modified or prepared before the model properties are set.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | the data to initialize the model with |
destruct
Destructor placeholder method.
protected destruct(): voidReturns: void
This method is called when the model is being destructed.
constructed
Constructed placeholder method.
protected constructed(): voidReturns: void
This 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, ?array $context): voidReturns: void
This 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 | array | one or more contexts for serialization |
setUserProperty
Sets the value of a user-defined property.
private setUserProperty(string $propertyName, mixed $propertyValue): voidReturns: void
Parameters
| 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, string $propertyName): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$reflectionProperty | ReflectionProperty | the reflection of the property |
$propertyValue | mixed | |
$propertyName | string |
convertValueDataType
Converts the value of a property to the specified data type.
private convertValueDataType(array|string $propertyType, mixed $propertyValue, string $propertyName): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$propertyType | array | string |
$propertyValue | mixed | The value of the property to be converted. This value is passed by reference. |
$propertyName | string | the name of the property being converted |
parseArrayOrListType
Parses a single array<...> or Type[] type expression into a key/value spec.
private parseArrayOrListType(string $typeExpression, \ReflectionMethod|\ReflectionProperty $reflectionProperty): ?arrayReturns: array
Returns null when the expression isn't one of those two forms, so callers can fall back to leaving the value unconverted (top level) or treating it as a plain leaf type name (nested).
Parameters
| Parameter | Type | Description |
|---|---|---|
$typeExpression | string | |
$reflectionProperty | ReflectionMethod | ReflectionProperty |
extractBalancedGeneric
Finds the contents between the < immediately after a leading array and its matching >,
private extractBalancedGeneric(string $typeExpression): ?stringReturns: string
tracking bracket depth so nested generics (array<string, array<Foo>>) resolve correctly and anything after the matching > (e.g. a docblock description) is ignored rather than preventing the match entirely.
Parameters
| Parameter | Type | Description |
|---|---|---|
$typeExpression | string |
resolveArraySpec
Splits the inner contents of an array<...> expression into its key/value halves.
private resolveArraySpec(string $inner, \ReflectionMethod|\ReflectionProperty $reflectionProperty): arrayReturns: array
A key type is only recorded when it's explicitly given (the two-argument form) and is one of the recognised array key types (int/integer/string); the single-argument form (array<Foo>) is treated as key-unconstrained, matching how it's actually used throughout this codebase (e.g. DBI\Manager\Schema's $tables/$views/etc. are populated as string-keyed maps despite using the single-argument form) and PHPStan's own semantics (array<Foo> means array<array-key, Foo>, distinct from list<Foo>).
Parameters
| Parameter | Type | Description |
|---|---|---|
$inner | string | |
$reflectionProperty | ReflectionMethod | ReflectionProperty |
resolveElementType
Resolves a single (trimmed) value-type token from an array<...>/Type[] expression: either a
private resolveElementType(string $typeExpression, \ReflectionMethod|\ReflectionProperty $reflectionProperty): array|stringReturns: array|string
nested array/list spec, one of the builtin scalar types, or a class name resolved via use-statement lookup (falling back to the declaring class's namespace).
Parameters
| Parameter | Type | Description |
|---|---|---|
$typeExpression | string | |
$reflectionProperty | ReflectionMethod | ReflectionProperty |
validateArrayKeyType
Validates an array element's key against a declared key type, if any (a null key type is
private validateArrayKeyType(mixed $key, ?string $keyType, string $propertyName): voidReturns: void
unconstrained and always passes).
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | mixed | |
$keyType | string | |
$propertyName | string |
getFullClassName
private getFullClassName(string $className, \ReflectionMethod|\ReflectionProperty $reflectionProperty): ?stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$className | string | |
$reflectionProperty | ReflectionMethod | ReflectionProperty |
execPropertyAttributes
Executes the property rules for a given property.
private execPropertyAttributes(mixed $value, \ReflectionProperty $property, array $rules): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | |
$property | ReflectionProperty | |
$rules | array | the array of rules to be applied |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000