PHPackages                             seblegall/api-validator-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. seblegall/api-validator-bundle

ActiveLibrary

seblegall/api-validator-bundle
==============================

v0.1.0(9y ago)65.3kMITPHP

Since Jun 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/seblegall/api-validator-bundle)[ Packagist](https://packagist.org/packages/seblegall/api-validator-bundle)[ Docs](https://github.com/seblegall/api-validator-bundle)[ RSS](/packages/seblegall-api-validator-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Api Validator Bundle
====================

[](#api-validator-bundle)

[![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/seblegall/api-validator-bundle/master/LICENSE.md) [![Build Status](https://camo.githubusercontent.com/a89ce279aab34acf0d7c5dd624a6b2df76590bd298fd055f2d0e3fcd4a7ed3ce/68747470733a2f2f7472617669732d63692e6f72672f7365626c6567616c6c2f6170692d76616c696461746f722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/seblegall/api-validator-bundle) [![Code Coverage](https://camo.githubusercontent.com/f40d9445bb242462d3d9ea771dccc4f779706b3f86fdbe235455084ca0547aa2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7365626c6567616c6c2f6170692d76616c696461746f722d62756e646c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/seblegall/api-validator-bundle/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/bfb6a9aac92bb256d650248b0c342c87683655b0ddfd72b920fb4397d599e528/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7365626c6567616c6c2f6170692d76616c696461746f722d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/seblegall/api-validator-bundle/?branch=master)

A Symfony's parameters bag based data validation bundle.

Requirements
------------

[](#requirements)

- PHP &gt; 5.3
- Symfony &gt; 2.4
- Composer

How it works
------------

[](#how-it-works)

REST is great. But, most of the time, it is quite hard to think your WebServices architecture in a way that each WS is stateless. Here is an example.

If you have to design a personal data form and wish to ask the user to complete some fields such as the `name`, the `firstname`, the `birthdate`, and two addresses with, for each, an `addresse`, a `city`, a `zipcode`, and a `country`.

In that case, your database model will probably looks like that :

useruser\_addressaddressid\_userid\_userid\_adressnameid\_addressaddressfirstnamecitybirthdatezipcodecountryNow, if you would like to strictly use REST standards, you will probably expose 2 WS :

- One that POST a user
- One that POST an address

And then, for each, hydrate your objects, check some rules such as the name is only composed of letters using the Validator Symfony Component. Here is an example :

```
$user = new User();
$user->setName($request->get('name'))

$errors = $this->validator->validate($user);
if($errors) {
  //...
}
```

However, most of the time, this is probably not what you'll do. There are some reasons why :

- Making at least 3 calls to post a simple form could be a bad idea if you wish to improve performances
- That way, it will be quite difficult to check, for example, that the 2 required addresses are different. (You will probably have to post the first one and then check the DB to compare with the second one)
- Some of your WS will be stateless but won't make any sens as a domain.

A common way to avoid such problems is using the Symfony Form Builder in the API. Then, you need to hydrate your form with the request data and test the Symfony validator method `isValid()` on the form.

This is not a good way to deal with REST data validation.

- First of all, Symfony form are design to actually generate HTML form.
- Why would you create a form object (using a fractory) when you already have a form on the front app?
- Form validation is great when you need to actually show (html way) errors. If your goal is to send an error message to your frontend app... well... that's not the purpose.

This bundle is the solution you need.

Instead of exposing 2 WS, you will only expose one. You will be able to send all your datas as a Json object and validate the Json object instead of validate each domain object apart.

Here is an example of what you will be able to do :

Send your data :

```
{
   "name":"Doe",
   "firstname":"John",
   "birthdate":"11/24/1988",
   "addresses":[
      {
         "address":"36, Disney Road",
         "city":"Paradize",
         "zipcode":"764576",
         "country":"France"
      },
      {
         "address":"37, Mickey Road",
         "city":"Paradize",
         "zipcode":"764576",
         "country":"France"
      }
   ]
}
```

And then, the bundle validate all the object for you using the Symfony Validator Component. All you need to do is creating a ParameterBag Class in which you'll define all the expected parameters (query, post, get, etc.) and created an associated validator file where you will define all the rules you need.

You could, for example, apply some unique constraints on the addresses.

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

[](#installation)

Using composer :

```
$ composer require seblegall/api-validator-bundle
```

Then, set up the bundle in your Symfony's `AppKernel.php` file :

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            // ...
            new Seblegall\ApiValidatorBundle\ApiValidatorBundle(),
        );
    }
// ....
```

Finally, import the bundle routing by inserting those lines in the `app/config/routing.yml` file :

```
api_validator_bundle:
    resource: "@ApiValidatorBundle/Resources/config/routing.yml"
```

Usage
-----

[](#usage)

See [documentation](./Resources/doc/index.md).

License
-------

[](#license)

`ApiValidatorBundle` is licensed under the MIT License - see the LICENSE file for details

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3622d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6054602da3bf2bc4b8df9955ccee9b314613fdf0ac81d1d7417b5a42dfe4365f?d=identicon)[seblegall](/maintainers/seblegall)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/seblegall-api-validator-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/seblegall-api-validator-bundle/health.svg)](https://phpackages.com/packages/seblegall-api-validator-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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