{"id":18553115,"url":"https://github.com/chipbell4/data-mapper","last_synced_at":"2025-10-05T07:52:28.551Z","repository":{"id":17891870,"uuid":"20840734","full_name":"chipbell4/data-mapper","owner":"chipbell4","description":"A Data Mapper From Flat Arrays to Object Structure","archived":false,"fork":false,"pushed_at":"2014-06-15T15:43:22.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-02-17T10:49:16.992Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chipbell4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-14T20:01:14.000Z","updated_at":"2014-06-15T15:43:22.000Z","dependencies_parsed_at":"2022-09-02T13:41:31.837Z","dependency_job_id":null,"html_url":"https://github.com/chipbell4/data-mapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipbell4%2Fdata-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipbell4%2Fdata-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipbell4%2Fdata-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chipbell4%2Fdata-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chipbell4","download_url":"https://codeload.github.com/chipbell4/data-mapper/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254330714,"owners_count":22053033,"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-06T21:16:08.588Z","updated_at":"2025-10-05T07:52:23.513Z","avatar_url":"https://github.com/chipbell4.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Schema Mapper\n\n[![Build Status](https://travis-ci.org/chipbell4/data-mapper.svg)](https://travis-ci.org/chipbell4/data-mapper)\n\nUtility for mapping a flat array of data to a complex object tree via \ntheir constructors. The best way to observe is to see an example.\n\nSuppose you have a class ```Person``` that represents a Person (go figure).\nThe constructor looks something like this:\n```PHP\n__construct($name)\n{\n    $this-\u003ename = $name;\n}\n```\nPretty generic stuff. This library will take a schema like this:\n```JSON\n{\n    \"type\" : \"Person\",\n    \"fields\" : {\n        \"name\" : {\n            \"type\" : \"string\",\n            \"source\" : \"name_value\"\n        }\n    }\n}\n```\nAnd an array like this:\n```PHP\narray('name_value' =\u003e 'Chip')\n```\nand spit out a ```Person``` object with a name field of 'Chip'. This may\nseem like overkill, but the structure allows for more complex objects.\n\nConsider a class ```Couple``` with a constructor that looks like this:\n```PHP\n__construct(Person $p1, Person $p2, $hobby)\n{\n   // ...\n}\n``` \nAgain, typical fare, but it now has a little deeper dependency. In order to \nconstruct a ```Couple``` object, you're going to need two ```Person```s and\nalso a hobby. Given a schema like this:\n```JSON\n{\n    \"type\" : \"Couple\",\n    \"fields\" : {\n        \"p1\" : {\n            \"type\" : \"Person\",\n            \"fields\" : {\n                \"name\" : {\n\t\t\t\t\t\t\"type\" : \"string\",\n\t\t\t\t\t\t\"source\" : \"name_value_1\"\n                }\n            }\n        }\n        \"p2\" : {\n            \"type\" : \"Person\",\n            \"fields\" : {\n                \"name\" : {\n\t\t\t\t\t\t\"type\" : \"string\",\n\t\t\t\t\t\t\"source\" : \"name_value_2\"\n                }\n            }\n        },\n        \"hobby\" : {\n            \"type\" : \"string\",\n            \"source\" : \"hobby\" \n        }\n    }\n}\n```\nand an data array like\n```PHP\narray('name_value_1' =\u003e 'Chip', 'name_value_2' =\u003e 'April');\n```\nThe data mapper class can actually build a ```Couple``` object, with two people\nobjects, one with the name 'Chip' and the other with the name 'April'.\n\nTo use the class, simply instantiate and call:\n```PHP\n$mapper = new chipbell4\\DataMapper\\DataMapper();\n\n// assuming you already have a schema and flat data defined\n$obj = $mapper-\u003emap($schema, $data);\n\n// If the schema is still in a file\n$obj = $mapper-\u003emapFromFile('path/to/schema.json', $data);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipbell4%2Fdata-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchipbell4%2Fdata-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchipbell4%2Fdata-mapper/lists"}