Download the PHP package paysera/lib-normalization-bundle without Composer

On this page you can find all versions of the php package paysera/lib-normalization-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lib-normalization-bundle

Paysera Normalization Bundle

Latest Version on Packagist Build Status Coverage Status Quality Score Total Downloads

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?

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:

Installation

Configuration

Basic usage

Write de/normalizers for your business entities:

If you don't use auto-configuration (also keep in mind that it works only when you implement TypeAwareInterface), tag your services:

Use for de/normalization:

Advanced usage

Available tags

Tag Description Available attributes Required interface
paysera_normalization.normalizer Registers service as normalizer type, group NormalizerInterface
paysera_normalization.object_denormalizer Registers service as object denormalizer type, group ObjectDenormalizerInterface
paysera_normalization.mixed_type_denormalizer Registers service as mixed type denormalizer type, group MixedTypeDenormalizerInterface
paysera_normalization.autoconfigured_normalizer Registers service depending on implemented interfaces group TypeAwareInterface

If service does not implement TypeAwareInterface interface, type attribute is required. You can provide it in any case to overwrite any value returned from getType method.

group attribute instructs to register de/normalizer to specific normalization group instead of default one. See usage on normalization groups below for more information.

You can use several (even same) tags on a service. For example:

Normalizing data

Normalization is a process of converting your business objects to "normalized" (plain) structures.

This can be done when returning them as response to REST requests, before sending to some MQ system, before storing to any relational or NoSQL database or in any other case where you need plain, manageable representation.

Normalization is initiated by using CoreNormalizer (paysera_normalization.core_normalizer service) normalize method which has the following interface:

If $type is not passed, code tries to find registered normalizer in this order:

With NormalizationContext you can customize normalization group and included fields. Keep in mind that NormalizationContext needs the same CoreNormalizer instance when constructing it – it's passed down to concrete normalizer instances which needs easy way to recursively normalize internal structures.

Included fields

You can configure an array of fields to be included in the normalized result.

* means all (default) fields of the object.

You can use . to indicate sub-elements, for example user.address or user.*.

Included fields are used in two separate places:

Using this structure, following table shows what structure would be returned with different field configurations.

Included fields Returned structure
Default {"email": ..., "residence_address": ...}
['*'] {"email": ..., "residence_address": ...}
['email'] {"email": ...}
['shipping_addesses'] {"shipping_addesses": ...}
['*', 'shipping_addesses'] {"email": ..., "residence_address": ..., "shipping_addesses": ...}

Usually optimizations make sense only when you make some remote calls to fetch the data or at least make any additional database calls. In this example this can be the case if Doctrine did not load the data by relation beforehand.

Denormalizing data

Denormalization is a process of converting "normalized" (plain) structures to your business objects.

This can be done when receiving JSON via some endpoint, getting the structure from MQ, database or in any other case where you want to read the normalized structure.

Normalization is initiated by using CoreDenormalizer (paysera_normalization.core_denormalizer service) denormalize method which has the following interface:

Type is required here as there's nothing to guess it from.

You can configure normalization group to use with DenormalizationContext. Same as with normalization process, make sure you pass the same CoreDenormalizer to your structured DenormalizationContext:

Registered denormalizers have one of 2 interfaces (but never both):

Normalization groups

Each de/normalizer can belong to some concrete normalization group. De/normalizers, registered without group attribute, belong to default group – this means that they are always used as a fallback.

When using customised normalization group, de/normalizer is looked for in the following algorithm:

This allows to easily overwrite logic for concrete normalizers, but also have the default behavior in most common use-cases.

Semantic versioning

This bundle follows semantic versioning.

Public API of this bundle (in other words, you should only use these features if you want to easily update to new versions):

See Symfony BC rules for basic information about what can be changed and what not in the API.

Running tests

Contributing

Feel free to create issues and give pull requests.

You can fix any code style issues using this command:


All versions of lib-normalization-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0 || ^8.0
paysera/lib-normalization Version ^1.2
symfony/framework-bundle Version ^3.4.26|^4.2.7|^5.4|^6.0
paysera/lib-dependency-injection Version ^1.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paysera/lib-normalization-bundle contains the following files

Loading the files please wait ....