PHPackages                             paysera/lib-normalization-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. paysera/lib-normalization-bundle

ActiveSymfony-bundle[Parsing &amp; Serialization](/categories/parsing)

paysera/lib-normalization-bundle
================================

De/normalize business objects without tightly coupling them to your normalization format

1.3.1(1y ago)017.8k6[2 PRs](https://github.com/paysera/lib-normalization-bundle/pulls)1MITPHPPHP ^7.0 || ^8.0CI failing

Since Feb 25Pushed 1y ago2 watchersCompare

[ Source](https://github.com/paysera/lib-normalization-bundle)[ Packagist](https://packagist.org/packages/paysera/lib-normalization-bundle)[ RSS](/packages/paysera-lib-normalization-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (7)Versions (11)Used By (1)

Paysera Normalization Bundle
============================

[](#paysera-normalization-bundle)

[![Build Status](https://github.com/paysera/lib-normalization-bundle/workflows/CI/badge.svg)](https://github.com/paysera/lib-normalization-bundle/actions)[![Coverage Status](https://camo.githubusercontent.com/81e6690e9bed860aed7327b937c50daaf980f58b5b8b580ebc6480592d78dde2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c652e737667)](https://scrutinizer-ci.com/g/paysera/lib-normalization-bundle/code-structure)[![Quality Score](https://camo.githubusercontent.com/6e1fc2576d29927495669b1dc229a0022255752ca6636712718b27f8f86abcdf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c652e737667)](https://scrutinizer-ci.com/g/paysera/lib-normalization-bundle)[![Total Downloads](https://camo.githubusercontent.com/ac00466808f83d8043f819b28840b013015bf2c28523593072b2d84d205e68f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c652e737667)](https://packagist.org/packages/paysera/lib-normalization-bundle)[![Latest Stable Version](https://camo.githubusercontent.com/ef8c59292fbb23927d59f58511df45a25d9fee1b6eb7f699e4788a78660f35de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c652e737667)](https://packagist.org/packages/paysera/lib-normalization-bundle)[![PHP Version Require](https://camo.githubusercontent.com/ce246c98717a0b111414ddb486c691bc200b43f68f6928e7656006ef561f6be4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c652f706870)](https://packagist.org/packages/paysera/lib-normalization-bundle)[![License](https://camo.githubusercontent.com/eba71b168669aee063b88c54fca4700d51bf97939a924da8fd0043307e29ba51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706179736572612f6c69622d6e6f726d616c697a6174696f6e2d62756e646c653f636f6c6f723d626c7565)](LICENSE)

This bundle allows to de/normalize your business entities (plain PHP objects) without tightly coupling them with your normalization format. You would usually do this before converting normalized structure to JSON or after converting from it.

Why?
----

[](#why)

Symfony has Serializer component that has normalizers as a part of it. This component is created for similar reasons but with different approach.

Symfony component exposes your business entities by default, but allows sophisticated but challenging configuration options. It also writing custom normalization logic, but it usually resides inside your normalized classes (which probably are plain PHP objects).

Paysera Normalization library embraces simplicity by always writing a bit of code for getting full control of the situation – normalization logic is placed in related classes, which are usually registered from DIC. This allows to use other services, fetch data from database, call remote services if needed or make any other things in familiar PHP source code. You can easily rename any fields, use any custom naming, duplicate some data for backward compatibility or, well, just write any other code. No difficult configuration is needed for edge-cases, as you have full control over the situation.

Main features of this bundle:

- supports explicit type safety when denormalizing by integrating [lib-object-wrapper](https://github.com/paysera/lib-object-wrapper);
- normalization type can be guessed by passed data;
- easily reuse other de/normalizers without direct dependencies;
- supports different normalization groups with fallback to default one;
- supports explicitly or implicitly included fields, allowing performance tuning in normalization process.

Installation
------------

[](#installation)

```
composer require paysera/lib-normalization-bundle
```

Configuration
-------------

[](#configuration)

```
paysera_normalization:
  register_normalizers:
    date_time:      # registers de/normalizers for DateTime, DateTimeImmutable and DateTimeInterface
      format: "U"   # Unix timestamp. Use any from https://www.php.net/manual/en/function.date.php
```

Basic usage
-----------

[](#basic-usage)

Write de/normalizers for your business entities:

```
