{"id":19039618,"url":"https://github.com/windwalker-io/structure","last_synced_at":"2026-03-11T16:39:50.495Z","repository":{"id":20479619,"uuid":"23757545","full_name":"windwalker-io/structure","owner":"windwalker-io","description":"[DEPRECATED] Nested data structure storage object. ","archived":false,"fork":false,"pushed_at":"2022-02-16T21:47:41.000Z","size":126,"stargazers_count":42,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T21:02:19.915Z","etag":null,"topics":["php","registry","storage","struct","structure"],"latest_commit_sha":null,"homepage":"https://github.com/ventoviro/windwalker","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/windwalker-io.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-09-07T10:32:20.000Z","updated_at":"2024-12-16T13:48:55.000Z","dependencies_parsed_at":"2022-07-31T21:18:00.633Z","dependency_job_id":null,"html_url":"https://github.com/windwalker-io/structure","commit_stats":null,"previous_names":["ventoviro/windwalker-structure"],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fstructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fstructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fstructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fstructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windwalker-io","download_url":"https://codeload.github.com/windwalker-io/structure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514780,"owners_count":21443209,"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":["php","registry","storage","struct","structure"],"created_at":"2024-11-08T22:17:55.479Z","updated_at":"2025-12-18T09:05:34.764Z","avatar_url":"https://github.com/windwalker-io.png","language":"PHP","readme":"# Windwalker Structure\n\nWindwalker Structure is a storage of nested array or object, help us manage multi-level structures data.\n\n## Installation via Composer\n\nAdd this to the require block in your `composer.json`.\n\n``` json\n{\n    \"require\": {\n        \"windwalker/structure\": \"~3.0\"\n    }\n}\n```\n\n## Supported Formats\n\n- JSON\n- PHP file (return array or class)\n- JSON\n- [HJSON](https://hjson.org/)\n- YAML\n- [TOML](https://github.com/toml-lang/toml)\n- XML\n- INI\n\n## Getting Started\n\n``` php\nuse Windwalker\\Structure\\Structure;\n\n$structure = new Structure;\n\n// Set a value in the structure.\n$structure-\u003eset('foo', 'bar');\n\n// Get a value from the structure;\n$value = $structure-\u003eget('foo');\n\n```\n\n## Load config by Structure\n\n``` php\nuse Windwalker\\Structure\\Structure;\n\n$structure = new Structure;\n\n// Load by string\n$structure-\u003eloadString('{\"foo\" : \"bar\"}');\n\n$structure-\u003eloadString('\u003croot\u003e\u003c/root\u003e', 'xml');\n\n// Load by object or array\n$structure-\u003eload($object);\n\n// Load by file\n$structure-\u003eloadFile($root . '/config/config.json', 'json');\n```\n\n## Accessing a Structure by getter \u0026 setter\n\n### Get value\n\n``` php\n$structure-\u003eget('foo');\n\n// Get a non-exists value and return default\n$structure-\u003eget('foo', 'default');\n\n// OR\n\n$structure-\u003eget('foo') ?: 'default';\n```\n\n### Set value\n\n``` php\n// Set value\n$structure-\u003eset('bar', $value);\n\n// Sets a default value if not already assigned.\n$structure-\u003edef('bar', $default);\n```\n\n### Accessing children value by path\n\n``` php\n$json = '{\n\t\"parent\" : {\n\t\t\"child\" : \"Foo\"\n\t}\n}';\n\n$structure = new Structure($json);\n\n$structure-\u003eget('parent.child'); // return 'Foo'\n\n$structure-\u003eset('parent.child', $value);\n```\n\n### Append \u0026 Prepend\n\nSupport `push / pop / shift / unshift` methods.\n\n``` php\n$structure-\u003eset('foo.bar', array('fisrt', 'second'));\n\n$structure-\u003epush('foo.bar', 'third');\n\n$structure-\u003eget('foo.bar');\n// Result: Array(first, second, third)\n```\n\n### Use other separator\n\n``` php\n$structure-\u003esetSeparator('/');\n\n$data = $structure-\u003eget('foo/bar');\n```\n\n## Accessing a Structure as an Array\n\nThe `Structure` class implements `ArrayAccess` so the properties of the structure can be accessed as an array. Consider the following examples:\n\n``` php\n// Set a value in the structure.\n$structure['foo'] = 'bar';\n\n// Get a value from the structure;\n$value = $structure['foo'];\n\n// Check if a key in the structure is set.\nif (isset($structure['foo']))\n{\n\techo 'Say bar.';\n}\n```\n\n## Merge Structure\n\n#### Using load* methods to merge two config files.\n\n``` php\n$json1 = '{\n    \"field\" : {\n        \"keyA\" : \"valueA\",\n        \"keyB\" : \"valueB\"\n    }\n}';\n\n$json2 = '{\n    \"field\" : {\n        \"keyB\" : \"a new valueB\"\n    }\n}';\n\n$structure-\u003eloadString($json1);\n$structure-\u003eloadString($json2);\n```\n\nOutput\n\n```\nArray(\n    field =\u003e Array(\n        keyA =\u003e valueA\n        keyB =\u003e a new valueB\n    )\n)\n```\n\n#### Merge Another Structure\n\n``` php\n$object1 = '{\n\t\"foo\" : \"foo value\",\n\t\"bar\" : {\n\t\t\"bar1\" : \"bar value 1\",\n\t\t\"bar2\" : \"bar value 2\"\n\t}\n}';\n\n$object2 = '{\n\t\"foo\" : \"foo value\",\n\t\"bar\" : {\n\t\t\"bar2\" : \"new bar value 2\"\n\t}\n}';\n\n$structure1 = new Structure(json_decode($object1));\n$structure2 = new Structure(json_decode($object2));\n\n$structure1-\u003emerge($structure2);\n```\n\nIf you just want to merge first level, do not hope recursive:\n\n``` php\n$structure1-\u003emerge($structure2, false); // Set param 2 to false that Structure will only merge first level\n```\n\nMerge to a child node:\n\n``` php\n$structure-\u003emergeTo('foo.bar', $anotherStructure);\n```\n\n## Dump to file.\n\n``` php\n$structure-\u003etoString();\n\n$structure-\u003etoString('xml');\n\n$structure-\u003etoString('ini');\n```\n\n## Dump to one dimension\n\n``` php\n$array = array(\n    'flower' =\u003e array(\n        'sunflower' =\u003e 'light',\n        'sakura' =\u003e 'samurai'\n    )\n);\n\n$structure = new Structure($array);\n\n// Make data to one dimension\n\n$flatted = $structure-\u003eflatten();\n\nprint_r($flatted);\n```\n\nThe result:\n\n```\nArray\n(\n    [flower.sunflower] =\u003e light\n    [flower.sakura] =\u003e samurai\n)\n```\n\n## Using YAML\n\nAdd Symfony YAML component in `composer.json`\n\n``` json\n{\n\t\"require-dev\": {\n\t\t\"symfony/yaml\": \"^4.0||^5.0\"\n\t}\n}\n```\n\nUsing `yaml` format\n\n``` php\n$structure-\u003eloadFile($yamlFile, 'yaml');\n\n$structure-\u003eloadString('foo: bar', 'yaml');\n\n// Convert to string\n$structure-\u003etoString('yaml');\n```\n\n## StructureHelper\n\n``` php\nuse Windwalker\\Structure\\StructureHelper;\n\nStructureHelper::loadFaile($file, $format); // File to array\nStructureHelper::loadString($string, $format); // String to array\nStructureHelper::toString($array, $format); // Array to string\n\n// Use format class\n$json = StructureHelper::getFormatClass('json'); // Get JsonFormat\n$string = $json::structToString($array);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fstructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindwalker-io%2Fstructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fstructure/lists"}