{"id":28497136,"url":"https://github.com/netmexmedia/hydratorbundle","last_synced_at":"2026-04-16T00:32:44.595Z","repository":{"id":296398386,"uuid":"993247685","full_name":"netmexmedia/HydratorBundle","owner":"netmexmedia","description":"Hydration classes for your Symfony project.","archived":false,"fork":false,"pushed_at":"2025-05-30T19:52:27.000Z","size":2200,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-08T13:05:15.600Z","etag":null,"topics":["bundle","hydration","hydrator","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netmexmedia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-05-30T13:15:42.000Z","updated_at":"2025-05-30T19:52:30.000Z","dependencies_parsed_at":"2025-05-30T18:18:16.050Z","dependency_job_id":"67876125-f137-47cb-92f2-7f7d6885ac39","html_url":"https://github.com/netmexmedia/HydratorBundle","commit_stats":null,"previous_names":["netmexmedia/hydratorbundle"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/netmexmedia/HydratorBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netmexmedia%2FHydratorBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netmexmedia%2FHydratorBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netmexmedia%2FHydratorBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netmexmedia%2FHydratorBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netmexmedia","download_url":"https://codeload.github.com/netmexmedia/HydratorBundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netmexmedia%2FHydratorBundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271985645,"owners_count":24854104,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bundle","hydration","hydrator","php","symfony","symfony-bundle"],"created_at":"2025-06-08T13:05:15.605Z","updated_at":"2026-04-16T00:32:44.550Z","avatar_url":"https://github.com/netmexmedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Netmex HydratorBundle\n\n## About\nThe Netmex HydratorBundle is a Symfony bundle designed to simplify the process of hydrating data transfer objects (DTOs) from arrays or JSON inputs with built-in support for data transformation and validation using Symfony constraints.\n\nIt enables you to:\n* Define mappers that transform and validate input data.\n* Easily create reusable transformers to convert raw data (e.g., capitalization, formatting).\n* Handle validation errors gracefully.\n* Integrate seamlessly into Symfony controllers for clean and maintainable code.\n\n## Installation\n\n```bash\ncomposer require netmex/hydrator-bundle\n```\n\n## Usage\n\nCreate a mapper class that implements\n```Netmex\\HydratorBundle\\Contracts\\MapperDefinitionInterface```.\n\n##### Example Hydrator\n```php\n\u003c?php\n\nnamespace App\\Hydrator;\n\nuse App\\Entity\\MyClass;\nuse Netmex\\HydratorBundle\\Contracts\\BuilderInterface;\nuse Netmex\\HydratorBundle\\Contracts\\MapperDefinitionInterface;\nuse Netmex\\HydratorBundle\\Options\\OptionsResolver;\nuse Symfony\\Component\\Validator\\Constraints\\NotBlank;\nuse Symfony\\Component\\Validator\\Constraints\\Length;\nuse App\\Transformer\\CapitalizationTransformer;\n\nclass Hydrator implements MapperDefinitionInterface\n{\n    public function process(BuilderInterface $builder): void\n    {\n        $builder\n            -\u003eadd('key', CapitalizationTransformer::class, [\n                NotBlank::class =\u003e null,\n                Length::class =\u003e ['min' =\u003e 6, 'max' =\u003e 7],\n            ]);\n    }\n\n    public function options(OptionsResolver $resolver): void\n    {\n        $resolver-\u003esetDefaults([\n            'model' =\u003e MyClass::class,\n        ]);\n    }\n}\n```\n\n### Create a Transformer\n\n```php\n\u003c?php\n\nnamespace App\\Transformer;\n\nuse Netmex\\HydratorBundle\\Contracts\\TransformerInterface;\n\nclass CapitalizationTransformer implements TransformerInterface\n{\n    public function transform(string $data): string\n    {\n        return strtoupper($data);\n    }\n}\n```\n\n### Injecting the Mapper into a Controller\n\n```php\n\u003c?php\n\nnamespace App\\Controller;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\HttpFoundation\\JsonResponse;\nuse Symfony\\Component\\Routing\\Annotation\\Route;\nuse App\\Hydrator\\Hydrator;\nuse Netmex\\HydratorBundle\\Contracts\\MapperInterface;\nuse Netmex\\HydratorBundle\\Exception\\ValidationFailedException;\n\nclass ExampleController\n{\n    #[Route('/example', name: 'app_example')]\n    public function index(Request $request, MapperInterface $hydrator): Response\n    {\n        $jsonContent = $request-\u003egetContent();\n        $data = json_decode($jsonContent, true);\n\n        if (json_last_error() !== JSON_ERROR_NONE) {\n            return new JsonResponse(['error' =\u003e 'Invalid JSON'], 400);\n        }\n\n        try {\n            $result = $hydrator-\u003ebuild(Hydrator::class, $data);\n        } catch (ValidationFailedException $e) {\n            return new JsonResponse(['errors' =\u003e (string) $e-\u003egetViolations()], 400);\n        }\n\n        return new JsonResponse($result);\n    }\n}\n```\n\n## Recommended Directory Layout\n```text\nsrc/\n├── Hydrator/\n│   └── Hydrator.php\n├── Transformer/\n│   └── CapitalizationTransformer.php\n└── Controller/\n    └── ExampleController.php\n```\n\n## Exception Handling\n```php\ntry {\n    $data = $hydrator-\u003ebuild(Hydrator::class, $requestData);\n} catch (ValidationFailedException $e) {\n    return new JsonResponse(['errors' =\u003e (string) $e-\u003egetViolations()], 400);\n}\n```\n\n## More about Constraints\nSee [Symfony Validation Constraints](https://symfony.com/doc/current/validation.html#constraints) for available options.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetmexmedia%2Fhydratorbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetmexmedia%2Fhydratorbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetmexmedia%2Fhydratorbundle/lists"}