{"id":37013692,"url":"https://github.com/php-collective/symfony-dto","last_synced_at":"2026-03-07T19:05:54.226Z","repository":{"id":328812444,"uuid":"1116853379","full_name":"php-collective/symfony-dto","owner":"php-collective","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-09T09:26:13.000Z","size":75,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-09T09:28:58.450Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-collective.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-15T13:27:03.000Z","updated_at":"2026-02-09T03:28:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/php-collective/symfony-dto","commit_stats":null,"previous_names":["php-collective/symfony-dto"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/php-collective/symfony-dto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Fsymfony-dto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Fsymfony-dto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Fsymfony-dto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Fsymfony-dto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-collective","download_url":"https://codeload.github.com/php-collective/symfony-dto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Fsymfony-dto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30226831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T01:21:44.701Z","updated_at":"2026-03-07T19:05:54.220Z","avatar_url":"https://github.com/php-collective.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony DTO Bundle\n\nSymfony bundle integration for [php-collective/dto](https://github.com/php-collective/dto).\n\n## Installation\n\n```bash\ncomposer require php-collective/symfony-dto\n```\n\nThe bundle will be auto-configured if you're using Symfony Flex.\n\n### Manual Registration\n\nIf not using Flex, add to `config/bundles.php`:\n\n```php\nreturn [\n    // ...\n    PhpCollective\\SymfonyDto\\PhpCollectiveDtoBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Configuration\n\nCreate `config/packages/php_collective_dto.yaml`:\n\n```yaml\nphp_collective_dto:\n    config_path: config/          # Path to DTO config files (relative to project root)\n    output_path: src/Dto/        # Path for generated DTOs\n    namespace: App\\Dto           # Namespace for generated DTOs\n    typescript_output_path: assets/types  # TypeScript output\n    jsonschema_output_path: config/schemas  # JSON Schema output\n    enable_value_resolver: true  # Enable controller DTO auto-resolution\n```\n\n## Usage\n\n### 1. Initialize DTO configuration\n\n```bash\nbin/console dto:init\n```\n\nThis creates a `config/dto.php` file with a sample DTO definition (PHP format is the default).\nYou can also use `--format=xml` or `--format=yaml`.\n\nThe generated config looks like:\n\n```php\nuse PhpCollective\\Dto\\Builder\\Dto;\nuse PhpCollective\\Dto\\Builder\\Field;\nuse PhpCollective\\Dto\\Builder\\Schema;\n\nreturn Schema::create()\n    -\u003edto(Dto::create('User')-\u003efields(\n        Field::int('id'),\n        Field::string('name'),\n        Field::string('email')-\u003enullable(),\n    ))\n    -\u003etoArray();\n```\n\n### 2. Generate DTOs\n\n```bash\nbin/console dto:generate\n```\n\nOptions:\n- `--dry-run` - Preview changes without writing files\n- `--config-path` - Override config path\n- `--output-path` - Override output path\n- `--namespace` - Override namespace\n- `-v` - Verbose output\n\n### 3. Generate TypeScript interfaces\n\n```bash\nbin/console dto:typescript\nbin/console dto:typescript --multiple-files --readonly\n```\n\n### 4. Generate JSON Schema\n\n```bash\nbin/console dto:jsonschema\nbin/console dto:jsonschema --multiple-files\n```\n\n### 5. Use your DTOs\n\n```php\nuse App\\Dto\\UserDto;\n\n$user = new UserDto([\n    'id' =\u003e 1,\n    'name' =\u003e 'John Doe',\n    'email' =\u003e 'john@example.com',\n]);\n\nreturn $this-\u003ejson($user-\u003etoArray());\n```\n\n## DTO Mapping Helpers\n\n```php\nuse App\\Dto\\UserDto;\nuse PhpCollective\\SymfonyDto\\Mapper\\DtoMapper;\n\n$dto = DtoMapper::fromArray(['name' =\u003e 'Mark'], UserDto::class);\n\n$dtos = DtoMapper::fromIterable($rows, UserDto::class);\n$collection = DtoMapper::fromCollection($doctrineCollection, UserDto::class);\n\n// Generic pagination wrapper\n$pagination = DtoMapper::fromPaginated(\n    items: $pageItems,\n    total: $total,\n    perPage: $perPage,\n    page: $page,\n    dtoClass: UserDto::class,\n);\n```\n\n## JSON Response Helper\n\n```php\nuse PhpCollective\\SymfonyDto\\Http\\DtoJsonResponse;\n\nreturn DtoJsonResponse::fromDto($dto);\n// or\nreturn DtoJsonResponse::fromCollection($dtos);\n```\n\n## Controller DTO Resolution\n\nWhen `enable_value_resolver` is enabled, you can use `#[MapRequestDto]` to map request data to DTOs:\n\n```php\nuse PhpCollective\\SymfonyDto\\Attribute\\MapRequestDto;\n\n#[Route('/users', methods: ['POST'])]\npublic function create(#[MapRequestDto] UserDto $dto): Response\n{\n    // $dto is built from request data\n}\n```\n\nThe `source` option controls where data comes from: `body`, `query`, `request`, or `auto`.\n\n## Collections\n\nThe bundle automatically registers Doctrine's `ArrayCollection` for DTO collection fields. Define collection fields with the `[]` suffix:\n\n```php\nField::array('roles', 'Role'),  // Role[] collection\nField::array('tags', 'string'), // string[] collection\n```\n\nAfter generating, collection fields use Doctrine's `ArrayCollection` class with its methods (`filter`, `map`, `first`, etc.).\n\n## Validation Bridge\n\nAutomatically convert DTO validation rules to Symfony Validator constraints:\n\n```php\nuse PhpCollective\\SymfonyDto\\Validation\\DtoConstraintBuilder;\nuse Symfony\\Component\\Validator\\Validation;\n\n$constraint = DtoConstraintBuilder::fromDto(new UserDto());\n$violations = Validation::createValidator()-\u003evalidate($data, $constraint);\n```\n\nSee [Usage docs](docs/README.md#validation-bridge) for details.\n\n## Supported Config Formats\n\nThe bundle supports multiple config file formats:\n\n- `dto.php` - PHP format (default)\n- `dto.xml` - XML format\n- `dto.yml` / `dto.yaml` - YAML format\n- `dto/` subdirectory with multiple files\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-collective%2Fsymfony-dto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-collective%2Fsymfony-dto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-collective%2Fsymfony-dto/lists"}