PHPackages                             paysera/lib-normalization - 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

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

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

Library for normalizing and denormalizing PHP objects to and from JSON structures

1.3.1(1y ago)018.6k42MITPHPPHP ^7.0 || ^8.0CI failing

Since Feb 25Pushed 1y ago2 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (12)Used By (2)

Normalization library
=====================

[](#normalization-library)

[![Build Status](https://github.com/paysera/lib-normalization/workflows/CI/badge.svg)](https://github.com/paysera/lib-normalization/actions)[![Coverage Status](https://camo.githubusercontent.com/ab24f33a31a3035975df5a3d36b01695ddb24164843d42dfbed2c96e6d7b9aa7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f706179736572612f6c69622d6e6f726d616c697a6174696f6e2e737667)](https://scrutinizer-ci.com/g/paysera/lib-normalization/code-structure)[![Quality Score](https://camo.githubusercontent.com/d5edb1bb90ee272677bd680c11cfc0fb4759ea6de75485a26cd007578fb23228/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706179736572612f6c69622d6e6f726d616c697a6174696f6e2e737667)](https://scrutinizer-ci.com/g/paysera/lib-normalization)[![Total Downloads](https://camo.githubusercontent.com/e7ffff560fef23d87cf60b3d7f5e07d6b0f3755a9981382661b8e8a25acece11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706179736572612f6c69622d6e6f726d616c697a6174696f6e2e737667)](https://packagist.org/packages/paysera/lib-normalization)[![Latest Stable Version](https://camo.githubusercontent.com/ea73dc2afb248058e5ddeb22a0d14ee738c814556df57e3e6d0022df9e71a881/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706179736572612f6c69622d6e6f726d616c697a6174696f6e2e737667)](https://packagist.org/packages/paysera/lib-normalization)[![PHP Version Require](https://camo.githubusercontent.com/62166c826dbd47ebd006130759741c738b3f3caf9868c12dcd2085984d494c15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f706179736572612f6c69622d6e6f726d616c697a6174696f6e2f706870)](https://packagist.org/packages/paysera/lib-normalization)[![License](https://camo.githubusercontent.com/c9c82f84291e799037bbd41ab46b3e6061ae7cbe3061e264f998074b5a79e96a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706179736572612f6c69622d6e6f726d616c697a6174696f6e3f636f6c6f723d626c7565)](LICENSE)

This library 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.

If you intend to use the library with Symfony, use [lib-normalization-bundle](https://github.com/paysera/lib-normalization-bundle) instead.

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 library:

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

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

Write de/normalizers for your business entities:

```
