php-collective/symfony-dto
最新稳定版本:0.1.0
Composer 安装命令:
composer require php-collective/symfony-dto
包简介
Symfony integration for php-collective/dto
README 文档
README
Symfony bundle integration for php-collective/dto.
Installation
composer require php-collective/symfony-dto
The bundle will be auto-configured if you're using Symfony Flex.
Manual Registration
If not using Flex, add to config/bundles.php:
return [ // ... PhpCollective\SymfonyDto\PhpCollectiveDtoBundle::class => ['all' => true], ];
Configuration
Create config/packages/php_collective_dto.yaml:
php_collective_dto: config_path: config # Path to DTO config files (relative to project root) output_path: src/Dto # Path for generated DTOs namespace: App\Dto # Namespace for generated DTOs
Usage
1. Create your DTO configuration
Create config/dto.xml:
<?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
bin/console dto:generate
Options:
--dry-run- Preview changes without writing files--config-path- Override config path--output-path- Override output path--namespace- Override namespace-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 $this->json($user->toArray());
Or create from an array:
$user = UserDto::createFromArray([ 'id' => 1, 'name' => 'John Doe', 'email' => 'john@example.com', ]);
Supported Config Formats
The bundle supports multiple config file formats:
dto.xml- XML formatdto.yml/dto.yaml- YAML formatdto.php- PHP formatdto/subdirectory with multiple files
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-16