chriha / data-objects
A PHP package to create immutable data objects with validation and transformation capabilities.
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/chriha/data-objects
Requires
- php: ^8.3
- illuminate/collections: ^11.46|^12.26
- illuminate/support: ^11.46|^12.26
- illuminate/translation: ^11.46|^12.26
- illuminate/validation: ^11.46|^12.26
- nesbot/carbon: ^3.8.4
Requires (Dev)
- laravel/pint: ^1.24
- pestphp/pest: ^4.0
- symfony/var-dumper: ^7.3
README
A PHP project for working with flexible data objects, supporting dynamic properties and array initialization.
Features
- Dynamic Properties: Easily set and get properties on data objects.
- Array Initialization: Instantiate objects with an associative array of properties.
- Extensible: Create your own data object classes by extending the base
DataObject.
Example Usage
use ClipMyHorseTV\DataObject; use ClipMyHorseTV\DataObjects\Attributes\MapFrom; class Person extends DataObject { #[MapFrom('name_attr')] public string $name; public int $age; } $person = Person::from(['name_attr' => 'Alice', 'age' => 30]); echo $person->name; // Alice echo $person->age; // 30
Running Tests
This project uses PestPHP for testing.
To run the tests:
composer install ./vendor/bin/pest
Directory Structure
src/- Source code for data objectstests/- PestPHP test suite
Requirements
- PHP 8.3+
- Composer
License
MIT