Download the PHP package diephp/data-object without Composer
On this page you can find all versions of the php package diephp/data-object. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download diephp/data-object
More information about diephp/data-object
Files in diephp/data-object
Package data-object
Short Description Simple object to be used as a DTO/MODEL/ValueObject.
License MIT
Informations about the package data-object
DataObject
Simple object to be used as a DTO/MODEL/ValueObject.
Overview
The DataObject
class is a versatile data container designed for use as a Data Transfer Object (DTO), Model, or ValueObject. It can be initialized with an associative array and provides various methods for manipulating and accessing data. This class implements both the \JsonSerializable
and ArrayAccess
interfaces.
Features
- Initialize with an associative array
- Implements
\JsonSerializable
andArrayAccess
interfaces - Supports dot notation for nested data access
- Provides methods for merging, filtering, mapping, and transforming data
- Automatically converts objects to arrays if they implement a
toArray
method - Various utility methods like
hash
,flatten
,collapse
,clone
, etc.
Installation
Install the package via Composer:
Or manually add it to your composer.json
:
Usage
Initialization
Create a new instance of DataObject
:
Or use the static of
method:
Accessing Data
Access data using property notation or array access:
Check if a key exists:
Manipulating Data
Set a value:
Get a value with a default:
Merge new data:
Filter data:
Map data:
Utility Methods
Convert to array:
Convert to JSON:
Get the MD5 hash of the data:
Clone the object:
Example
License
This project is licensed under the MIT License. See the LICENSE file for details.