{"id":21810677,"url":"https://github.com/samdark/hydrator","last_synced_at":"2025-08-25T14:04:30.187Z","repository":{"id":62539693,"uuid":"72486915","full_name":"samdark/hydrator","owner":"samdark","description":"Allows extracting data from objects and getting objects from data","archived":false,"fork":false,"pushed_at":"2020-08-24T22:40:35.000Z","size":23,"stargazers_count":115,"open_issues_count":2,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-07-27T19:02:42.457Z","etag":null,"topics":["hydrator","php"],"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/samdark.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"samdark","patreon":"samdark"}},"created_at":"2016-10-31T23:34:06.000Z","updated_at":"2025-05-16T19:12:43.000Z","dependencies_parsed_at":"2022-11-02T15:46:16.447Z","dependency_job_id":null,"html_url":"https://github.com/samdark/hydrator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/samdark/hydrator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fhydrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fhydrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fhydrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fhydrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samdark","download_url":"https://codeload.github.com/samdark/hydrator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdark%2Fhydrator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272077690,"owners_count":24869288,"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-25T02:00:12.092Z","response_time":1107,"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":["hydrator","php"],"created_at":"2024-11-27T13:37:07.750Z","updated_at":"2025-08-25T14:04:30.107Z","avatar_url":"https://github.com/samdark.png","language":"PHP","readme":"Hydrator\n========\n\nHydrator can be used for two purposes:\n\n- To extract data from a class to be further stored in a persistent storage.\n- To fill an object with data or create a new instance of a class filled with data.\n\nIn both cases it is saving and filling protected and private properties without calling\nany methods which leads to ability to persist state of an object with properly encapsulated\ndata.\n\n[![Latest Stable Version](https://poser.pugx.org/samdark/hydrator/v/stable.png)](https://packagist.org/packages/samdark/hydrator)\n[![Total Downloads](https://poser.pugx.org/samdark/hydrator/downloads.png)](https://packagist.org/packages/samdark/hydrator)\n[![Build Status](https://travis-ci.org/samdark/hydrator.svg?branch=master)](https://travis-ci.org/samdark/hydrator)\n\n\n## Installation\n\nThe preferred way to install this package is through [composer](http://getcomposer.org/download/).\n\n```\ncomposer require --prefer-dist samdark/hydrator\n```\n\n## Usage\n\nConsider we have a `Post` entity which represents a blog post. It has a title and a text. A unique id is generated to\nidentify it.\n\n```php\nclass Post\n{\n    private $id;\n    protected $title;\n    protected $text;\n\n    public function __construct($title, $text)\n    {\n        $this-\u003eid = uniqid('post_', true);\n        $this-\u003etitle = $title;\n        $this-\u003etext = $text;\n    }\n   \n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n    \n    public function getTitle()\n    {\n        return $this-\u003etitle;\n    }\n    \n    public function setTitle($title)\n    {\n        $this-\u003etitle = $title;\n    }\n    \n    public function getText()\n    {\n        return $this-\u003etext;\n    }\n    \n    public function setText()\n    {\n        return $this-\u003etext;\n    }\n}\n```\n\nSaving a post to database:\n\n```php\n$post = new Post('First post', 'Hell, it is a first post.');\n\n$postHydrator = new \\samdark\\hydrator\\Hydrator([\n    'id' =\u003e 'id',\n    'title' =\u003e 'title',\n    'text' =\u003e 'text',\n]);\n\n$data = $postHydrator-\u003eextract($post);\nsave_to_database($data);\n```\n\nLoading post from database:\n\n```php\n\u003c?php\n$data = load_from_database();\n\n$postHydrator = new \\samdark\\hydrator\\Hydrator([\n    'id' =\u003e 'id',\n    'title' =\u003e 'title',\n    'text' =\u003e 'text',\n]);\n\n$post = $postHydrator-\u003ehydrate($data, Post::class);\necho $post-\u003egetId();\n```\n\nFilling existing post object with data:\n\n```php\n$data = load_from_database();\n\n$postHydrator = new \\samdark\\hydrator\\Hydrator([\n    'title' =\u003e 'title',\n    'text' =\u003e 'text',\n]);\n\n$post = get_post();\n$post = $postHydrator-\u003ehydrateInto($data, $post);\necho $post-\u003egetTitle();\n```\n","funding_links":["https://github.com/sponsors/samdark","https://patreon.com/samdark"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdark%2Fhydrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamdark%2Fhydrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdark%2Fhydrator/lists"}