yadddl / serializer
Yet another Serializer library
Requires
- php: ^8.0|^8.1
- symfony/property-access: ^4.4|^5.3|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.0
- psalm/plugin-phpunit: ^0.16.1
- vimeo/psalm: ^4.0
- yadddl/value-object: ^0.5
Suggests
- yadddl/value-object: If you need a ready to use primitive objects
This package is auto-updated.
Last update: 2024-11-09 17:45:42 UTC
README
by Yet Another DDD Library (YADDDL)
This library implements a serializer, and it follows those rules:
-
Do not use extra metadata: the PHP language is expressive enough to give you everything you need.
-
Convention over configuration: just configure what differ from the standard use case, that already cover the majority of the cases.
It goes in-pair with the Value Object project of the same family, but could be used alone. Just be sure to follow the conventions!
It doesn't cover all the possibile use cases, then use it if you want, or contribute if you like what we are doing and want to expand it.
Usage
composer require yadddl/serializer
Getting started
Given a simple DTO
class SillyDTO { public function __construct( private string $propertyOne, private int $propertyTwo, private string $hiddenProperty ) {} public function getPropertyOne(): string { return $this->propertyOne; } public function getPropertyTwo(): int { return $this->propertyTwo; } }
The easy way to serialize it is this one
use Yadddl\Serializer\Factory\SerializerBaseFactory; // Fastest way to create a basic serializer $serializer = SerializerBaseFactory::make(); $dto = new SillyDTO('one', 2, 'hidden'); $data = $serializer->serialize($dto); echo json_encode($data, JSON_PRETTY_PRINT);
And the resulting json
{ "propertyOne": "one", "propertyTwo": 2 }