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

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

sentinelphp/dto
===============

PHP DTO generation from JSON Schemas

v1.0.1(1mo ago)00GPL-3.0-or-laterPHPPHP &gt;=8.2

Since Apr 27Pushed 1mo agoCompare

[ Source](https://github.com/SentinelPHP/DTO)[ Packagist](https://packagist.org/packages/sentinelphp/dto)[ Docs](https://github.com/SentinelPHP/dto)[ RSS](/packages/sentinelphp-dto/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Sentinel DTO
============

[](#sentinel-dto)

[![Latest Version](https://camo.githubusercontent.com/30157620afa56b9d397ad337ac8eaf2dfea243b0a3b1c59b14240ee057acc919/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73656e74696e656c7068702f64746f2e737667)](https://packagist.org/packages/sentinelphp/dto)[![License](https://camo.githubusercontent.com/a273708257bef5748d4a149291aebe1a8c7949fd253b69a1bb5069548c9fae5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73656e74696e656c7068702f64746f2e737667)](https://github.com/SentinelPHP/dto/blob/main/LICENSE)

PHP DTO (Data Transfer Object) generation from JSON Schemas.

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

[](#installation)

```
composer require sentinelphp/dto
```

Features
--------

[](#features)

- **Generate** PHP classes from JSON Schema
- **Type-safe** properties with proper PHP types
- **Nested objects** and arrays support
- **Enum generation** from schema enums
- **Serialization** methods (fromArray/toArray)

Usage
-----

[](#usage)

### Basic Generation

[](#basic-generation)

```
use SentinelPHP\Dto\Generator;
use SentinelPHP\Dto\Config\GeneratorConfig;

$generator = new Generator();

$schema = [
    'type' => 'object',
    'properties' => [
        'id' => ['type' => 'integer'],
        'name' => ['type' => 'string'],
        'email' => ['type' => 'string', 'format' => 'email'],
        'created_at' => ['type' => 'string', 'format' => 'date-time'],
    ],
    'required' => ['id', 'name'],
];

$metadata = new SchemaMetadata(
    httpMethod: 'GET',
    endpointPath: '/users/{id}',
    schemaType: 'response'
);

$dto = $generator->generate($schema, $metadata);

// Write to file
file_put_contents($dto->filePath, $dto->code);
```

### Generated Output

[](#generated-output)

```
