{"id":19136912,"url":"https://github.com/xactsystems/type-hint-hydrator","last_synced_at":"2026-05-06T16:18:22.503Z","repository":{"id":41294071,"uuid":"423403262","full_name":"XactSystems/type-hint-hydrator","owner":"XactSystems","description":"A Symfony Type Hint hydrator that uses @var annotations to determine the hydrated type","archived":false,"fork":false,"pushed_at":"2025-05-06T10:28:47.000Z","size":186,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T11:18:52.934Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/XactSystems.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}},"created_at":"2021-11-01T09:15:18.000Z","updated_at":"2024-08-28T12:56:06.000Z","dependencies_parsed_at":"2024-11-09T06:36:03.429Z","dependency_job_id":"fccd1eda-4e46-48ed-b06c-b5caaad129f4","html_url":"https://github.com/XactSystems/type-hint-hydrator","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":"0.10526315789473684","last_synced_commit":"76e4fd87c165d42f0b3309a44e3c60da1f9ecaa5"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Ftype-hint-hydrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Ftype-hint-hydrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Ftype-hint-hydrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XactSystems%2Ftype-hint-hydrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XactSystems","download_url":"https://codeload.github.com/XactSystems/type-hint-hydrator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761234,"owners_count":21800127,"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","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":"2024-11-09T06:35:50.123Z","updated_at":"2026-03-11T05:31:34.823Z","avatar_url":"https://github.com/XactSystems.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-hint-hydrator\nA Symfony Type Hint hydrator that uses declared types and @var annotations to determine the hydrated type.\nUnder the hood it uses the laminas-hydrator for the mapping process. See https://github.com/laminas/laminas-hydrator/\n\nIt can handle request objects and arrays of data to hydrate annotated classes and arrays etc. It can also validate against any Assert annotations the hydrated object may contain.\n\nIf properties of the hydrated object are annotated as Doctrine Entities, the hydrator will attempt to load the entity for the key value provided. We currently don't support composite keys.\n\n## Documentation\n-------------\n### 1) Add the type-hint-hydrator to your project\n\n```bash\ncomposer require xactsystems/type-hint-hydrator\n```\n\n### 2) Add the bundle to your configuration file\nIf you are using Symfony 4 onwards and using Flex you can skip this step.\n\nSymfony 4.4 onwards - bundles.php\n```php\n    return [\n        ...\n        Xact\\TypeHintHydrator\\XactTypeHintHydrator::class =\u003e ['all' =\u003e true],\n    ];\n```\n\n### 3) Declare types or annotate your hydrated object properties\n```php\nnamespace App;\n\nclass Author\n{\n    /**\n     * @var int|null\n     */\n    public $objectId;\n\n    public int $noneNullId;\n\n    /**\n     * @var string|null\n     */\n    public $fullName;\n\n    public float $myFloat;\n\n    /**\n     * @var \\App\\Book[]\n     */\n    public $books;\n\n    /**\n     * @var \\App\\Authors[]\n     */\n    public array $authors;\n\n    /**\n     * @var array\u003c\\App\\References\u003e\n     */\n    public array $references;\n}\n```\n\n### 4) Hydrate your object in your controller\n```php\n    use Xact\\TypeHintHydrator\\TypeHintHydrator;\n    ...\n    public function update(Request $request, EntityManagerInterface $em, TypeHintHydrator $hydrator): JsonResponse\n    {\n        $author = new Author();\n        $hydrator-\u003ehandleRequest($request, $author);\n        if (!$hydrator-\u003eisValid()) {\n            return JsonResponse::fromJsonString($hydrator-\u003egetJsonErrors(), JsonResponse::HTTP_BAD_REQUEST);\n        }\n\n        $em-\u003epersist($author);\n        $em-\u003eflush();\n\n        return new JsonResponse::fromJsonString(json_encode($author));\n    }\n```\n\nOr to update and existing entity:\n```php\n    use Xact\\TypeHintHydrator\\TypeHintHydrator;\n    ...\n    /**\n     * @Route(\"/author/{id}\", methods={\"POST\"})\n     * @ParamConverter(\"author\", class=\"App\\Entity\\Author\")\n     */\n    public function update(Author $author, Request $request, TypeHintHydrator $hydrator): Response\n    {\n        $hydrator-\u003ehandleRequest($request, $author);\n        if (!$hydrator-\u003eisValid()) {\n            return JsonResponse::fromJsonString($hydrator-\u003egetJsonErrors(), JsonResponse::HTTP_BAD_REQUEST);\n        }\n\n        $em-\u003epersist($author);\n        $em-\u003eflush();\n\n        return new JsonResponse::fromJsonString(json_encode($author));\n    }\n```\n\n### 5) Smile and be happy\nIt really is that easy. No more form types! Annotate your objects correctly with types and assertions, make sure your submitted forms use the same names as your object proprieties and it will just work!\n\nCreate proper Model classes for your data and hydrate them, and let them do the work a proper MVC model should.\n\n## Methods\n\n### hydrateObject\n```php\nhydrateObject(array $values, object $target, bool $validate = true, $constraints = null, $groups = null): object\n```\nHydrate an object from an array of values. If $validate is true, the hydrated object is validated against annotations and supplied validation constraints and groups.\n\n\n### handleRequest\n```php\nhandleRequest(Request $request, object $target, bool $validate = true, $constraints = null, $groups = null): object\n```\nHydrate an object from the Request object. Property mapping is based on the submitted form property names matching the property names of the hydrated object. If $validate is true, the hydrated object is validated against annotations and supplied validation constraints and groups.\n\n\n### isValid\n```php\nisValid()\n```\nIs the hydrated object valid after processing the validation constraints. If no validation has occurred the method returns true;\n\n\n### getErrors\n```php\ngetErrors()\n```\nReturn a Symfony\\Component\\Validator\\ConstraintViolationListInterface list of any validation errors.\n\n\n### getJsonErrors\n```php\ngetJsonErrors()\n```\nReturn a JSON serialised version of getErrors().\n\n\n## Credits\n-------\n\n* Ian Foulds as the creator of this package.\n* Marco Pivetta (https://github.com/ocramius) for developing and maintaining the laminas-hydrator - https://github.com/laminas/laminas-hydrator.\n\n## License\n-------\n\nThis bundle is released under the MIT license. See the complete license in the\nbundle:\n\n[LICENSE](https://github.com/xactsystems/type-hint-hydrator/blob/master/LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxactsystems%2Ftype-hint-hydrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxactsystems%2Ftype-hint-hydrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxactsystems%2Ftype-hint-hydrator/lists"}