{"id":20980614,"url":"https://github.com/php-api-clients/hydrator","last_synced_at":"2025-05-14T15:30:46.741Z","repository":{"id":52422289,"uuid":"65233185","full_name":"php-api-clients/hydrator","owner":"php-api-clients","description":":droplet:","archived":false,"fork":false,"pushed_at":"2023-12-15T17:49:23.000Z","size":404,"stargazers_count":4,"open_issues_count":7,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T08:56:30.956Z","etag":null,"topics":["hacktoberfest","hydrator","php","php7","reactphp"],"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/php-api-clients.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2016-08-08T19:35:34.000Z","updated_at":"2021-02-18T22:06:32.000Z","dependencies_parsed_at":"2023-12-15T18:45:52.650Z","dependency_job_id":"2fccb1d0-0f07-45ff-9aea-9763e16d107b","html_url":"https://github.com/php-api-clients/hydrator","commit_stats":{"total_commits":304,"total_committers":5,"mean_commits":60.8,"dds":0.06907894736842102,"last_synced_commit":"04289d4357ee83200edf092a357a130d60fbc053"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Fhydrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Fhydrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Fhydrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Fhydrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-api-clients","download_url":"https://codeload.github.com/php-api-clients/hydrator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171576,"owners_count":22026466,"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":["hacktoberfest","hydrator","php","php7","reactphp"],"created_at":"2024-11-19T05:29:22.977Z","updated_at":"2025-05-14T15:30:44.520Z","avatar_url":"https://github.com/php-api-clients.png","language":"PHP","readme":"# Hydrator for API Clients for PHP 7.x\n\n[![License](https://poser.pugx.org/api-clients/hydrator/license.png)](https://packagist.org/packages/api-clients/hydrator)\n![Linux Build](https://blog.wyrihaximus.net/images/linux-logo-icon-20.png)[![Build Status](https://travis-ci.org/php-api-clients/hydrator.svg?branch=master)](https://travis-ci.org/php-api-clients/hydrator)\n![Windows Build](https://blog.wyrihaximus.net/images/windows-logo-icon-20.png)[![Build status](https://ci.appveyor.com/api/projects/status/jp1hmn4wrcjnnwpl?svg=true)](https://ci.appveyor.com/project/WyriHaximus/hydrator)\n[![Code Coverage](https://scrutinizer-ci.com/g/php-api-clients/hydrator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-api-clients/hydrator/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/api-clients/hydrator/v/stable.png)](https://packagist.org/packages/api-clients/hydrator)\n[![Total Downloads](https://poser.pugx.org/api-clients/hydrator/downloads.png)](https://packagist.org/packages/api-clients/hydrator/stats)\n[![PHP 7 ready](http://php7ready.timesplinter.ch/php-api-clients/hydrator/badge.svg)](https://travis-ci.org/php-api-clients/hydrator)\n\nIn a nutshell this package is a wrapper around [`ocramius/generated-hydrator`](https://github.com/Ocramius/GeneratedHydrator) adding some annotations for nesting, collections, and renaming properties.\n\n# Install\n\nTo install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.\n\n```\ncomposer require api-clients/hydrator\n```\n\n# Preheating\n\nIn order to ensure the hydrator doesn't block the hydrator comes with a `preheat` method. Give it a the path of a namespace and the namespace it self, and it will create a hydrator for each resource it finds plus read the annotations for the given resource. This ensures all disk IO and heavy CPU operations have been completed before using the hydrator. When using the hydrator in async code the hydrator should, preferable, be created before running the loop.\n\n# Set up\n\nBefore using the Hydrator it has to be set up, note that using this method of setting up it will also preheat the hydrator.\n\n```php\n$loop = LoopFactory::create();\n$commandBus = new CommandBus(); // Implementation of ApiClients\\Tools\\CommandBus\\CommandBusInterface\n$options = []; // Options as described below\n$hydrator = Factory::create($loop, $commandBus, $options);\n```\n\n# Hydrating\n\nThe hydrator offers two methods of hydrating. The first is a method that accepts FQCN (Fully Qualified Class Name), for example `ApiClients\\Client\\Github\\Resource\\Async\\Emoji` or `Emoji::class` for short, and the JSON holding the resource contents.\n\n```php\n$resource = $hydrator-\u003ehydrateFQCN(Emoji::class, $json);\n```\n\nOr when you've configured `Options::NAMESPACE`, `Options::NAMESPACE_SUFFIX` you can do the same with the `hydrate` method, which internally uses `hydrateFQCN`:\n\n```php\n$resource = $hydrator-\u003ehydrate('Emoji', $json);\n```\n\n# Extracting\n\nA resource can also be broken down again into JSON with the hydrator.\n\n```php\n$json = $hydrator-\u003eextractFQCN(Emoji::class, $resource);\n```\n\nSame magic as the `hydrate` method applies to the `extract` method, this does exactly the same as `extractFQCN` when `Options::NAMESPACE` and `Options::NAMESPACE_SUFFIX` are configured.\n```php\n$json = $hydrator-\u003eextract('Emoji', $resource);\n```\n\n# Options\n\n## Options::ANNOTATIONS\n\nSupply an array with extra annotations in the format key =\u003e annotation, value =\u003e handler.\n\n## Options::ANNOTATION_CACHE_DIR\n\nCache directory for resource annotations.\n\n## Options::NAMESPACE\n\nBase namespace where the resources reside, required.\n\n## Options::NAMESPACE_DIR\n\nFilesystem path to the base namespace where the resources reside, required. \n\n## Options::NAMESPACE_SUFFIX\n\nNamespaces suffix, useful for different types of the same resource.\n\n## Options::RESOURCE_CACHE_DIR\n\nCache directory for resource generated resources.\n\n## Options::RESOURCE_NAMESPACE\n\nNamespace for generated resources.\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 Cees-Jan Kiewiet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-api-clients%2Fhydrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-api-clients%2Fhydrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-api-clients%2Fhydrator/lists"}