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

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

jooservices/dto
===============

A PHP 8.5+ DTO and Data library with immutable DTOs and mutable Data objects

1.0.1(2mo ago)034↓50%[2 PRs](https://github.com/jooservices/dto/pulls)3MITPHPPHP &gt;=8.5CI passing

Since Jan 22Pushed 3mo agoCompare

[ Source](https://github.com/jooservices/dto)[ Packagist](https://packagist.org/packages/jooservices/dto)[ RSS](/packages/jooservices-dto/feed)WikiDiscussions master Synced 1mo ago

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

JOOservices DTO Library
=======================

[](#jooservices-dto-library)

[![PHP Version](https://camo.githubusercontent.com/2788132aa1e54031a6c94edcbf8688566d3e18cb5492cd1766836f74a24b27b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e352532422d626c75652e737667)](https://www.php.net/)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/f83530e81d82db85857033ac2b33bb020f3817c059a08e7010ea8264d4e8e885/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d312e302e302d6f72616e67652e737667)](https://packagist.org/packages/jooservices/dto)

A modern PHP 8.5+ library for building type-safe, immutable Data Transfer Objects (DTOs) with powerful hydration, validation, and transformation capabilities.

---

✨ Key Features
--------------

[](#-key-features)

FeatureDescription🔒 **Immutable DTOs**Type-safe, readonly data transfer objects✏️ **Mutable Data Objects**Flexible mutable data containers via `Data` class💧 **Multi-Source Hydration**Create from arrays, JSON, objects with `from()`, `fromArray()`, `fromJson()`🔄 **Type Casting**Automatic type conversion (scalars, DateTime, Enums, nested DTOs, arrays)✅ **Validation**Built-in validation attributes (`@Required`, `@Email`, `@Valid`)🎨 **Custom Casters**Extensible type casting system via `CasterInterface`🔧 **Custom Transformers**Output transformation pipeline with `TransformerInterface`📝 **Naming Strategies**Automatic `camelCase` ↔ `snake_case` conversion📚 **Collections**`DataCollection` and `PaginatedCollection` support📋 **Schema Generators**Export to JSON Schema and OpenAPI 3.0 specifications⚡ **Pipeline System**Global and per-property data transformation pipelines🛠️ **Utility Methods**`diff()`, `equals()`, `hash()`, `merge()`, `clone()`, `when()`, `unless()`🔀 **Optional**Type-safe optional value wrapper for handling missing data🎯 **Lifecycle Hooks**`transformInput()`, `afterHydration()`, `beforeSerialization()`⚡ **Computed Properties**WeakMap-based cached lazy-evaluated properties🏗️ **Polymorphism**`@DiscriminatorMap` for polymorphic type mapping---

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
composer require jooservices/dto
```

**Requirements:** PHP 8.5 or higher

### Basic Usage

[](#basic-usage)

```
use JOOservices\Dto\Core\Dto;
use JOOservices\Dto\Attributes\MapFrom;
use JOOservices\Dto\Attributes\Validation\Required;

class UserDto extends Dto
{
    public function __construct(
        #[Required]
        public readonly string $name,

        #[MapFrom('email_address')]
        public readonly string $email,

        public readonly int $age,
    ) {}
}

// Create from array
$user = UserDto::from([
    'name' => 'John Doe',
    'email_address' => 'john@example.com',
    'age' => 30
]);

// Access properties
echo $user->name;  // John Doe
echo $user->email; // john@example.com

// Convert to array
$array = $user->toArray();

// Convert to JSON
$json = $user->toJson();
```

### Advanced Example: Nested DTOs and Collections

[](#advanced-example-nested-dtos-and-collections)

```
class AddressDto extends Dto
{
    public function __construct(
        public readonly string $street,
        public readonly string $city,
        public readonly string $country,
    ) {}
}

class UserProfileDto extends Dto
{
    public function __construct(
        public readonly string $name,
        public readonly AddressDto $address,
        /** @var array */
        public readonly array $tags,
    ) {}
}

$profile = UserProfileDto::from([
    'name' => 'Jane Smith',
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York',
        'country' => 'USA'
    ],
    'tags' => [
        ['name' => 'developer'],
        ['name' => 'php']
    ]
]);
```

---

📖 Documentation
---------------

[](#-documentation)

Comprehensive documentation is available in the [`./docs`](./docs) directory:

- **[Getting Started](./docs/01-getting-started/)** - Installation, quick start, basic concepts
- **[User Guide](./docs/02-user-guide/)** - Creating DTOs, validation, best practices, troubleshooting
- **[Examples](./docs/03-examples/)** - Real-world usage examples and API integration patterns

👉 **Start here:** [Documentation Hub](./docs/README.md)

---

🎯 Use Cases
-----------

[](#-use-cases)

- **REST API Development** - Type-safe request/response handling
- **Form Processing** - Validate and transform user input
- **Database Mapping** - Map database records to typed objects
- **Microservices** - Consistent data contracts between services
- **Data Validation** - Ensure data integrity with built-in validation
- **API Clients** - Type-safe API response objects

---

🔗 Links
-------

[](#-links)

ResourceURL📦 **Packagist**[packagist.org/packages/jooservices/dto](https://packagist.org/packages/jooservices/dto)💻 **GitHub**[github.com/jooservices/dto](https://github.com/jooservices/dto)🐛 **Issue Tracker**[github.com/jooservices/dto/issues](https://github.com/jooservices/dto/issues)📧 **Contact**---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please see our contributing guidelines in the documentation for details on:

- Code style and standards
- Running tests
- Submitting pull requests
- Reporting issues

---

📜 License
---------

[](#-license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

---

🙏 Credits
---------

[](#-credits)

Developed and maintained by **[JOOservices](https://jooservices.com)**

Special thanks to all [contributors](https://github.com/jooservices/dto/graphs/contributors) who have helped improve this library.

---

**Ready to build type-safe DTOs?** → [Get Started](./docs/01-getting-started/installation.md)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance84

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

71d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/142772948?v=4)[JOOservices Ltd](/maintainers/jooservices)[@jooservices](https://github.com/jooservices)

---

Top Contributors

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

---

Tags

datamappingdata-transfer-objectdtocastinghydrationnormalization

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[cerbero/dto

Data Transfer Object (DTO)

17119.4k1](/packages/cerbero-dto)[event4u/data-helpers

Framework-agnostic PHP library for data mapping, DTOs and utilities. Includes DataMapper, SimpleDto/LiteDto, DataAccessor/Mutator/Filter and helper classes (MathHelper, EnvHelper, etc.). Works with Laravel, Symfony/Doctrine or standalone PHP.

1421.5k](/packages/event4u-data-helpers)

PHPackages © 2026

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