php-collective/laravel-dto
最新稳定版本:0.1.0
Composer 安装命令:
composer require php-collective/laravel-dto
包简介
Laravel integration for php-collective/dto
README 文档
README
Laravel integration for php-collective/dto.
Installation
composer require php-collective/laravel-dto
The service provider will be auto-discovered.
Configuration
Publish the config file:
php artisan vendor:publish --provider="PhpCollective\LaravelDto\DtoServiceProvider"
This creates config/dto.php with the following options:
return [ 'config_path' => config_path(), // Where DTO config files are located 'output_path' => app_path('Dto'), // Where to generate DTOs 'namespace' => 'App\\Dto', // Namespace for generated DTOs ];
Usage
1. Create your DTO configuration
Create config/dto.xml (or config/dtos.xml to avoid conflicts):
<?xml version="1.0" encoding="UTF-8"?> <dtos xmlns="php-collective-dto"> <dto name="User"> <field name="id" type="int"/> <field name="name" type="string"/> <field name="email" type="string"/> </dto> </dtos>
2. Generate DTOs
php artisan dto:generate
Options:
--dry-run- Preview changes without writing files-v- Verbose output
3. Use your DTOs
use App\Dto\UserDto; $user = new UserDto(); $user->setId(1); $user->setName('John Doe'); $user->setEmail('john@example.com'); return response()->json($user->toArray());
Or create from an array:
$user = UserDto::createFromArray([ 'id' => 1, 'name' => 'John Doe', 'email' => 'john@example.com', ]);
Supported Config Formats
The package supports multiple config file formats:
dto.xmlordtos.xml- XML formatdto.yml/dto.yamlordtos.yml/dtos.yaml- YAML formatdtos.php- PHP format (usedtos.phpto avoid conflict withconfig/dto.php)dto/subdirectory with multiple files
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-16