{"id":18084868,"url":"https://github.com/coderofsalvation/datamapper-minimal","last_synced_at":"2025-04-06T00:13:25.165Z","repository":{"id":36857225,"uuid":"41164183","full_name":"coderofsalvation/datamapper-minimal","owner":"coderofsalvation","description":"Easily transform arrays and objects in PHP with different layouts into one format","archived":false,"fork":false,"pushed_at":"2020-05-28T18:47:18.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-12T06:21:43.522Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderofsalvation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://gumroad.com/l/hGYGh"}},"created_at":"2015-08-21T15:47:14.000Z","updated_at":"2020-05-28T18:47:21.000Z","dependencies_parsed_at":"2022-08-21T04:10:19.947Z","dependency_job_id":null,"html_url":"https://github.com/coderofsalvation/datamapper-minimal","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/coderofsalvation%2Fdatamapper-minimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdatamapper-minimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdatamapper-minimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderofsalvation%2Fdatamapper-minimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderofsalvation","download_url":"https://codeload.github.com/coderofsalvation/datamapper-minimal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415976,"owners_count":20935387,"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-10-31T15:08:28.183Z","updated_at":"2025-04-06T00:13:25.086Z","avatar_url":"https://github.com/coderofsalvation.png","language":"PHP","funding_links":["https://gumroad.com/l/hGYGh"],"categories":[],"sub_categories":[],"readme":"DataMapper-Minimal\n==================\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"\" width=\"250\" src=\"http://www.gifbin.com/bin/1232014623_seven_1.gif\"/\u003e\n  \u003c/p\u003e\nEasily transform arrays and objects with different layouts into one format.\nThink importing data from several sources in different formats to generate statistics or exports.\n\n## Usage \n\n    $ composer require coderofsalvation/datamapper-minimal\n\nAnd then \n\n    \u003c? \n      use coderofsalvation\\DataMapper;\n      $datamapper = new DataMapper();\n    ?\u003e \n\nLets say this is our desired object format: \n\n    class MyObject {\n      public $name;\n      public $id;\n    }\n\nBut source A provide these object formats:\n\n    [{ \"short_name\": \"foo\", \"ID\": 12 },{ \"short_name\": \"bar\", \"ID\":13}]\n\nAnd oh no! source B has this object format:    \n\n    \u003citems\u003e \n      \u003citem id=\"15\"\u003e\n        \u003cName\u003eBoo\u003c/Name\u003e\n      \u003c/item\u003e\n    \u003c/items\u003e       \n\nThis is going to be a mess...or not?\nNope, we can just define transformations and convert them in batch:\n\n    $datamapper-\u003eaddMapping(\"A\", array(\n      array( \"source\" =\u003e \"short_name\", \"destination\" =\u003e \"name\", \"transform\" =\u003e function($s,\u0026$d){ return $s-\u003eshort_name;    } ), \n      array( \"source\" =\u003e \"id\",         \"destination\" =\u003e \"id\",   \"transform\" =\u003e function($s,\u0026$d){ return $s-\u003eid;            } ) \n    ));\n\n    $datamapper-\u003eaddMapping(\"B\", array(\n      array( \"source\" =\u003e \"Name\", \"destination\" =\u003e \"name\",       \"transform\" =\u003e function($s,\u0026$d){ return $s-\u003eName;                } ), \n      array( \"source\" =\u003e \"Id\",   \"destination\" =\u003e \"id\",         \"transform\" =\u003e function($s,\u0026$d){ return $s-\u003egetAttribute(\"id\");  } )\n    ));\n\n    // lets do it!\n    $items = [];\n    foreach( $Aitems as $item ) $items[] = $datamapper-\u003emap(\"A\", $item, new MyObject() );\n    foreach( $Bitems as $item ) $items[] = $datamapper-\u003emap(\"B\", $item, new MyObject() );\n\n    print_r($items);\n    // voila there you go :D\n\n## License\n\nBSD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdatamapper-minimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderofsalvation%2Fdatamapper-minimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderofsalvation%2Fdatamapper-minimal/lists"}