{"id":15028557,"url":"https://github.com/blacktrs/data-transformer","last_synced_at":"2026-01-28T01:34:58.032Z","repository":{"id":174144944,"uuid":"553641348","full_name":"blacktrs/data-transformer","owner":"blacktrs","description":"Zero-dependency PHP array-to-object transformer","archived":false,"fork":false,"pushed_at":"2023-09-30T08:15:57.000Z","size":254,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T06:27:43.782Z","etag":null,"topics":["array-transformer","data-transfer-object","php","php-library","php82"],"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/blacktrs.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":"2022-10-18T14:28:14.000Z","updated_at":"2024-09-18T17:33:04.000Z","dependencies_parsed_at":"2025-01-19T21:43:55.254Z","dependency_job_id":"adfe362e-964e-442e-9b26-9a5d5aaa554d","html_url":"https://github.com/blacktrs/data-transformer","commit_stats":null,"previous_names":["blacktrs/data-transformer"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/blacktrs/data-transformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacktrs%2Fdata-transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacktrs%2Fdata-transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacktrs%2Fdata-transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacktrs%2Fdata-transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blacktrs","download_url":"https://codeload.github.com/blacktrs/data-transformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blacktrs%2Fdata-transformer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28831751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T23:29:49.665Z","status":"ssl_error","status_checked_at":"2026-01-27T23:25:58.379Z","response_time":168,"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":["array-transformer","data-transfer-object","php","php-library","php82"],"created_at":"2024-09-24T20:08:37.014Z","updated_at":"2026-01-28T01:34:58.018Z","avatar_url":"https://github.com/blacktrs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Scrutinizer coverage](https://img.shields.io/scrutinizer/coverage/g/blacktrs/data-transformer/main)\u0026nbsp;\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/blacktrs/data-transformer/php.yaml)\u0026nbsp;\n![Packagist Version](https://img.shields.io/packagist/v/blacktrs/data-transformer)\n\n# Data transformer\n\nThe modern PHP library for converting arrays into objects and vice-versa.\n\n## Installation\n\n`composer require blacktrs/data-transformer`\n\n## Summary\n\nBy default, the library will try to resolve `public` properties and match the with array fields. \nThe transformer is trying to find an object property with equal name as array field. \nIn case, if object missing such fields, the transformer converts array keys into camel case.\nHowever, it is possible to configure needed properties with attributes.\n\n\n### Features\n* Seamless converting of objects into arrays and vice-versa\n* Auto conversion of nested properties with class type-hint into array and vice-versa\n* The library respects the declared property type\n* The library will respect private properties unless they will be declared explicitly as writable by the attribute\n* The library takes into account getters or methods with the same name as a property\n* Enum conversion\n* Stringable objects conversion\n* Configurable custom property value resolvers\n* Configurable custom object transformers\n\n## Configuration\n\nDefault transformer implementation `\\Blacktrs\\DataTransformer\\Transformer\\Transformer`\nallows to force private properties write by using method `setIncludePrivateProperties` or constructor parameter `$includePrivateProperties`\n\n### Attribute `DataField`\nThis attribute is applicable to properties. By this attribute you can configure the behavior for each property you need\n\nThe following parameters can be specified:\n* `string|null $nameIn` Field name in an input array to map with the property\n* `string|null $nameOut` Field name in an output array to fill with the property data\n* `ValueResolverInterface|class-string\u003cValueResolverInterface\u003e|null $valueResolver` Custom value resolver to convert property data in a needed way\n* `array\u003ckey,value\u003e $valueResolverArguments` Additional arguments passed into value resolver\n* `TransformerInterface|class-string\u003cTransformerInterface\u003e|null $objectTransformer` Custom property transformer to achieve more control in case if object passed\n* `bool $ignoreTransform` Skip property while transforming an array into the object\n* `bool $ignoreSerialize` Skip property while serializing an object into array\n\n### Attribute `DataObject`\nThis attribute is applicable to classes and allows to use custom object serializer while converting object into other form\n\nThe following parameters can be specified:\n* `ObjectSerializerInterface|class-string\u003cObjectSerializerInterface\u003e|null $objectTransformer` Custom object serializer\n\n## Examples\n\n### Convert the array into the object\n\n```php\nuse Blacktrs\\DataTransformer\\Attribute\\DataField;\nuse Blacktrs\\DataTransformer\\Value\\DateTimeValueResolver;\nuse Blacktrs\\DataTransformer\\Transformer\\Transformer;\n\nclass RequestObject\n{\n    public readonly int $id;\n    public readonly string $email;\n    public readonly string $name;\n    #[DataField(valueResolver: DateTimeValueResolver::class)]\n    public readonly \\DateTime $date;\n}\n\n$requestPayload = ['id' =\u003e 1, 'email' =\u003e 'some.email@example.com', 'name' =\u003e 'John Doe', 'date' =\u003e '2023-06-01 10:10:10'];\n\n$transformer = new Transformer();\n$requestObject = $transformer-\u003etransform(RequestObject::class, $requestPayload);\n\necho $requestObject-\u003eid; // 1\necho $requestObject-\u003eemail; // some.email@example.com\necho $requestObject-\u003ename; // John Doe\necho $requestObject-\u003edate-\u003eformat('Y-m-d'); // 2023-06-01\n```\n\n### Convert the object into the array\n\n```php\nuse Blacktrs\\DataTransformer\\Serializer\\ObjectSerializer;\n\nclass ResponseObject\n{\n    public function __construct(\n        public readonly int $id,\n        public readonly string $email,\n        public readonly string $name\n    ) {\n    }\n}\n\n$responseObject = new ResponseObject(\n    id: 1, \n    email: 'some.email@example.com', \n    name: 'John Doe'\n);\n\n$serializer = new ObjectSerializer();\n$responseArray = $serializer-\u003eserialize($responseObject);\n\necho $responseArray['id']; // 1\n```\n\n### More examples\nMore examples could be found in `tests`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacktrs%2Fdata-transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblacktrs%2Fdata-transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacktrs%2Fdata-transformer/lists"}