PHPackages                             damianulan/php-dtos - 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. damianulan/php-dtos

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

damianulan/php-dtos
===================

Provides a template for creating robust and efficient data-transfer-objects (DTOs) in your PHP projects.

1.0.0(5mo ago)121MITPHPPHP ^8.0

Since Jan 26Pushed 2mo agoCompare

[ Source](https://github.com/damianulan/php-dtos)[ Packagist](https://packagist.org/packages/damianulan/php-dtos)[ RSS](/packages/damianulan-php-dtos/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (1)

PHP DTOs
========

[](#php-dtos)

[![Licence](https://camo.githubusercontent.com/0c2e91939275c9fd009f7680dc38d0763918d859f61af587b5271311f234efcf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f496c65726961796f2f6d61726b646f776e2d6261646765733f7374796c653d666f722d7468652d6261646765)](./LICENSE) [![Static Badge](https://camo.githubusercontent.com/1c44eb0e6c2006f3c5e16a51c67b79b9aae86a926bf1103e458160e8249d50c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d64616d69616e756c616e2d626c75653f7374796c653d666f722d7468652d6261646765)](https://damianulan.me)

Description
-----------

[](#description)

Provides a template for creating robust and efficient data-transfer-objects (DTOs) in your PHP projects. Initialization steps look very similar to the ones in Laravel's Eloquent models, regarding objects are based on attributes, which are accessible as propertiesm and DTO objects are bootable.

Installation
------------

[](#installation)

You can install the package via composer in your laravel project:

```
composer require damianulan/php-dtos

```

Usage
-----

[](#usage)

Standard DTO object looks like this:

```
use DTOs\Dto;

class UserDto extends Dto
{
    // here you can define default values to your attributes
    protected $attributes = [
        'name' => 'Damian',
        'email' => 'damian.ulan@protonmail.com',

    ];

    // here you can define attributes that are assignable outside of constructor
    // then assigning anything outside of this list will throw an exception
    protected $fillable = ['name', 'email'];

    /**
     * Here contain all the logic you need.
    **/
}
```

Creating and basics on DTO instance:

```
$dto = new UserDto();

// or with attributes assigned.
// these will be assigned to the object before its initialization
$dto = new UserDto([
    'name' => 'Damian',
    'email' => 'damian.ulan@protonmail.com',
]);

// you can retrieve attributes changes as:
$dto->name = 'Alexander';
$dto->getDirty('name'); // returns 'Alexander'
$dto->getOriginal('name'); // returns 'Damian'

// those will return all attributes as an assoc array
$dto->all();
$dto->toArray();

// check if attributes are empty/filled
$dto->isEmpty();
$dto->isFilled();

// or check if a specific attribute is assigned
$dto->hasAttribute('name');
$dto->hasAttribute('email');
```

### Additional Options

[](#additional-options)

In your DTO class you can implement additional options, that will add custom behavior to your object.

```
use DTOs\Workshop\ReadOnlyAttributes;

/**
 * This interface will prevent overriding attributes over those previously assigned.
 */
class UserDto extends Dto implements ReadOnlyAttributes
{
    //
}
```

Available options:

- `ReadOnlyAttributes` - prevents reassignment of attributes after object construction.
- `ForbidOverrides` - prevents overriding attributes over those already assigned.
- `PreventAccessingMissingAttributes` - throws exception on accessing uninitialized attributes.

Contact &amp; Contributing
--------------------------

[](#contact--contributing)

Any question You can submit to ****.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance80

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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

Every ~0 days

Total

2

Last Release

157d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31820473?v=4)[Damian Ułan](/maintainers/damianulan)[@damianulan](https://github.com/damianulan)

---

Top Contributors

[![damianulan](https://avatars.githubusercontent.com/u/31820473?v=4)](https://github.com/damianulan "damianulan (11 commits)")

---

Tags

data-transfer-objectextensiondto

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/damianulan-php-dtos/health.svg)

```
[![Health](https://phpackages.com/badges/damianulan-php-dtos/health.svg)](https://phpackages.com/packages/damianulan-php-dtos)
```

###  Alternatives

[cerbero/laravel-dto

Data Transfer Object (DTO) for Laravel

5913.7k](/packages/cerbero-laravel-dto)[cerbero/dto

Data Transfer Object (DTO)

19121.6k1](/packages/cerbero-dto)

PHPackages © 2026

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