PHPackages                             kairos-project/api-normalizer - 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. [API Development](/categories/api)
4. /
5. kairos-project/api-normalizer

ActiveLibrary[API Development](/categories/api)

kairos-project/api-normalizer
=============================

A data normalizer listener to be attached to ApiController events

05PHP

Since Aug 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kairosProject/ApiNormalizer)[ Packagist](https://packagist.org/packages/kairos-project/api-normalizer)[ RSS](/packages/kairos-project-api-normalizer/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

ApiNormalizer
=============

[](#apinormalizer)

A data normalizer listener to be attached to ApiController events

1) Subject
----------

[](#1--subject)

The normalizer part of the API is in charge of the object transformation before the response formatting.

This normalization allows the formatting process to use a regular array type instead of a set of objects.

2) Class architecture
---------------------

[](#2-class-architecture)

The API normalizer is a pure decorator class for more powerful existing normalizer. The choice to use the Symfony serializer was made to allow context configuration and advanced group usage in securitizing output.

3) Dependency description and use into the element
--------------------------------------------------

[](#3-dependency-description-and-use-into-the-element)

A the time of writing, the normalizer is designed to have four production dependencies as:

- psr/log
- symfony/event-dispatcher
- kairos-project/api-loader
- symfony/serializer

### 3.1) psr/log

[](#31-psrlog)

The debugging and error retracement in each project parts is currently a fundamental law in development and it's missing is part of the OWASP top ten threats.

As defined by the third PHP standard reference, the logger components have to implement a specific interface. By the way, the logging system will be usable by each existing frameworks.

### 3.2) symfony/event-dispatcher

[](#32-symfonyevent-dispatcher)

The normalizing system is designed to be easily extendable and will implement an event dispatching system, allowing the attachment and separation of logic by priority.

### 3.3) kairos-project/api-loader

[](#33-kairos-projectapi-loader)

The normalizer is made to be used by APIs and the generic system into kairos project is the API controller. Even, the system needs access to the API loader constants. This Loader makes use of the API controller itself.

### 3.4) symfony/serializer

[](#34-symfonyserializer)

The normalization logic can become hard to implement if we want to offer a generic interface. The Symfony serializer will be used to bypass this difficulty.

4) Implementation specification
-------------------------------

[](#4-implementation-specification)

The normalizer component will provide a unique method to normalize, that process the normalization.

The configuration of the component will be part of the instantiation arguments.

A normalizing event will be created to store the process event, the data, and the context.

#### 4.1) Dependency injection specification

[](#41-dependency-injection-specification)

The processing logic will need a normalizer instance, a parameter key to retrieve the elements to normalize and another one to store the result. The parameter key will be the API loader's one by default.

A default context will be provided to allow normalization settings, such as grouping.

Additionally, two event names will be injected to define the dispatched events.

#### 4.2) normalize algorithm

[](#42-normalize-algorithm)

The normalize method is in charge of the data normalization.

```
We assume to receive the process event from the parameters.
We assume the process event parameter key to be part of the attributes.

Get the data to normalize from the process event, using the parameter key.
Create a distinct normalizer event. This element encloses the data to be normalized, the normalizer context, and the initial one.

Dispatch the before normalizing event.
Normalize the data and replace the normalize event content.
Dispatch the after normalizing event.

Set a new parameter into the process event to store the normalized data.
```

5) Usage
--------

[](#5-usage)

The symfony/property-access is needed to use ObjectNormalizer, and sensio/framework-extra-bundle required for annotation grouping.

#### 5.1) Basic usage

[](#51-basic-usage)

```
use KairosProject\ApiNormalizer\Normalizer\Normalizer;
use KairosProject\ApiLoader\Loader\AbstractApiLoader;
use KairosProject\ApiController\Event\ProcessEvent;

$normalizer = new Normalizer(
    $logger,
    $objectNormalizer
);

$processEvent = new ProcessEvent();
$processEvent->setParameter(AbstractApiLoader::EVENT_KEY_STORAGE, $data);

$dispatcher->addListener('event', [$normalizer, 'normalize']);
$dispatcher->dispatch('event', $processEvent);

$normalizedData = $processEvent->getParameter(Normalizer::NORMALIZED_DATA);
```

#### 5.1) With property grouping

[](#51-with-property-grouping)

```
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;

AnnotationRegistry::registerLoader('class_exists');
$objectNormalizer = new ObjectNormalizer(
   new ClassMetadataFactory(
       new AnnotationLoader(
           new AnnotationReader()
       )
   )
);

$normalizer = new Normalizer(
   $logger,
   $objectNormalizer,
   ['groups' => ['output_group']]
);
```

#### 5.1) Complete constructor

[](#51-complete-constructor)

```
public function __construct(
   LoggerInterface $logger,
   NormalizerInterface $normalizer,
   array $context = [],
   string $inputParameter = AbstractApiLoader::EVENT_KEY_STORAGE,
   string $outputParameter = Normalizer::NORMALIZED_DATA,
   string $beforeNormalizeEvent = Normalizer::EVENT_BEFORE,
   string $afterNormalizerEvent = Normalizer::EVENT_AFTER
);
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12436206?v=4)[cscfa](/maintainers/cscfa)[@cscfa](https://github.com/cscfa)

---

Top Contributors

[![matthieu88160](https://avatars.githubusercontent.com/u/11874266?v=4)](https://github.com/matthieu88160 "matthieu88160 (4 commits)")

### Embed Badge

![Health badge](/badges/kairos-project-api-normalizer/health.svg)

```
[![Health](https://phpackages.com/badges/kairos-project-api-normalizer/health.svg)](https://phpackages.com/packages/kairos-project-api-normalizer)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
