PHPackages                             michaelcozzolino/symfony-validation-enhancements-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. michaelcozzolino/symfony-validation-enhancements-bundle

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

michaelcozzolino/symfony-validation-enhancements-bundle
=======================================================

A set of symfony validations to enhance the experience with the Symfony validator

v1.0.0(1y ago)123[5 PRs](https://github.com/michaelcozzolino/symfony-validation-enhancements-bundle/pulls)MITPHPPHP &gt;=8.2

Since Nov 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/michaelcozzolino/symfony-validation-enhancements-bundle)[ Packagist](https://packagist.org/packages/michaelcozzolino/symfony-validation-enhancements-bundle)[ RSS](/packages/michaelcozzolino-symfony-validation-enhancements-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (10)Versions (12)Used By (0)

Symfony Validation Enhancements Bundle
======================================

[](#symfony-validation-enhancements-bundle)

The **Symfony Validation Enhancements Bundle** is a Symfony bundle designed to extend and enhance the default validation capabilities provided by the Symfony framework. It introduces additional constraints and validation features to facilitate more robust data validation within Symfony applications.

Key Features
------------

[](#key-features)

- **Additional Validators**: Custom validators that complement Symfony's native validation constraints for more specific and tailored validation rules.
- **Enhanced Validation Logic**: Advanced validation mechanisms to implement complex scenarios with ease.

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

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

### Applications that use Symfony Flex

[](#applications-that-use-symfony-flex)

Open a command console, enter your project directory and execute:

```
$ composer require michaelcozzolino\SymfonyValidationEnhancementsBundle
```

### Applications that don't use Symfony Flex

[](#applications-that-dont-use-symfony-flex)

#### Enable the Bundle

[](#enable-the-bundle)

Then, enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project:

```
// config/bundles.php

return [
    // ...
    MichaelCozzolino\SymfonyValidationEnhancementsBundle\SymfonyValidationEnhancementsBundle::class => ['all' => true],
];
```

Docs
----

[](#docs)

The bundle automatically register the following event listeners:

`RequestPayloadTrimmerListener`
-------------------------------

[](#requestpayloadtrimmerlistener)

The `RequestPayloadTrimmerListener` is an event listener designed to trim whitespace from the request payload during the Symfony kernel request event. This ensures clean and sanitized data is passed through the application.

When used together with the `NonEmptyString` constraint, it will cause validation to fail for requests containing only whitespace or empty strings, such as:

```
{
    "name": "     ",
    "surname": ""
}
```

### Usage

[](#usage)

`max` is used to specify the maximum length of the string, if `null` or omitted, the max length is `+inf`.

```
use MichaelCozzolino\SymfonyValidationEnhancementsBundle\Validator\Constraint\NonEmptyString;

class MyRequest {
    public function __construct(
        #[NonEmptyString(max: 1000)]
        public readonly string $name,

        #[NonEmptyString(max: null)]
        public readonly string $surname
    ) {
    }
}
```

if working with MySql, more specific constraints can be used:

```
use MichaelCozzolino\SymfonyValidationEnhancementsBundle\Validator\Constraint\NonEmptyMySqlText;
use MichaelCozzolino\SymfonyValidationEnhancementsBundle\Validator\Constraint\NonEmptyMySqlVarcharDefault;

class PersonRequest {
    public function __construct(
        #[NonEmptyMySqlText]
        public readonly string $name,

        #[NonEmptyMySqlVarcharDefault]
        public readonly string $surname
    ) {
    }
}
```

`ValidationErrorListener`
-------------------------

[](#validationerrorlistener)

The `ValidationErrorListener` automatically standardizes the obtained response after one or more validation failure. Let's suppose your request object is the following one:

```
use MichaelCozzolino\SymfonyValidationEnhancementsBundle\Validator\Constraint\NonEmptyString;
use Symfony\Component\Validator\Constraints as Assert;

class AddressRequest {
    public function __construct(
        #[NonEmptyString]
        public readonly string $street,

        #[Assert\Positive]
        public readonly int $number
    ) {
    }
}

class UserRequest {
    public function __construct(
        #[Assert\Positive]
        public readonly int $userId,

        #[Assert\All([
            new Assert\Positive
        ])]
        public readonly array $productIds,

        #[Assert\Valid]
        public readonly AddressRequest $address
    ) {

    }
}
```

and an invalid payload could be:

```
{
    "userId": -19,
    "productIds": [
        -1,
        2,
        0
    ],
    "address": {
        "street": "",
        "number": -1
    }
}
```

the listener above will return a json response structured as:

```
{
    "userId": [
        "validation error for -19"
    ],
    "productIds": {
        "0": [
            "validation error for -1"
        ],
        "2": [
            "validation error for 0"
        ]
    },
    "address": {
        "street": [
            "validation error for street"
        ],
        "number": [
            "validation error for number"
        ]
    }
}
```

So, the final json response is the same object from the request whose values are an array (in case of multiple constraint) of errors.

Constraints
-----------

[](#constraints)

In addition to the constraints mentioned before, we also have:

`EntityExists`
--------------

[](#entityexists)

It checks that an entity exists, meaning that there exists one row in the database using the specified identifier.

### Usage

[](#usage-1)

```
use MichaelCozzolino\SymfonyValidationEnhancementsBundle\Validator\Constraint\EntityExists;class EntityRequest {
    public function __construct(
        #[EntityExists(entityClass: MyEntity::Class, validateExistence:true, entityProperty: 'id', entityName: 'my entity')]
        public readonly int $entityId
    ) {
    }
}
```

### Parameters

[](#parameters)

`entityClass`: The class-string of the entity.

`validateExistence`: If set to true the validation will fail if the entity already exists, if set to false the validation will fail if the entity does not exist. The last one is useful for example when you want to store some data whose id is for example a non auto generated one but decided by the code. **Default**: `true`

`entityProperty`: The name of the column used as primary key to retrieve the entity. **Default**: `'id'`

`entityName`: The name of the entity that will be used in the validation message. **Default**: `null`. In case the default value is used the validator will try to guess the short name of the entity class.

### Message

[](#message)

**type**: `string` **default**: `The requested `{entityName}` does not exist.`

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.5% 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 ~6 days

Total

4

Last Release

582d ago

Major Versions

v0.2.0 → v1.0.02024-11-29

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/41123653?v=4)[Michael Cozzolino](/maintainers/michaelcozzolino)[@michaelcozzolino](https://github.com/michaelcozzolino)

---

Top Contributors

[![michaelcozzolino](https://avatars.githubusercontent.com/u/41123653?v=4)](https://github.com/michaelcozzolino "michaelcozzolino (67 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/michaelcozzolino-symfony-validation-enhancements-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/michaelcozzolino-symfony-validation-enhancements-bundle/health.svg)](https://phpackages.com/packages/michaelcozzolino-symfony-validation-enhancements-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M387](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[sylius/sylius

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

8.5k5.9M738](/packages/sylius-sylius)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)[sulu/sulu

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

1.3k1.4M203](/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.1k17.8k](/packages/prestashop-prestashop)

PHPackages © 2026

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