Download the PHP package devuri/dot-access without Composer
On this page you can find all versions of the php package devuri/dot-access. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devuri/dot-access
More information about devuri/dot-access
Files in devuri/dot-access
Package dot-access
Short Description A simple PHP library for accessing nested data using dot notation.
License MIT
Informations about the package dot-access
DotAccess - Convenient Access to Nested Data Using Dot Notation
The 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.
Installation
- Ensure you have Composer installed on your system.
- Run the following command to install the package:
Getting Started
-
Include the
DotAccess
class in your PHP script: - Create an instance of the
DotAccess
class and pass the nested data (array or object) to the constructor:
Accessing Data
The DotAccess
class provides the following methods to access the nested data using dot notation:
Get the Value
Use the get()
method to retrieve the value associated with a dot notation key:
Set the Value
Use the set()
method to set a value for a dot notation key:
Checking for Key Existence
Use the has()
method to check if a dot notation key exists in the data:
Removing a Key
Use the remove()
method to unset the value associated with a dot notation key:
Example
Wrapper Function - DataKey:get()
In addition to the DotAccess
class, we also provide a standalone wrapper function DataKey
that simplifies accessing nested data using dot notation.
Usage
The DataKey:get()
function allows you to quickly access nested data without having to create an instance of the DotAccess
class. It takes three parameters:
- The data array or object to access.
- The dot notation key to access the data.
- An optional default value to return if the key is not found.
Here's how you can use the DataKey:get()
function:
When to Use DataKey:get()
vs. DotAccess
Both 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.
Use DataKey:get()
when:
- You prefer a simple function call over creating an instance of the
DotAccess
class. - You only need to access nested data at a few specific points in your code.
- You don't need to perform multiple operations (e.g., setting, checking, or removing keys).
Use DotAccess
class when:
- You need to perform multiple operations on the same nested data within your code.
- You prefer an object-oriented approach for handling nested data.
- You need better encapsulation and separation of concerns in your code.
Both 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.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
The 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.