CSR3PropertyDTOTrait
trait CSR3PropertyDTOTrait
CSR3PropertyDTOTrait.php
The CSR3PropertyDTOTrait allow to use custom DTO with properties as attribute
Properties
| protected string | $attributeContainer | Attribute container | |
| protected string | $positionContainer | Position container |
Methods
Set attribute
Get attribute
Set attributes
Get attributes
Offset exist
Offset get
Offset set
Offset unset
Current
Next
Key
Valid
Rewind
Property exist
Get properties
Set property
Get property
Details
at line 61
$this
setAttribute(string $attributeName, mixed $attributeValue)
Set attribute
This method allow to set or add an attribute to the DTO
at line 84
mixed
getAttribute(string $attributeName)
Get attribute
This method allow to retreive a value from a named attribute of the DTO
at line 106
$this
setAttributes(array $attributes)
Set attributes
This method allow to set the attributes of the DTO from an associative array
at line 122
array
getAttributes()
Get attributes
This method return the attributes as array from the DTO
at line 142
bool
offsetExists(mixed $offset)
Offset exist
This method validate the existence of an offset
at line 160
mixed
offsetGet(mixed $offset)
Offset get
This method return an offset value
at line 175
void
offsetSet(mixed $offset, mixed $value)
Offset set
This method allow to set a value at an offset place
at line 189
void
offsetUnset(mixed $offset)
Offset unset
This method remove an offset
at line 205
mixed
current()
Current
This method return the current iterated value
at line 217
void
next()
Next
This method advance the internal pointer by one step
at line 229
string
key()
Key
This method return the current iterated key
at line 241
bool
valid()
Valid
This method validate the current internal position existence
at line 255
void
rewind()
Rewind
This method reinitialize the internal position
at line 271
protected boolean
propertyExist(string $propertyName)
Property exist
This method validate that a given property name is part of the current class. This validation allow to the DTO to store a value direcly into an object property instead of the default storage array.
at line 302
protected array
getProperties()
Get properties
This method return the existants properties of the current DTO object. It unset the attribute management properties to allow the only return of storage properties.
By overriding it you can specify any private properties that you want to use inside the final DTO object. This feature must be used with the override of the setProperty() method and getProperty() method.
exemple :
protected function getProperties()
{
$privateArray = ['propA', 'propB'];
return array_merge(
parent::getProperties(),
$privateArray
);
}
at line 344
protected $this
setProperty(string $propertyName, mixed $propertyValue)
Set property
This method inject a value into an existing class property. This offer to the DTO to store a value into object properties since current attribute container.
By overriding this method you can store a value into a private class property. This feature must be used in addition with the override of the getProperties() method and getProperty() method.
exemple :
protected function setProperty(string $propertyName, $propertyValue)
{
if (in_array($propertyName, ['privatePropA', 'privatePropB'])) {
$method = 'set'.ucfirst($propertyName);
$this->$method($propertyValue);
return $this;
}
return parent::setProperty($propertyName, $propertyValue);
}
at line 378
protected mixed
getProperty(string $propertyName)
Get property
This method return a value contained into any existing property of the current DTO.
By overriding this method you can extract a value from a private class property. This feature must be used with the override of the getProperties() method and setProperty() method.
exemple :
protected function getProperty(string $propertyName)
{
if (in_array($propertyName, ['privatePropA', 'privatePropB'])) {
$method = 'get'.ucfirst($propertyName);
return $this->$method();
}
return parent::getProperty($propertyName);
}