pew-pew/hydrator-jms

JMS serializer hydrator bridge

0.2.0 2024-03-26 22:05 UTC

This package is auto-updated.

Last update: 2024-11-26 23:39:54 UTC


README

PHP 8.3+ Latest Stable Version Latest Unstable Version License MIT

JMS Hydrator Bridge

A set of interfaces for mapping arbitrary values to their typed equivalents and their inverses using the JMS (jms/serializer) package.

Installation

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.

Usage

Simple hydrator creation:

$jms = PewPew\Hydrator\JMS\Builder::create();

Hydrator

$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

$extractor = PewPew\Hydrator\JMS\Builder::create()
    ->createExtractor();

$data = $extractor->extract(new ExampleDTO(
    id: 42,
    name: 'Vasya',
));

// array(2) [
//   id => int(42),
//   name => string("Vasya"),
// ]