PHPackages                             ibekiaris/zf2-annotation-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. ibekiaris/zf2-annotation-validator

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

ibekiaris/zf2-annotation-validator
==================================

Add validation annotations to doctrine entity

425PHP

Since Oct 7Pushed 10y ago4 watchersCompare

[ Source](https://github.com/ibekiaris/zf2-annotation-validator)[ Packagist](https://packagist.org/packages/ibekiaris/zf2-annotation-validator)[ RSS](/packages/ibekiaris-zf2-annotation-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Description
-----------

[](#description)

Annotation validator is a ZF2 module used to validate Doctrine Entities during their lifecycle call backs (events).

By using Annotation Validator in your projects you can enhance productivity. At the same time, Junior developers who are involved in your project don't have to be concerned about validation since it takes place in entities.
You can also be sure that your persistence layer is more protected against code vulnerabilities.

At the moment data is validated just before flush, against the idea of using an ORM where entities must be valid after their "construction".

However this module solved a lot of real life problems for me and I think that this is what matters when sharing code.

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

[](#installation)

1. With composer:

```
composer require ibekiaris/zf2-annotation-validator

```

2. Directly in you ZF2 project:

Just copy module files into "module" directory

In any case, after including code, add the following lines in application.config.php

```
'modules' => array(
        'Application',
        'AnnotationValidator'
    ),

```

Finally add "module.config.sample.php" lines into your global or local project configuration file. You have to change of course 'validation\_classes\_aliases' according your needs.

Documentation
-------------

[](#documentation)

Use AnnotationValidator\\DoctrineValidatorTrait into you entities.

```
use AnnotationValidator\DoctrineValidatorTrait

/**
 * This is a simple Entity Class
 *
 *
 * @ORM\Entity
 * @ORM\Table(name="clients")
 * @ORM\HasLifecycleCallbacks
 *
 * @author     Ioannis Bekiaris
 * @copyright  2015 - 2016 Ioannis Bekiaris
 */
class Client
{
    use DoctrineValidatorTrait;

    /**
     * @ORM\Column(name="title", type="string")
     *
     * @VLD {"type":"RequiredString"}
     * @var string
     */
    private $name;

}

```

Use @VLD annotation to validate $name property.

e.g module.config.php

```
return [
    'validation_classes_aliases' => [
        'RequiredString' => [
            'validation_class' => '\Zend\Validator\Regex',
            'validation_options' => [
                'pattern' => '/^[\p{L}0-9\s\.\-]+$/u',
            ],
        ],
        'HostName' => [
            'validation_class' => '\Zend\Validator\Hostname',
            'validation_options' => [
                'allow' => \Zend\Validator\Hostname::ALLOW_ALL,
            ],
        ],
        'LonLat' => [
            'validation_class' => '\Zend\Validator\Regex',
            'validation_options' => [
                'pattern' => '/^[A-Z0-9\s\.]{0,10}$/',
             ],
        ],
    ],

```

NOTICES
-------

[](#notices)

Use "NotRequired" as suffix or prefix in validation types(aliases) to accept null as values:

e.g

```
/**
 * @ORM\Column(name="facebook_account_url", type="string", nullable=true)
 *
 * @VLD {"type":"UriNotRequired"}
 * @var string
 */
protected $facebookAccountUrl;

```

### LICENSE

[](#license)

The files in this archive are released under license. You can find a copy of this license in [LICENSE.txt](LICENSE.txt).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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://www.gravatar.com/avatar/79b3ce6e2f292f37874c079922faff1c9ffbe23742b588cd8c4d66e02301f1cd?d=identicon)[ibekiaris](/maintainers/ibekiaris)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/ibekiaris-zf2-annotation-validator/health.svg)

```
[![Health](https://phpackages.com/badges/ibekiaris-zf2-annotation-validator/health.svg)](https://phpackages.com/packages/ibekiaris-zf2-annotation-validator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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