A set of interfaces for mapping arbitrary values to their typed equivalents and their inverses using the JMS (jms/serializer) package.
PewPew JMS Hydrator is available as Composer repository and can be installed using the following command in a root of your project:
$ composer require pew-pew/hydrator-jms
More detailed installation instructions are here.
Simple hydrator creation:
$jms = PewPew\Hydrator\JMS\Builder::create();
$hydrator = PewPew\Hydrator\JMS\Builder::create()
->createHydrator();
$dto = $hydrator->hydrate(ExampleDTO::class, [
'id' => 42,
'name' => 'Vasya',
]);
// object(ExampleDTO) {
// id: int(42),
// name: string("Vasya"),
// }
$extractor = PewPew\Hydrator\JMS\Builder::create()
->createExtractor();
$data = $extractor->extract(new ExampleDTO(
id: 42,
name: 'Vasya',
));
// array(2) [
// id => int(42),
// name => string("Vasya"),
// ]