{"id":15509073,"url":"https://github.com/devuri/dot-access","last_synced_at":"2025-03-22T17:15:03.427Z","repository":{"id":184734269,"uuid":"672395518","full_name":"devuri/dot-access","owner":"devuri","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-28T20:56:07.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-29T14:03:10.510Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devuri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-29T23:53:52.000Z","updated_at":"2023-09-23T05:02:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"34e6a9dc-8645-49b0-8216-f856513d37d4","html_url":"https://github.com/devuri/dot-access","commit_stats":null,"previous_names":["devuri/dot-access"],"tags_count":3,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devuri%2Fdot-access","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devuri%2Fdot-access/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devuri%2Fdot-access/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devuri%2Fdot-access/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devuri","download_url":"https://codeload.github.com/devuri/dot-access/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244991175,"owners_count":20543627,"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-02T09:41:18.276Z","updated_at":"2025-03-22T17:15:03.391Z","avatar_url":"https://github.com/devuri.png","language":"PHP","readme":"# DotAccess - Convenient Access to Nested Data Using Dot Notation\n\nThe `DotAccess` class provides a user-friendly wrapper around the functionality of the `Dflydev\\DotAccessData\\Data` package, allowing easy access to nested data using dot notation in PHP.\n\n## Installation\n\n1. Ensure you have [Composer](https://getcomposer.org/) installed on your system.\n2. Run the following command to install the package:\n\n```bash\ncomposer require devuri/dot-access\n```\n\n## Getting Started\n\n1. Include the `DotAccess` class in your PHP script:\n\n```php\n\nuse Urisoft\\DotAccess;\n\n```\n\n2. Create an instance of the `DotAccess` class and pass the nested data (array or object) to the constructor:\n\n```php\n$data = [\n    'user' =\u003e [\n        'name' =\u003e 'John Doe',\n        'email' =\u003e 'john.doe@example.com',\n        'address' =\u003e [\n            'city' =\u003e 'New York',\n            'country' =\u003e 'USA',\n        ],\n    ],\n];\n\n$dotdata = new DotAccess($data);\n```\n\n## Accessing Data\n\nThe `DotAccess` class provides the following methods to access the nested data using dot notation:\n\n### Get the Value\n\nUse the `get()` method to retrieve the value associated with a dot notation key:\n\n```php\n$name = $dotdata-\u003eget('user.name');\n$email = $dotdata-\u003eget('user.email');\n$city = $dotdata-\u003eget('user.address.city');\n```\n\n### Set the Value\n\nUse the `set()` method to set a value for a dot notation key:\n\n```php\n$dotdata-\u003eset('user.age', 30);\n```\n\n### Checking for Key Existence\n\nUse the `has()` method to check if a dot notation key exists in the data:\n\n```php\n$emailExists = $dotdata-\u003ehas('user.email');\n```\n\n### Removing a Key\n\nUse the `remove()` method to unset the value associated with a dot notation key:\n\n```php\n$dotdata-\u003eremove('user.address.country');\n```\n\n## Example\n\n```php\n$data = [\n    'user' =\u003e [\n        'name' =\u003e 'John Doe',\n        'email' =\u003e 'john.doe@example.com',\n        'address' =\u003e [\n            'city' =\u003e 'New York',\n            'country' =\u003e 'USA',\n        ],\n    ],\n];\n\n$dotdata = new DotAccess($data);\n\n$name = $dotdata-\u003eget('user.name'); // Output: \"John Doe\"\n$dotdata-\u003eset('user.age', 30);\n$emailExists = $dotdata-\u003ehas('user.email'); // Output: true\n$dotdata-\u003eremove('user.address.country');\n\necho \"Name: $name\\n\";\necho \"Age: \" . $dotdata-\u003eget('user.age') . \"\\n\";\necho \"Email exists: \" . ($emailExists ? 'Yes' : 'No') . \"\\n\";\n```\n\n## Wrapper Function - DataKey:get()\n\nIn addition to the `DotAccess` class, we also provide a standalone wrapper function `DataKey` that simplifies accessing nested data using dot notation.\n\n### Usage\n\nThe `DataKey:get()` function allows you to quickly access nested data without having to create an instance of the `DotAccess` class. It takes three parameters:\n\n1. The data array or object to access.\n2. The dot notation key to access the data.\n3. An optional default value to return if the key is not found.\n\nHere's how you can use the `DataKey:get()` function:\n\n```php\n$data = [\n    'user' =\u003e [\n        'name' =\u003e 'John Doe',\n        'email' =\u003e 'john.doe@example.com',\n        'address' =\u003e [\n            'city' =\u003e 'New York',\n            'country' =\u003e 'USA',\n        ],\n    ],\n];\n\n// Using the wrapper function\n$name = DataKey:get($data, 'user.name');\n$email = DataKey:get($data, 'user.email');\n$city = DataKey:get($data, 'user.address.city');\n$zipCode = DataKey:get($data, 'user.address.zip_code', 'N/A'); // Provide a default value if the key doesn't exist\n\necho \"Name: $name\\n\";\necho \"Email: $email\\n\";\necho \"City: $city\\n\";\necho \"Zip Code: $zipCode\\n\";\n```\n\n### When to Use `DataKey:get()` vs. `DotAccess`\n\nBoth the `DataKey:get()` function and the `DotAccess` class serve the same purpose: accessing nested data using dot notation. The choice between them depends on your specific use case and coding preferences.\n\nUse `DataKey:get()` when:\n\n- You prefer a simple function call over creating an instance of the `DotAccess` class.\n- You only need to access nested data at a few specific points in your code.\n- You don't need to perform multiple operations (e.g., setting, checking, or removing keys).\n\nUse `DotAccess` class when:\n\n- You need to perform multiple operations on the same nested data within your code.\n- You prefer an object-oriented approach for handling nested data.\n- You need better encapsulation and separation of concerns in your code.\n\nBoth approaches provide a convenient and user-friendly way to work with nested data using dot notation. Choose the one that best fits your coding style and requirements.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nThe `DotAccess` class is a simple wrapper around the `Dflydev\\DotAccessData\\Data` package, which provides the core functionality for accessing nested data using dot notation. Special thanks to the authors of the `Dflydev\\DotAccessData` package for their excellent work.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevuri%2Fdot-access","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevuri%2Fdot-access","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevuri%2Fdot-access/lists"}