{"id":26964453,"url":"https://github.com/nicklayb/php_assoc_map","last_synced_at":"2025-04-03T06:32:26.750Z","repository":{"id":57533082,"uuid":"134017837","full_name":"nicklayb/php_assoc_map","owner":"nicklayb","description":"Library that parses PHP's associative array into Elixir's map.","archived":false,"fork":false,"pushed_at":"2024-06-04T13:07:53.000Z","size":80,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-08T15:19:23.297Z","etag":null,"topics":["associative-array","map","parser","php"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/nicklayb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-05-19T01:04:18.000Z","updated_at":"2024-06-04T13:07:57.000Z","dependencies_parsed_at":"2024-02-03T03:32:19.874Z","dependency_job_id":"5e59c2c0-eb6d-4949-8947-48513debf1a3","html_url":"https://github.com/nicklayb/php_assoc_map","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"9bf8c8c1e0134552d061365d11490306b28c69ae"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Fphp_assoc_map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Fphp_assoc_map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Fphp_assoc_map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Fphp_assoc_map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicklayb","download_url":"https://codeload.github.com/nicklayb/php_assoc_map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246948037,"owners_count":20859366,"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":["associative-array","map","parser","php"],"created_at":"2025-04-03T06:31:36.143Z","updated_at":"2025-04-03T06:32:26.739Z","avatar_url":"https://github.com/nicklayb.png","language":"Elixir","readme":"# PhpAssocMap\n\n[![Build Status](https://travis-ci.org/nicklayb/php_assoc_map.svg?branch=master)](https://travis-ci.org/nicklayb/php_assoc_map)\n[![Coverage Status](https://coveralls.io/repos/github/nicklayb/php_assoc_map/badge.svg?branch=master)](https://coveralls.io/github/nicklayb/php_assoc_map?branch=master)\n\nLibrary that parses PHP's associative array into Elixir's map.\n\nAt his current state,\n\n\n## NEW\n\nA rewrite has been done to the parsing to accelerate the process and make more stable. The use of Leex and Yecc had become very handy. Some utils have been removed, if you were using them, we recommend not migrating to 1.0 yet. If you were using `PhpAssocMap.to_tuple/1` or `PhpAssocMap.to_map/1`, everthing should work as it was.\n\nFeel free to post any issue.\n\n## Installation\n\nAdd the following to your `mix.exs` file:\n```elixir\ndefp deps do\n  [\n    # ...\n    {:php_assoc_map, \"~\u003e 3.0\"}\n  ]\nend\n```\n\nDon't forget to run `mix deps.get` to update dependencies\n\n### Note\n\nThis library only parses single quoted string as key and value. In PHP, the double quoted string can do interpolation which makes them a bit greedy on performance. For this particular reason, the serialized array will be using single quote. But you can fill any format of associative array (using either single (') or double (\") quote as string delimiter)\n\n## Usage\n\n### Parsing\n\n#### To map\n\nIf you would like to retrieve a map of you array, the function `to_map/1` will do the job.\n```elixir\nsource = \"\"\"\n[\n  'lvl_1_1' =\u003e [\n    'lvl_2_1' =\u003e 1,\n    'lvl_2_2' =\u003e 'Single quoted string',\n    'lvl_2_3' =\u003e 'A string, with \"commas\" and stuff'\n  ],\n  'lvl_1_2' =\u003e false\n]\n\"\"\"\n\nPhpAssocMap.to_map(source)\n\n# Outputs\n%{\n  \"lvl_1_1\": %{\n    \"lvl_2_1\": 1,\n    \"lvl_2_2\": \"Single quoted string\",\n    \"lvl_2_3\": \"A string, with \"commas\" and stuff\"\n  },\n  \"lvl_1_2\": false\n}\n\n```\n\n#### To tuple\n\nIf you would like to retrieve a list o tuple instead of mapof you array, the function `to_tuple/1` will be your friend.\n```elixir\nsource = \"\"\"\n[\n  'lvl_1_1' =\u003e [\n    'lvl_2_1' =\u003e 1,\n    'lvl_2_2' =\u003e 'Single quoted string',\n    'lvl_2_3' =\u003e \"A string, with \"commas\" and stuff\"\n  ],\n  'lvl_1_2' =\u003e false\n]\n\"\"\"\n\nPhpAssocMap.to_tuple(source)\n\n# Outputs\n[\n  {\"lvl_1_1\", [\n      {\"lvl_2_1\", 1},\n      {\"lvl_2_2\", \"Single quoted string\"},\n      {\"lvl_2_3\", \"A string, with \\\"commas\\\" and stuff\"}\n    ]\n  },\n  {\"lvl_1_2\", false}\n}\n```\n\n### Serializing\n\n#### From map\n\nIf you would like to get a serialized version of a map, the function `from_map/1` will do it.\n\n```elixir\nsource = %{\n  \"lvl_1_1\" =\u003e %{\n    \"lvl_2_1\" =\u003e 1,\n    \"lvl_2_2\" =\u003e \"Single quoted string\",\n    \"lvl_2_3\" =\u003e \"A string, with \\\"commas\\\" and stuff\"\n  },\n  \"lvl_1_2\" =\u003e false\n}\n\nPhpAssocMap.from_map(source)\n```\n\n#### From tuple\n\nIf you would like to retrieve a list o tuple instead of mapof you array, the function `to_tuple/1` will be your friend.\n\n```elixir\nsource = [\n  {\"lvl_1_1\", [\n      {\"lvl_2_1\", 1},\n      {\"lvl_2_2\", \"Single quoted string\"},\n      {\"lvl_2_3\", \"A string, with \\\"commas\\\" and stuff\"}\n    ]\n  },\n  {\"lvl_1_2\", false}\n}\n\nPhpAssocMap.from_tuple(source)\n\n```\n\n# Outputs\n\n#### Formatting the result\n\nIf you would like to print the serialized array to a PHP file, you might want to have indented. For this purpose, you can use the `explode/2` function from the `PhpAssocMap.Utils` module.\n\n```elixir\nstring_source = \"\"\"\n['lvl_1_1'=\u003e['lvl_2_1'=\u003e1,'lvl_2_2'=\u003e'Single quoted string','lvl_2_3'=\u003e'A string, with \"commas\" and stuff'],'lvl_1_2'=\u003efalse]\n\"\"\"\nsource = PhpAssocMap.to_tuple(string_source)\n# You can replace de 2 below for the number of space to use\nPhpAssocMap.from_tuple(source, {:spaces, 2})\n\n\"\"\"\n[\n\\s\\s'lvl_1_1' =\u003e [\n\\s\\s\\s\\s'lvl_2_1' =\u003e 1,\n\\s\\s\\s\\s'lvl_2_2' =\u003e 'Single quoted string',\n\\s\\s\\s\\s'lvl_2_3' =\u003e 'A string, with \"commas\" and stuff'\n\\s\\s\\s\\s],\n\\s\\s'lvl_1_2' =\u003e false\n\\s\\s]\n\"\"\"\n```\n\n*You can replace de 2 below for the number of space to use*\n\n##### Or with tabs instead\n\n```elixir\nPhpAssocMap.from_tuple(source, :tabs)\n\n\"\"\"\n[\n\\t'lvl_1_1' =\u003e [\n\\t\\t'lvl_2_1' =\u003e 1,\n\\t\\t'lvl_2_2' =\u003e 'Single quoted string',\n\\t\\t'lvl_2_3' =\u003e 'A string, with \"commas\" and stuff'\n\\t\\t],\n\\t'lvl_1_2' =\u003e false\n\\t]\n\"\"\"\n```\n\n##### Or no indentation/breakline\n\n```elixir\nPhpAssocMap.from_tuple(source, :none)\n\n\"\"\"\n[\n\\t'lvl_1_1' =\u003e [\n\\t\\t'lvl_2_1' =\u003e 1,\n\\t\\t'lvl_2_2' =\u003e 'Single quoted string',\n\\t\\t'lvl_2_3' =\u003e 'A string, with \"commas\" and stuff'\n\\t\\t],\n\\t'lvl_1_2' =\u003e false\n\\t]\n\"\"\"\n```\n\n## Limitations\n\n### Keyed array\n\nCurrently, the library only supports named keys, which means that straight are not parsed a the moment.\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/D1D2YX9OU)\n","funding_links":["https://ko-fi.com/D1D2YX9OU"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklayb%2Fphp_assoc_map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicklayb%2Fphp_assoc_map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklayb%2Fphp_assoc_map/lists"}