PHPackages                             ensostudio/doctrine-entity-validator - 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. [Database &amp; ORM](/categories/database)
4. /
5. ensostudio/doctrine-entity-validator

ActiveLibrary[Database &amp; ORM](/categories/database)

ensostudio/doctrine-entity-validator
====================================

Entity validator for Doctrine ORM 3

1.1.3(11mo ago)06BSD-3-ClausePHPPHP &gt;=8.1

Since May 6Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/ensostudio/doctrine-entity-validator)[ Packagist](https://packagist.org/packages/ensostudio/doctrine-entity-validator)[ Docs](https://github.com/ensostudio/doctrine-entity-validator)[ RSS](/packages/ensostudio-doctrine-entity-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Entity validator for Doctrine ORM 3
-----------------------------------

[](#entity-validator-for-doctrine-orm-3)

[![Latest Stable Version](https://camo.githubusercontent.com/a01d94a3d5dec68b2ae69b341a957b547916944235e8d14fc3b6bd9e635e361c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e736f73747564696f2f646f637472696e652d656e746974792d76616c696461746f722e737667)](https://packagist.org/packages/ensostudio/doctrine-entity-validator)[![Total Downloads](https://camo.githubusercontent.com/4e32350c9a65f5833b10b1960a698277d9e4c510279defec47353f21bd68f083/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e736f73747564696f2f646f637472696e652d656e746974792d76616c696461746f722e737667)](https://packagist.org/packages/ensostudio/doctrine-entity-validator)

By default, entity validation based on attached `\Doctrine\ORM\Mapping\Column` attributes and attributes inherited [ColumnValidator](src/ColumnValidators/ColumnValidator.php) interface.

Also, you can add custom validators by `EntityValidator::addValidator()` or create instance of [ColumnValidator](src/ColumnValidators/ColumnValidator.php) interface.

Validator skip validation:

- If `Column` attribute declared as not `updatable` and/or `insertable`
- Validation on persist/insert and property have `\Doctrine\ORM\Mapping\Id` attribute

Validator checks by column type:

- If property value is null (or not defined), but `Column` attribute not declared as `nullable` or/and don't have default value (`options: ['default' => '...']`)
- If `Column` attribute have **numeric** type (integer, float, decimal and etc.):
    - If defined `unsigned` option, then property value must be more than zero
    - If type `decimal` and defined `precision`, then check size of value
- If `Column` attribute have **string** type (sting, text and etc.):
    - If defined `fixed` option and `length`, then check string length
    - If defined only `length`, then check string length
- If `Column` attribute have **enum** type:
    - If defined `enumType`, then check is proprerty value is declared in enum class

`ColumnValidator` attributes:

- [MinLength](src/ColumnValidators/MinLength.php)
- [Greater](src/ColumnValidators/Greater.php)
- [Number](src/ColumnValidators/Number.php)
- [Regexp](src/ColumnValidators/Regexp.php)
- [Type](src/ColumnValidators/Type.php)
- [Filter](src/ColumnValidators/Filter.php)
- [Slug](src/ColumnValidators/Slug.php)
- [Ip](src/ColumnValidators/Ip.php)
- [Url](src/ColumnValidators/Url.php)
- [Email](src/ColumnValidators/Email.php)

Events
------

[](#events)

The `postValidate`(`EntityValidator::EVENT_POST_VALIDATE`) event triggers after successful validation, the syntax of listener method: `function (LifecycleEventArgs $args): void`.

Examples
--------

[](#examples)

Validates `Product` entity before insert/update data:

```
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use \EnsoStudio\Doctrine\ORM\ColumnValidators;
use EnsoStudio\Doctrine\ORM\EntityValidator;
use EnsoStudio\Doctrine\ORM\EntityValidationException;

#[ORM\Entity]
#[ORM\Table(name: 'products')]
#[ORM\HasLifecycleCallbacks]
class Product
{
    ...

    #[ORM\Column(type: Types::STRING, length: 200)]
    #[ColumnValidators\MinLength(2)]
    #[ColumnValidators\Slug]
    private string $slug;

    #[ORM\Column(type: Types::STRING, length: 150)]
    #[ColumnValidators\Type('print')]
    private string $name;

    #[ORM\PrePersist]
    public function beforeInsert(): void
    {
        $validator = new EntityValidator($this);
        // Callback same to ColumnValidators\MinLength(3)
        $validator->addValidator(
            'name',
            static function (string $propertyValue, string $propertyName, object $entity) {
                if (mb_strlen($propertyValue) < 3) {
                    throw new EntityValidationException(
                        ['% less than 3 characters', $propertyName],
                        $propertyName,
                        $entity
                    );
                }
            }
        );
        $validator->validate();
    }

    #[ORM\PreUpdate]
    public function beforeUpdate(): void
    {
        $validator = new EntityValidator($this);
        ...
        $validator->validate(true);
    }
}
```

Or you can use `EntityValidationSubscriber` to validates all entities:

```
use Doctrine\ORM\EntityManager;
use EnsoStudio\Doctrine\ORM\EntityValidationSubscriber;

...
$entityManager = new EntityManager($connection, $config);
$entityManager->getEventManager()
    ->addEventSubscriber(new EntityValidationSubscriber(true));
```

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

[](#requirements)

- PHP &gt;= 8.1 (with `mbstring` extension)
- doctrine/orm &gt;= 3.3

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

[](#installation)

If you do not have Composer, you may install it by following the instructions at [getcomposer.org](https://getcomposer.org/doc/00-intro.md#introduction).

You can then install this library using the following command:

```
composer require ensostudio/doctrine-entity-validator
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance54

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Every ~4 days

Total

5

Last Release

351d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc2a332d2cf8cd31b36bf1a8a16d76f1f6cca2e17a0b953072ddbc84731d66c0?d=identicon)[ensostudio](/maintainers/ensostudio)

---

Top Contributors

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

---

Tags

doctrinedoctrine-ormentityvalidatevalidationvalidatorphpvalidatorormdoctrinevalidateentity

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ensostudio-doctrine-entity-validator/health.svg)

```
[![Health](https://phpackages.com/badges/ensostudio-doctrine-entity-validator/health.svg)](https://phpackages.com/packages/ensostudio-doctrine-entity-validator)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[ergebnis/factory-bot

Provides a fixture factory for doctrine/orm entities.

81702.8k](/packages/ergebnis-factory-bot)[indaxia/doctrine-orm-transformations

Provides JSON-ready Doctrine ORM Entity-Array transfomtaions

1296.4k](/packages/indaxia-doctrine-orm-transformations)[andsalves/doctrine-elastic

Elasticsearch Doctrine Adaptation

156.6k](/packages/andsalves-doctrine-elastic)

PHPackages © 2026

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