zero-to-prod / transformable
Transform a class into different types.
v71.0.4
2024-09-04 10:53 UTC
Requires
- php: >=7.1.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^7.0
Suggests
- zero-to-prod/data-model: Transform data into a class.
README
Transform a class into different types.
Installation
You can install the package via Composer:
composer require zerotoprod/transformable
Methods
toArray(): array
Converts the object’s properties into an associative array.toJson(): string
Converts the object’s properties into a JSON string.
Usage
To use the Zerotoprod\Transformable\Transformable
trait in your class, simply include it:
use Zerotoprod\Transformable\Transformable; class YourDataModel { use Transformable; public $name; public $email; } $model = new YourDataModel(); $model->name = 'John Doe'; $model->email = 'john.doe@example.com'; $array = $model->toArray(); $json = $model->toJson();