chriha/data-objects

A PHP package to create immutable data objects with validation and transformation capabilities.

v1.0.1 2025-09-16 13:49 UTC

This package is auto-updated.

Last update: 2025-09-16 13:56:51 UTC


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 objects
  • tests/ - PestPHP test suite

Requirements

  • PHP 8.3+
  • Composer

License

MIT