Skip to content

pew-pew-team/hydrator-jms

Repository files navigation

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"),
// ]