Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pew-pew-team/hydrator-jms

JMS Serializer Hydrator Bridge
https://github.com/pew-pew-team/hydrator-jms

adapter bridge deserialization hydrator jms jms-serializer mapper serialization

Last synced: 21 days ago
JSON representation

JMS Serializer Hydrator Bridge

Awesome Lists containing this project

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)](https://jmsyst.com/libs/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:

```bash
$ composer require pew-pew/hydrator-jms
```

More detailed installation [instructions are here](https://getcomposer.org/doc/01-basic-usage.md).

## Usage

Simple hydrator creation:

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

### Hydrator

```php
$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

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

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

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