{"id":15470867,"url":"https://github.com/pflorek/php-elevator","last_synced_at":"2026-05-02T09:32:10.487Z","repository":{"id":57038374,"uuid":"85120806","full_name":"pflorek/php-elevator","owner":"pflorek","description":"PHP Elevator","archived":false,"fork":false,"pushed_at":"2019-07-16T21:42:27.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T01:13:15.880Z","etag":null,"topics":["array","composer","flatten","materialized-paths","php","tree"],"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/pflorek.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}},"created_at":"2017-03-15T21:04:23.000Z","updated_at":"2019-07-16T21:36:48.000Z","dependencies_parsed_at":"2022-08-23T23:30:56.610Z","dependency_job_id":null,"html_url":"https://github.com/pflorek/php-elevator","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pflorek%2Fphp-elevator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pflorek%2Fphp-elevator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pflorek%2Fphp-elevator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pflorek%2Fphp-elevator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pflorek","download_url":"https://codeload.github.com/pflorek/php-elevator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246034276,"owners_count":20712851,"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":["array","composer","flatten","materialized-paths","php","tree"],"created_at":"2024-10-02T02:07:23.698Z","updated_at":"2026-05-02T09:32:10.412Z","avatar_url":"https://github.com/pflorek.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Elevator\n\n[![Build Status](https://travis-ci.org/pflorek/php-elevator.svg?branch=master)](https://travis-ci.org/pflorek/php-elevator)\n[![Coverage Status](https://coveralls.io/repos/github/pflorek/php-elevator/badge.svg?branch=master)](https://coveralls.io/github/pflorek/php-elevator?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pflorek/php-elevator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/pflorek/php-elevator/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/pflorek/elevator/v/stable)](https://packagist.org/packages/pflorek/elevator)\n[![Total Downloads](https://poser.pugx.org/pflorek/elevator/downloads)](https://packagist.org/packages/pflorek/elevator)\n[![Latest Unstable Version](https://poser.pugx.org/pflorek/elevator/v/unstable)](https://packagist.org/packages/pflorek/elevator)\n[![License](https://poser.pugx.org/pflorek/elevator/license)](https://packagist.org/packages/pflorek/elevator)\n[![Monthly Downloads](https://poser.pugx.org/pflorek/elevator/d/monthly)](https://packagist.org/packages/pflorek/elevator)\n[![Daily Downloads](https://poser.pugx.org/pflorek/elevator/d/daily)](https://packagist.org/packages/pflorek/elevator)\n[![composer.lock](https://poser.pugx.org/pflorek/elevator/composerlock)](https://packagist.org/packages/pflorek/elevator)\n\nThis library provides a simple way to elevate a map (associative array) \nto a tree or to flatten a tree to a map (associative array). The tree's \nnode keys are the tokens of the map's materialized path separated by\na delimiter.\n\nThis library comes handy to map flat lists like SQL results to\ndocuments. The result's column name could be a materialized path of\nthe target document. You can pass a result row to `Elevator::up` and\nproceed marshalling by passing the elevated tree to a JSON or XML\nserializer. On unmarshalling just pass the deserialized array tree\nto `Elevator::down` and feed e.g. a SQL statement.\n\n## Usage\n\n### Elevate\n\nElevate a map with materialized paths to a tree:\n\n```PHP\nuse PFlorek\\Elevator\\Elevator;\nuse PFlorek\\Elevator\\ElevatorFactory;\nuse function \\PFlorek\\Elevator\\array_elevate;\n\n$flattened = [\n    'World.Asia.Afghanistan.0' =\u003e '...',\n    'World.Africa' =\u003e true,\n    'World.Antarctica' =\u003e -25.2,\n    'World.Europe' =\u003e new \\stdClass(),\n    'World.North America' =\u003e [],\n];\n\n// object oriented\n$factory = ElevatorFactory::getInstance();\n$elevator = $factory-\u003ecreate();\n$elevator-\u003eup($flattened);\n\n// or functional\n$elevated = array_elevate($flattened);\n\nvar_dump($elevated);\n\n//returns [\"World\"] =\u003e array(5) {\n//  [\"Asia\"] =\u003e array(1) {\n//    [\"Afghanistan\"] =\u003e array(1) {\n//      [0] =\u003e string(3) \"...\"\n//    }\n//  }\n//  [\"Africa\"] =\u003e bool(true)\n//  [\"Antarctica\"] =\u003e float(-25.2)\n//  [\"Europe\"]=\u003e object(stdClass)#298 (0) {}\n//  [\"North America\"]=\u003e []\n//}\n```\n\n### Flatten\n\nFlattens a tree to a map which keys are the materialized path of the node's keys:\n\n\n```PHP\nuse PFlorek\\Elevator\\Elevator;\nuse PFlorek\\Elevator\\ElevatorFactory;\nuse function \\PFlorek\\Elevator\\array_flatten;\n\n$elevated = [\n    'World' =\u003e [\n        'Asia' =\u003e [\n            'Afghanistan' =\u003e [\n                '...'\n            ]\n        ],\n        'Africa' =\u003e true,\n        'Antarctica' =\u003e -25.2,\n        'Europe' =\u003e new \\stdClass(),\n        'North America' =\u003e [],\n    ]\n];\n\n// object oriented\n$factory = ElevatorFactory::getInstance();\n$elevator = $factory-\u003ecreate();\n$elevator-\u003edown($flattened);\n\n// or functional\n$flattened = array_flatten($elevated);\n\nvar_dump($flattened);\n\n//returns array(5) {\n//  [\"World.Asia.Afghanistan.0\"] =\u003e string(3) \"...\"\n//  [\"World.Africa\"] =\u003e bool(true)\n//  [\"World.Antarctica\"] =\u003e float(-25.2)\n//  [\"World.Europe\"] =\u003e object(stdClass) (0) { }\n//  [\"World.North America\"] =\u003e array(0) { }\n//}\n```\n\n## Installation\n\nUse [Composer] to install the package:\n\n```bash\ncomposer require pflorek/elevator\n```\n\n## Authors\n\n* [Patrick Florek]\n\n## Contribute\n\nContributions are always welcome!\n\n* Report any bugs or issues on the [issue tracker].\n* You can download the sources at the package's [Git repository].\n\n## License\n\nAll contents of this package are licensed under the [MIT license].\n\n[Composer]: https://getcomposer.org\n[Git repository]: https://github.com/pflorek/php-elevator\n[issue tracker]: https://github.com/pflorek/php-elevator/issues\n[MIT license]: LICENSE\n[Patrick Florek]: https://github.com/pflorek\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpflorek%2Fphp-elevator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpflorek%2Fphp-elevator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpflorek%2Fphp-elevator/lists"}