PHPackages                             heseya/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. heseya/dto

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

heseya/dto
==========

Heseya Dto with optional properties

1.0.2(2y ago)04.3kPHPPHP ^8.0

Since Jan 17Pushed 2y ago3 watchersCompare

[ Source](https://github.com/heseya/dto)[ Packagist](https://packagist.org/packages/heseya/dto)[ RSS](/packages/heseya-dto/feed)WikiDiscussions main Synced 3w ago

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

Heseya Dto
==========

[](#heseya-dto)

Simple Dto system with optional parameters.

Install
-------

[](#install)

```
composer require heseya/dto

```

Get started
-----------

[](#get-started)

To create a new Dto you need to extend base `Heseya\Dto\Dto` class as such:

```
use Heseya\Dto\Dto;

class ExampleDto extends Dto {
    private string $property1;
    private string $property2;
}
```

`Heseya\Dto\Dto` base class provides constructor automatically handling all property initialization.

To create a new Dto use `PHP 8` named arguments:

```
$dto = new ExampleDto(property1: 'value1', property2: 'value2');
```

Or use an associative array:

```
$array = ['property1' => 'value1', 'property2' => 'value2'];

$dto = new ExampleDto($array);
```

The built-in `toArray()` method automatically returns Dto properties in the associative array format:

```
$dto->toArray(); // ['property1' => 'value1', 'property2' => 'value2']
```

Optional properties
-------------------

[](#optional-properties)

To make your Dto properties optional you need to use `Heseya\Dto\Missing` type as such:

```
use Heseya\Dto\Dto;
use Heseya\Dto\Missing;

class OptionalDto extends Dto {
    private string $required;
    private string|Missing $optional;
}
```

Optional properties when not initialized will automatically be hidden in `toArray()` method result:

```
$dto = new OptionalDto(required: 'required value')

$dto->toArray(); // ['required' => 'required value']
```

Hidden properties
-----------------

[](#hidden-properties)

Sometimes you want to hide your internal properties from appearing in the `toArray()` method result

You can hide those properties using `Heseya\Dto\Hidden` attribute:

```
use Heseya\Dto\Dto;
use Heseya\Dto\Hidden;

class HiddenDto extends Dto {
    private string $visible;
    #[Hidden]
    private string $hidden;
}

$dto = new HiddenDto(visible: 'visible value', hidden: 'hidden value');

$dto->toArray(); // [visible => 'visible value']
```

Exceptions
----------

[](#exceptions)

Non-optional properties need to be set explicitly in the constructor, otherwise a `Heseya\Dto\DtoException` will be raised:

```
use Heseya\Dto\Dto;

class NonOptionalDto extends Dto {
    private ?string $param;
}

$dto = new NonOptionalDto(); // DtoException("Property NonOptionalDto::$param is required")
```

Nullable properties such as `private ?string $param` will not be automatically initialized as null and need to be set explicitly as well.

Optional properties using `Heseya\Dto\Missing` type will be automatically initialized as `new Missing()` class instance when not set explicitly.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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 ~395 days

Total

3

Last Release

837d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb8aabd4e1f604898f54ec83f51ad502af0800c83d243bc91211b8155eb87875?d=identicon)[bvlinsky](/maintainers/bvlinsky)

### Embed Badge

![Health badge](/badges/heseya-dto/health.svg)

```
[![Health](https://phpackages.com/badges/heseya-dto/health.svg)](https://phpackages.com/packages/heseya-dto)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.6k2](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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