PropertyTrait
Provides a `property` reference.
This trait allows a class to define a property reference that can be initialized from an associative array (commonly used for hydration or model initialization).
Usage:
class MyModel
{
use PropertyTrait;
}
$model = new MyModel();
$model->initializeProperty(['property' => 'name']);
echo $model->property; // outputs "name"
Tags
Table of Contents
Constants
- PROPERTY = 'property'
- The 'property' key parameter used in initialization arrays.
Properties
- $property : string|null
- The `property` reference.
Methods
- assertProperty() : static
- Asserts the existence of the 'property' key.
- initializeProperty() : static
- Initialize the `property` reference from an associative array.
Constants
PROPERTY
The 'property' key parameter used in initialization arrays.
public
mixed
PROPERTY
= 'property'
When passing an array to initializeProperty(), this key
will be checked to set the $property value.
Properties
$property
The `property` reference.
public
string|null
$property
= null
This property is typically a string identifying a key or field name within the document or model context.
Methods
assertProperty()
Asserts the existence of the 'property' key.
public
assertProperty() : static
Tags
Return values
staticinitializeProperty()
Initialize the `property` reference from an associative array.
public
initializeProperty([array<string, mixed> $init = [] ]) : static
If the array contains the key self::PROPERTY, the value will be
assigned to $property. Otherwise, the property is set to null.
Parameters
- $init : array<string, mixed> = []
-
Optional initialization array.
Tags
Return values
static —Returns $this to allow method chaining.