{"id":41215021,"url":"https://github.com/phore/phore-hydrator","last_synced_at":"2026-01-22T23:59:06.782Z","repository":{"id":57039198,"uuid":"291968583","full_name":"phore/phore-hydrator","owner":"phore","description":"serialize / unserialize plain into object structures","archived":false,"fork":false,"pushed_at":"2025-01-10T11:53:51.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-20T06:54:29.454Z","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/phore.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}},"created_at":"2020-09-01T10:35:37.000Z","updated_at":"2025-01-10T11:46:22.000Z","dependencies_parsed_at":"2025-01-10T12:40:52.107Z","dependency_job_id":null,"html_url":"https://github.com/phore/phore-hydrator","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.3571428571428571,"last_synced_commit":"48460bf7918291174af2458fe0e6a105d6f798d2"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/phore/phore-hydrator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-hydrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-hydrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-hydrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-hydrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phore","download_url":"https://codeload.github.com/phore/phore-hydrator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-hydrator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28675290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T20:48:19.482Z","status":"ssl_error","status_checked_at":"2026-01-22T20:48:14.968Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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-22T23:59:04.940Z","updated_at":"2026-01-22T23:59:06.776Z","avatar_url":"https://github.com/phore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phore-hydrator\nserialize / unserialize plain into object structures. Hydrator parses\nthe DocComments of public properties and instanciates the classes\naccording to the definiton.\n\nExamples:\n- [hydrator-usage-example.php](doc/hydrator-usage-example.php)\n\nInstallation:\n\n```\ncomposer install phore/hydrator\n```\n\n## Basic Example\n\n```php\nclass UserData {\n    /**\n     * @var string\n     */\n    public $name;\n    \n    /**\n    * Assoc Array \n    * @var array\u003cstring, ClassType2\u003e \n    */\n    public $map;\n    \n    /**\n     * @var int\n     */\n    public $age;\n}\n\n$input = [\"name\"=\u003e\"bob\", \"age\"=\u003e37];\n\n$userData = phore_hydrate($input, UserData::class);\n\nassert( $userData instanceof UserData);\n```\n`$userData` is a `UserData` Object and all properties casted correctly\nto desired types specified in DocComments.\n\n## Recognized Annotations\n\n- Simple types like `string`, `int`, `bool`, `float`, `array`\n- Array types like `string[]`, `int[]`...\n- Object types `OtherClass`\n- Arrays of Objects `OtherClass[]`\n- Nullable properties `type|null`\n\n## Guide\n\n### Getters / Setters\n\nOn objects, hydrator will try to set property values in the following\norder:\n\n1) If object has a `set\u003cPropertyName\u003e($value)`-Method it will use it first\n2) If the property is `public` it will be set directly\n3) If there is a `__set($name, $value)` method it will be used\n\n### Default Values\n\nDefault values will be applied if no data was found for the specific\nkey\n\n```\npublic $prop1 = []\n```\n### Optional Properties\n\nYou can define a property as optional by adding `|null` to the\nDocBlock.\n\n```\n/**\n * @var SomeEntity1|null\n */\npublic $entity1;\n```\n\nIf the input data was not found, the value will be `null`.\n\n### Filter input data before hydration\n\nTo ease backwards compatibility issues, the magick `__hydrate()` method\nis called to prefilter the input data before it is hydrated.\n\n```php\nclass Entity1 {\n    public $p1;\n\n    public function __hydrate(array $input) : array\n    {\n        // .. modify input to match the object ..\n        return $input;\n    }\n}\n```\n\n### Dealing with additional / undefined input data\n\nBy default, on undefined input keys, hydrator will throw\nan exception. You can toggle this behaviour \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-hydrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphore%2Fphore-hydrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-hydrator/lists"}