{"id":20732153,"url":"https://github.com/ailixter/gears-dictionary","last_synced_at":"2025-07-19T11:34:53.504Z","repository":{"id":56942719,"uuid":"157719222","full_name":"ailixter/gears-dictionary","owner":"ailixter","description":"The project, which Gears Dictionary","archived":false,"fork":false,"pushed_at":"2019-08-17T13:57:09.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T10:27:52.160Z","etag":null,"topics":["arrays","data","dictionaries","dictionary","php","struct","utilities"],"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/ailixter.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":"2018-11-15T13:51:16.000Z","updated_at":"2019-08-16T12:26:27.000Z","dependencies_parsed_at":"2022-08-21T07:50:45.143Z","dependency_job_id":null,"html_url":"https://github.com/ailixter/gears-dictionary","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ailixter/gears-dictionary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-dictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-dictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-dictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-dictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ailixter","download_url":"https://codeload.github.com/ailixter/gears-dictionary/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ailixter%2Fgears-dictionary/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265926963,"owners_count":23850886,"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":["arrays","data","dictionaries","dictionary","php","struct","utilities"],"created_at":"2024-11-17T05:18:03.607Z","updated_at":"2025-07-19T11:34:53.474Z","avatar_url":"https://github.com/ailixter.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gears-dictionary\nThe project, which Gears Dictionary\n\n## Flat Dictionary\n\n### use Ailixter\\Gears\\Dictionary\\ReadonlyFlat;\n```php\n\n$readonly = new ReadonlyFlat(['x' =\u003e 123]);\n\nif ($readonly-\u003ehas('x')) {\n    echo $readonly-\u003eget('x'); // 123\n}\necho $readonly-\u003eget('y'); // null\necho $readonly-\u003eget('y', 'notset'); // 'notset'\necho $readonly['y']; // null\necho isset($readonly['x']); // true\necho isset($readonly['y']); // false\nunset($readonly['x']); // AccessException\n```\n\n### use Ailixter\\Gears\\Dictionary\\Flat;\n```php\n$writable = new Flat($readonly-\u003eall());\n\n$writable-\u003eset('x', 456);\n$array = $writable-\u003eset('y', 789)-\u003eremove('x')-\u003eall(); // ['y' =\u003e 789]\necho $writable-\u003ehas('y'); // true\n```\n\n## Structured Dictionary\n\n### use Ailixter\\Gears\\Dictionary\\ReadonlyStruct;\n```php\n$readonly = new ReadonlyStruct([\n    'x' =\u003e [123, 456],\n    'y' =\u003e [\n        'z' =\u003e 789\n    ]\n]);\n\nif ($readonly-\u003ehas('x')) {\n    echo $readonly-\u003eget('x'); // [123, 456]\n}\necho $readonly-\u003eget('x/0'); // 123 \necho $readonly['x/1']; // 456\necho isset($readonly['y/z']); // true\necho isset($readonly['y/z/0']); // false\nunset($readonly['x/0']); // AccessException\n```\n\n### use Ailixter\\Gears\\Dictionary\\Struct;\n```php\n$writable = new Struct($readonly-\u003eall());\n\n$writable-\u003eset('x', 456);\n$writable-\u003ehas('x/0'); // false\n```\n\n```php\n$writable-\u003eadd('x', 456);\n$writable-\u003ehas('x/0'); // true\n$writable-\u003eget('x'); // [456]\n```\n\n## Interfaces\n\n### use Ailixter\\Gears\\Dictionary\\ReadonlyDictionaryInterface;\n```php\nfunction testReadonly (ReadonlyDictionaryInterface $readonly) {\n    return $readonly-\u003eget('param');\n}\n\ntestReadonly(new ReadonlyFlat($_POST)) === testReadonly(new Struct($_POST)); // true\n```\n\n### use Ailixter\\Gears\\Dictionary\\DictionaryInterface;\n```php\nfunction testWritable (DictionaryInterface $writable, $key) {\n    return $writable-\u003eset($key, 123)-\u003eget($key);\n}\n\ntestWritable(new Flat($_POST), 'param') === testWritable(new Struct($_POST), 'data/0'); // true\n```\n\n## DictionaryExtraInterface\n\n### use extracting:\n```php\n$writable-\u003ehas('x'); // true\necho $writable-\u003eextract('x'); // [456]\n$writable-\u003ehas('x'); // false\n```\n\n### use references:\n```php\n$writable = new Flat;\n$var =\u0026 $writable-\u003eref('x');\n$writable-\u003eset('x', 123);\necho $var; // 123\n```\n\n```php\n$writable = new Struct;\n$var = 123;\n$writable-\u003esetref('x/0', $var);\n$var = 456;\necho $writable-\u003eget['x']; // [456]\n```\n\n```php\n(new Struct)-\u003erefer($_GET)-\u003eset('p/route', 'chapter/1');\necho $_GET['p']; // ['route' =\u003e 'chapter/1']\n```\n\n## Howtos\n\n### Struct: use custom path separator\n```php\necho new Struct(['x' =\u003e [123, 456])-\u003esetPathSeparator('.')-\u003eget('x.0'); // 123\n```\n\n### Struct: export data\n```php\nfunction export($dbRecord, $map) {\n    $jsonData = new Struct;\n    foreach ($map as $dst =\u003e $src) {\n        $jsonData[$dst] = $dbRecord[$src];\n    }\n    return $jsonData;\n}\n\n$jsonData = export(new Struct($dbRecord), [\n    'record_id'       =\u003e 'id',\n    'contacts/email'  =\u003e 'email',\n    'contacts/phone'  =\u003e 'phone',\n    'logo_url'        =\u003e 'images/url/0'\n]);\necho json_encode($jsonData-\u003eall());\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failixter%2Fgears-dictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Failixter%2Fgears-dictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Failixter%2Fgears-dictionary/lists"}