PHPackages                             cocoon-projet/control - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. cocoon-projet/control

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

cocoon-projet/control
=====================

Librairie de validation pour php

0.0.2(1y ago)0251MITPHPPHP ^8.0CI passing

Since Nov 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cocoon-projet/control)[ Packagist](https://packagist.org/packages/cocoon-projet/control)[ Docs](https://github.com/cocoon-projet/control/blob/master/docs/README.md)[ RSS](/packages/cocoon-projet-control/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

[![Tests](https://github.com/cocoon-projet/control/actions/workflows/ci.yml/badge.svg)](https://github.com/cocoon-projet/control/actions/workflows/ci.yml) [![codecov](https://camo.githubusercontent.com/8b762adba6e3bfcc4faf94f79005e9dfbc10780356264c7bd5ba9224b4fd9acc/68747470733a2f2f636f6465636f762e696f2f67682f636f636f6f6e2d70726f6a65742f636f6e74726f6c2f67726170682f62616467652e7376673f746f6b656e3d373639334d45554b3343)](https://codecov.io/gh/cocoon-projet/control) [![License](https://camo.githubusercontent.com/bbd05f341c8cc2fef766a381c121830e990070db1c11179202f86be4fbfae318/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d677265656e)](https://camo.githubusercontent.com/bbd05f341c8cc2fef766a381c121830e990070db1c11179202f86be4fbfae318/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d677265656e)

Cocoon Control
==============

[](#cocoon-control)

Une librairie PHP 8 de validation de données simple et puissante.

Prérequis
---------

[](#prérequis)

- PHP 8.0 ou supérieur
- Composer

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

[](#installation)

```
composer require cocoon-projet/control
```

Utilisation
-----------

[](#utilisation)

### Validation de base

[](#validation-de-base)

```
use Cocoon\Control\Validator;

$validator = new Validator();

$validator->validate([
    'name' => 'required',
    'email' => 'required|email',
    'age' => 'required|int|num_min:18',
    'password' => 'required|same:password_confirm',
    'password_confirm' => 'required'
]);
```

### Validation avec données personnalisées

[](#validation-avec-données-personnalisées)

```
$validator->data([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => '25',
    'password' => '123456',
    'password_confirm' => '123456'
])->validate([
    'name' => 'required',
    'email' => 'required|email',
    'age' => 'required|int|num_min:18',
    'password' => 'required|same:password_confirm',
    'password_confirm' => 'required'
]);
```

### Messages d'erreur personnalisés

[](#messages-derreur-personnalisés)

```
$validator->validate([
    'name' => 'required',
    'email' => 'required|email'
], [
    'name.required' => 'Le nom est obligatoire',
    'email.email' => 'L\'adresse email n\'est pas valide'
]);
```

### Alias de champs

[](#alias-de-champs)

```
$validator->validate([
    'user_name as nom d\'utilisateur' => 'required',
    'user_email as email' => 'required|email'
]);
```

### Règles personnalisées

[](#règles-personnalisées)

```
$validator->addRule('custom', function($value) {
    return $value === 'valid';
}, 'La valeur doit être "valid"');

$validator->validate([
    'field' => 'required|custom'
]);
```

### Gestion des erreurs

[](#gestion-des-erreurs)

```
try {
    $validator->validate([
        'name' => 'required',
        'email' => 'required|email'
    ]);
} catch (\Cocoon\Control\Exceptions\ValidationException $e) {
    $errors = $e->getErrors();
    // Traitement des erreurs
}
```

Règles disponibles
------------------

[](#règles-disponibles)

- `required` : Le champ est obligatoire
- `email` : Le champ doit être une adresse email valide
- `int` : Le champ doit être un nombre entier
- `num_min:value` : Le champ doit être supérieur ou égal à la valeur spécifiée
- `num_max:value` : Le champ doit être inférieur ou égal à la valeur spécifiée
- `same:field` : Le champ doit correspondre au champ spécifié
- `alpha` : Le champ ne doit contenir que des lettres
- `al_num` : Le champ ne doit contenir que des lettres et des chiffres
- `bool` : Le champ doit être un booléen
- `date` : Le champ doit être une date valide
- `ip` : Le champ doit être une adresse IP valide

Gestion des fichiers
--------------------

[](#gestion-des-fichiers)

La librairie supporte également la validation des fichiers uploadés :

```
$validator->validate([
    'avatar' => 'required_file|type:jpg,gif|size:100000'
]);
```

Tests
-----

[](#tests)

Pour exécuter les tests :

```
composer test
```

Pour générer un rapport de couverture de code :

```
composer test-coverage
```

Contribution
------------

[](#contribution)

Les contributions sont les bienvenues ! N'hésitez pas à :

1. Fork le projet
2. Créer une branche pour votre fonctionnalité (`git checkout -b feature/amazing-feature`)
3. Commit vos changements (`git commit -m 'Add some amazing feature'`)
4. Push vers la branche (`git push origin feature/amazing-feature`)
5. Ouvrir une Pull Request

Licence
-------

[](#licence)

Ce projet est sous licence MIT. Voir le fichier [LICENSE](LICENSE) pour plus de détails.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance50

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Every ~523 days

Total

2

Last Release

395d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b019cffcdf77ab35448666ea712d4263ae3afd4bc0110de6a267936e3dba08d?d=identicon)[cocoon-projet](/maintainers/cocoon-projet)

---

Top Contributors

[![cocoon-projet](https://avatars.githubusercontent.com/u/28481301?v=4)](https://github.com/cocoon-projet "cocoon-projet (7 commits)")

---

Tags

validatorvalidationverifyvalidatecontrolvalid

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cocoon-projet-control/health.svg)

```
[![Health](https://phpackages.com/badges/cocoon-projet-control/health.svg)](https://phpackages.com/packages/cocoon-projet-control)
```

###  Alternatives

[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.4M128](/packages/vlucas-valitron)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M29](/packages/wixel-gump)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18293.8k1](/packages/sadegh19b-laravel-persian-validation)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k8](/packages/awurth-slim-validation)[romeoz/rock-validate

Flexible validator for PHP with I18N.

251.7k6](/packages/romeoz-rock-validate)

PHPackages © 2026

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