Download the PHP package bernard/normalt without Composer
On this page you can find all versions of the php package bernard/normalt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bernard/normalt
More information about bernard/normalt
Files in bernard/normalt
Package normalt
Short Description Normalt is a extension to Symfony Serializer that only implements the Normalization part
License MIT
Informations about the package normalt
Normalt
Normalt contains additional normalizers for use with the serializer component found in Symfony. It also implements a normalizer delegator that will look at the data you want normalized and/or denormalized and call the normalizer which supports it.
In the context of Normalt normalization is the act of converting an object into an array. Denormalization is the opposite direction (converting array into an object). This is to my knowledge the same concept Symfony serializer uses.
Table of Contents
- Getting Started
- Normalizers
- AggregateNormalizer
- DoctrineNormalizer
- RecursiveReflectionNormalizer
- License
Getting Started
Getting started is as easy as requiring the library with composer.
Normalizers
Theese normalizers can be used with the serializer component directly or through the AggregateNormalizer
.
AggregateNormalizer
AggregateNormalizer
is a delegator and aggregator as it aggregates multiple normalizers and denormalizers
which it will delegate the process to.
It have a list of normalizers and denormalizers. It will ask each of theese if they support the data/object and use the first found.
It implements a subset of the full serializer and its only focus is normalizing to arrays and
denormalize arrays into objects. This lets you focus on normalization instead of converting
into a specific format such as xml
, json
etc.
Usage
You need to instantiate the normalizer and the list of normalizer/denormalizers you want to use.
For this example we use GetSetMethodNormalizer
which is distributed with the symfony package.
This is the class we are going to use. GetSetMethodNormalizer
uses getters and setters to do
its job.
Lets normalize and denormalize it again.
In contrast to the other normalizers in this package, it does not make sense to use this with the serializer as the Serializer already does most of the functionality already.
DoctrineNormalizer
DoctrineNormalizer
normalizes mapped objects (Entities, Documents etc.) into arrays and back again.
It usage is very simple. The following example assume a mapped object of $user
and that you are
using the doctrine orm (other doctrine projects work aswell!).
RecursiveReflectionNormalizer
This normalizes also delegates like the AggregateNormalizer
, but delegates for each property in the object
you are normalizing to normalize. It does this with recursion, so if a normalizer does not support a given
property and is an array it will loop through that array and look for more objects.
The same thing happens when denormalizing, except it will try and find a supporting denormalizer for the property structure before looping.
Using is simple as the other, the example utilises DoctrineNormalizer
and assumes we have a $profile
object
that contains a reference to a user with $profile->user
.
License
Please refer to the included LICENSE
file.