heseya/dto
Larablocks Analysis
heseya/dto works with Laravel 8 to 11 (latest release 1.0.2, Mar 18, 2024), all past end of life (the last on Mar 12, 2026): no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 8 to 11, past end of life since Mar 12, 2026
- No release in the last 12 months (last: Mar 18, 2024)
- 39 downloads a month (needs 10,000)
- 0 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Mar 18, 2024.
- No releases in the last 12 months.
- First released: Jan 17, 2022.
- Monthly downloads: 39.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 30, 2026.
| Install | |
|---|---|
composer require heseya/dto |
|
| Latest Version: | 1.0.2 |
| PHP: | ^8.0 |
| Laravel: | 8 – 11 |
| Last Updated: | Mar 18, 2024 |
| Links: | GitHub · Packagist |
Heseya Dto
Simple Dto system with optional parameters.
Install
composer require heseya/dto
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
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
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
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.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 1.0.2 | ^8.0 | ^8.0| | ||
| 1.0.1 | ^8.0 | ^8.0| | ||
| 1.0.0 | ^8.0 | ^8.0| |