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

$this
setAttribute(string $attributeName, mixed $attributeValue)

Set attribute

mixed
getAttribute(string $attributeName)

Get attribute

$this
setAttributes(array $attributes)

Set attributes

array
getAttributes()

Get attributes

bool
offsetExists(mixed $offset)

Offset exist

mixed
offsetGet(mixed $offset)

Offset get

void
offsetSet(mixed $offset, mixed $value)

Offset set

void
offsetUnset(mixed $offset)

Offset unset

mixed
current()

Current

void
next()

Next

string
key()

Key

bool
valid()

Valid

void
rewind()

Rewind

boolean
propertyExist(string $propertyName)

Property exist

array
getProperties()

Get properties

$this
setProperty(string $propertyName, mixed $propertyValue)

Set property

mixed
getProperty(string $propertyName)

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

Parameters

string $attributeName The attribute to set
mixed $attributeValue The value to set

Return Value

$this

at line 84
mixed getAttribute(string $attributeName)

Get attribute

This method allow to retreive a value from a named attribute of the DTO

Parameters

string $attributeName The name of the attribute whence return the value

Return Value

mixed

at line 106
$this setAttributes(array $attributes)

Set attributes

This method allow to set the attributes of the DTO from an associative array

Parameters

array $attributes The associative array of attributes

Return Value

$this

at line 122
array getAttributes()

Get attributes

This method return the attributes as array from the DTO

Return Value

array

at line 142
bool offsetExists(mixed $offset)

Offset exist

This method validate the existence of an offset

Parameters

mixed $offset The offset to validate

Return Value

bool

at line 160
mixed offsetGet(mixed $offset)

Offset get

This method return an offset value

Parameters

mixed $offset The offset whence retreive the value

Return Value

mixed

at line 175
void offsetSet(mixed $offset, mixed $value)

Offset set

This method allow to set a value at an offset place

Parameters

mixed $offset The offset where set the value
mixed $value The value to inject

Return Value

void

at line 189
void offsetUnset(mixed $offset)

Offset unset

This method remove an offset

Parameters

mixed $offset The offset to remove

Return Value

void

at line 205
mixed current()

Current

This method return the current iterated value

Return Value

mixed

at line 217
void next()

Next

This method advance the internal pointer by one step

Return Value

void

at line 229
string key()

Key

This method return the current iterated key

Return Value

string

at line 241
bool valid()

Valid

This method validate the current internal position existence

Return Value

bool

at line 255
void rewind()

Rewind

This method reinitialize the internal position

Return Value

void

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.

Parameters

string $propertyName The name of the property to check

Return Value

boolean

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
     );
}

Return Value

array

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);
}

Parameters

string $propertyName The property name where inject the value
mixed $propertyValue The value to inject inside the property

Return Value

$this

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);
}

Parameters

string $propertyName The property whence extract the value

Return Value

mixed