PHPackages                             cscfa\_tool\_division/csr3-dto - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cscfa\_tool\_division/csr3-dto

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cscfa\_tool\_division/csr3-dto
==============================

The CSCFA csr Division PHP implementation

1.0.0(9y ago)125MITPHP

Since Mar 19Pushed 9y ago2 watchersCompare

[ Source](https://github.com/cscfaToolDivision/CSR3)[ Packagist](https://packagist.org/packages/cscfa_tool_division/csr3-dto)[ RSS](/packages/cscfa-tool-division-csr3-dto/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

CSR3 Data Transfer Object
=========================

[](#csr3-data-transfer-object)

This project is the PHP implementation of the **[csr3 specification](https://github.com/cscfaCsrDivision/CSR-3_DataTransferObject)**.

The data transfer objects are elements used to encapsulate the data when they must go through multiple elements of an application. The DTO acts as a container.

[![SensioLabsInsight](https://camo.githubusercontent.com/375c617e841aab1730c9617671f112dcea70336c690fd704e4e2fbfcea712618/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39303461333633652d663562642d346664342d613563332d3138656632653532336431332f6269672e706e67)](https://insight.sensiolabs.com/projects/904a363e-f5bd-4fd4-a5c3-18ef2e523d13)

Basic usage
-----------

[](#basic-usage)

The CSR3 project define a generic DTO object :

```
use CSDT\CSR3\CSR3GenericDTO;

$dto = new CSR3GenericDTO();
```

The CSR3GenericDTO is an instance that implement CSR3DTOInterface. This interface extend ArrayAccess and Iterator interfaces.

###### The ArrayAccess iplementation

[](#the-arrayaccess-iplementation)

By using the ArrayAccess interface, the CSR3GenericDTO allow to be used as an array.

```
// ...

if (isset($user) && !empty($user)) {
    $dto['user_instance'] = $user;
}

// ...

if (isset($dto['user_instance']) {
    $user = $dto['user_instance'];

    if ($user->isLocked()) {
        unset($dto['user_instance']);
    }
}
```

###### The Iterator iplementation

[](#the-iterator-iplementation)

By using the Iterator interface, the CSR3GenericDTO allow to be used as an iterator.

```
$dto['hell'] = 'o w';
$dto['or'] = 'ld';

foreach ($dto as $key => $value) {
    echo $key . $value;
}

// Output : "hello world"
```

###### The CSR3DTOInterface iplementation

[](#the-csr3dtointerface-iplementation)

The CSR3DTOInterface is the default access feature of the CSR3 DTOs. It allow to set and get attributes.

```
$dto->setAttributes(['a' => 1, 'b' => 2]);

var_dump($dto->getAttributes());
/* array(2) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(2)
} */

$dto->setAttribute('a', 3);

var_dump($dto->getAttribute('b')); // int(2)
var_dump($dto->getAttributes());
/* array(2) {
  ["a"]=>
  int(3)
  ["b"]=>
  int(2)
} */
```

Adding custom methods
---------------------

[](#adding-custom-methods)

The CSR3GenericDTO is a final class and cannot be extended as it. But it extend an abstract class : the **AbstractCSR3DTO** that define all the logic needed to implement the **CSR3DTOInterface**.

Imagine you want to create a DTO that store a specific context and you want to be able to retreive this by a method call. You can create a DTO class as the following :

```
use CSDT\CSR3\Abstracts\AbstractCSR3DTO;

class ContextDTO extends AbstractCSR3DTO
{
    public function setContext($context)
    {
        $this['context'] = $context;
    }

    public function getContext($context)
    {
        return $this['context'] ?? [];
    }
}
```

Using custom class properties
-----------------------------

[](#using-custom-class-properties)

As seen in the custom method addition, you'll must create your own class :

```
use CSDT\CSR3\Abstracts\AbstractCSR3DTO;

class ContextDTO extends AbstractCSR3DTO
{
    protected $context = [];

    public function setContext($context)
    {
        $this->context = $context;
    }

    public function getContext($context)
    {
        return $this->context;
    }
}
```

The problem yu will discover by using this custom class is that the ArrayAccess and iterator property are not able to handle the `$context` property. To avoid this issue, you'll need to extend the `AbstractCSR3PropertyDTO` instead of the `AbstractCSR3DTO`.

```
use CSDT\CSR3\Abstracts\AbstractCSR3DTO;

class ContextDTO extends AbstractCSR3PropertyDTO
{
    protected $context = [];

    public function setContext($context)
    {
        $this->['context'] = $context;
    }

    public function getContext($context)
    {
        return $this['context'];
    }
}
```

💢 Note the AbstractCSR3PropertyDTO is not able to process private properties as it. This is in fact the POO structure of the PHP.

#### Using private properties

[](#using-private-properties)

To be able to manage the private properties of your DTO's, you'll must override three methods of the `AbstractCSR3PropertyDTO` :

```
use CSDT\CSR3\Abstracts\AbstractCSR3DTO;

class ContextDTO extends AbstractCSR3PropertyDTO
{
    private $context = [];

    protected function getProperties() : array
    {
        return array_merge(
            parent::getProperties(),
            ['context']
        );
    }

    protected function setProperty(string $propertyName, $propertyValue)
    {
        if ($propertyName == 'context') {
            $this->setContext($propertyValue);
            return $this;
        }

        return parent::setProperty($propertyName, $propertyValue);
    }

    protected function getProperty(string $propertyName)
    {
        if (propertyName == 'context') {
            return $this->getContext();
        }

        return parent::getProperty($propertyName);
    }

    public function setContext($context)
    {
        $this->context = $context;
    }

    public function getContext($context)
    {
        return $this->context;
    }
}
```

❕ These three methods work in cooperation and cannot be override without the other to enable the fully private property support.

Internal key-words and how to override them
-------------------------------------------

[](#internal-key-words-and-how-to-override-them)

The `AbstractCSR3DTO` and `AbstractCSR3PropertyDTO` defines an **attributes** and **traversingPosition** properties. The first one store the attributes of the DTO, the second store the internal iteration pointer. It is possible to override them by setting a **attributeContainer** and a **positionContainer** properties that store the attributes names to use instead of the two initial properties.

💢 The **attributeContainer** and **positionContainer** properties are key-words and cannot be overrides.

Using logic without CSR3 interfaces
-----------------------------------

[](#using-logic-without-csr3-interfaces)

The complete logic of this implementation is encapsulated inside a `CSR3DTOTrait` and a `CSR3PropertyDTOTrait`.

```
use CSDT\CSR3\Traits\CSR3DTOTrait;

class AttributeDTO
{
    use CSR3DTOTrait;

    private $attributes = [];

    private $traversingPosition = 0;
}
```

```
use CSDT\CSR3\Traits\CSR3DTOPropertyTrait;

class ContextDTO
{
    use CSR3DTOPropertyTrait;

    private $attributes = [];

    private $traversingPosition = 0;

    private $context = [];

    protected function getProperties() : array
    {
        return array_merge(
            parent::getProperties(),
            ['context']
        );
    }

    protected function setProperty(string $propertyName, $propertyValue)
    {
        if ($propertyName == 'context') {
            $this->setContext($propertyValue);
            return $this;
        }

        return parent::setProperty($propertyName, $propertyValue);
    }

    protected function getProperty(string $propertyName)
    {
        if (propertyName == 'context') {
            return $this->getContext();
        }

        return parent::getProperty($propertyName);
    }

    public function setContext($context)
    {
        $this->context = $context;
    }

    public function getContext($context)
    {
        return $this->context;
    }
}
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3389d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12436206?v=4)[cscfa](/maintainers/cscfa)[@cscfa](https://github.com/cscfa)

---

Top Contributors

[![matthieu88160](https://avatars.githubusercontent.com/u/11874266?v=4)](https://github.com/matthieu88160 "matthieu88160 (3 commits)")

---

Tags

csrdata-transfer-objectdtocscfa

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cscfa-tool-division-csr3-dto/health.svg)

```
[![Health](https://phpackages.com/badges/cscfa-tool-division-csr3-dto/health.svg)](https://phpackages.com/packages/cscfa-tool-division-csr3-dto)
```

###  Alternatives

[cerbero/dto

Data Transfer Object (DTO)

17121.0k1](/packages/cerbero-dto)[php-collective/dto

Framework-agnostic Data Transfer Object library with code generation

2812.2k6](/packages/php-collective-dto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
