PHPackages                             vection-framework/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. [Framework](/categories/framework)
4. /
5. vection-framework/validator

ActiveLibrary[Framework](/categories/framework)

vection-framework/validator
===========================

The Vection Validator provides validation of data and schemas. A number of different validators are already included and can be applied in a chained manner.

v0.3.4(6y ago)34601MITPHPPHP ^7.2

Since Aug 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Vection-Framework/Validator)[ Packagist](https://packagist.org/packages/vection-framework/validator)[ Docs](https://vection.de)[ RSS](/packages/vection-framework-validator/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (10)Used By (1)

[![release](https://camo.githubusercontent.com/2e70146e7d2e6864e3614d9058f4b162b60d44e748706f7c6f798e2432afbc90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f56656374696f6e2d4672616d65776f726b2f56656374696f6e3f696e636c7564655f70726572656c6561736573267374796c653d666f722d7468652d6261646765)](https://img.shields.io/github/v/release/Vection-Framework/Vection?include_prereleases)[![QA](https://camo.githubusercontent.com/80382627191a0df87fa0ebba20fabedcd1b0a44350635a8be44fafd09a23bd06/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f56656374696f6e2d4672616d65776f726b2f56656374696f6e2f51413f6c6162656c3d5141267374796c653d666f722d7468652d6261646765)](https://github.com/Vection-Framework/Vection/actions)[![PHPStan](https://camo.githubusercontent.com/00d51f739bc2a7ddc91055fb77a57bbe810ca04d41031111f77b534e71060205/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230362d626c756576696f6c65742e7376673f7374796c653d666f722d7468652d6261646765)](https://phpstan.org)

Vection Validator
=================

[](#vection-validator)

PHP Validator for data and schema validation
--------------------------------------------

[](#php-validator-for-data-and-schema-validation)

This vection component provides a data and schema validator for PHP. You can use it from validate simple values up to big data arrays via chained validators. This component also provides a schema based validation of data structures. The flexible and open closed aspect of vection components allows to extend and modify the most classes of this component or define custom validator classes. This component can be used for the following scenarios:

- simple value validation
- data set validation by chained validators
- extend with custom validators
- schema based data structure validation

### Installation

[](#installation)

Vection Components supports only installation via [composer](https://getcomposer.org). So first ensure your composer is installed, configured and ready to use.

```
$ composer require vection-framework/validator
```

### Simple value validation

[](#simple-value-validation)

```
$validator = new Vection\Component\Validator\Validator\Date("H:i:s");

# Each validator returns null on success or an object of Violation on fail
$violation = $validator->validate("17:12-43");

if( $violation ){
    $violation->getMessage();   // or
    $violation->getValue();     // or
    echo $violation; // Date "17:12-43" is invalid or does not match format "H:i:s".
}
```

### Data set validation by chained validators

[](#data-set-validation-by-chained-validators)

```
// e.g. the POST request input
$data = [
    'name' => 'John Doe',
    'age' => 42,
    'date' => '2019-02-03'
];

$chain = new Vection\Component\Validator\ValidatorChain();

$chain('name')
    ->notNull()
    ->alphaNumeric()
    ->betweenLength(3, 20)
;

$chain('age')
    ->notNull()
    ->numeric()
    ->range(0, 100)
;

$chain('date')
    ->nullable()
    ->date("Y-m-d")
;

$chain->verify($data);

if( $violations = $chain->getViolations() ){
    //here we got an array of Violation objects
    print json_encode($violations);
    # output: {"name": {"value":"2019-02-03", "message":"..."}, "age": {...}, ...}
}
```

### Using custom validator implementation

[](#using-custom-validator-implementation)

```
class CustomValidator extends Vection\Component\Validator\Validator { ... }

$customValidator = new CustomValidator(...);
$customValidator->validate(...);

// or

$chain = new ValidatorChain();

$chain('xxx')
    ->notNull()
    ->use($customValidator)
;
```

### Schema based data structure validation

[](#schema-based-data-structure-validation)

The schema validator uses a json schema definition to validate the given data structure by json/yaml file, json/yaml strings or data array.

#### The base of each schema

[](#the-base-of-each-schema)

The schema starts always with an object which must have properties and optional reusable template definitions.

```
{
    "@type": "object",
    "@properties": {},
    "@templates": {}
}
```

##### String

[](#string)

```
{
    "@type": "object",
    "@properties": {
        "foo": {
            "@type": "string",
            "@required": true,
            "@allowed": "yes|no"
        }
    }
}
```

##### Integer/Float

[](#integerfloat)

```
{
    "@type": "object",
    "@properties": {
        "foo": {
            "@type": "integer",
            "@required": true,
            "@range": "0..100"
        },
        "bar": "float"
    }
}
```

##### Object with fixed property names

[](#object-with-fixed-property-names)

Use @properties for fixed property names to ensure that this keys are set with an value.

```
{
    "@type": "object",
    "@properties": {
        "foo": {
            "@type": "string"
        },
        "bar": {
            "@type": "integer",
            "@required": true
        }
    }
}
```

##### Object with variable property names

[](#object-with-variable-property-names)

Use @property for variable property names to allow multiple properties with different names but same property schema definition.

```
{
    "@type": "object",
    "@property": {
        "@type": "string",
        "@required": true
    }
}
```

##### Array of properties

[](#array-of-properties)

Use the array type to define an array property which contains elements by schema defined in @property.

```
{
    "@type": "object",
    "@properties": {
        "foo": {
            "@type": "array",
            "@property": {
                "@type": "object",
                "@properties": {
                    "foo": {
                        "@type": "string"
                    },
                    "bar": {
                        "@type": "integer",
                        "@required": true
                    }
                }
            }
        }
    }
}
```

#### Schema property validators

[](#schema-property-validators)

The schema definition can use the validators of this component to validate a schema property value.

```
{
    "@type": "object",
    "@properties": {
        "foo": {
            "@type": "string",
            "@validator": "alphaNumeric"
        },
        "bar": {
            "@type": "string",
            "@validator": {
                "@name": "email"
            }
        },
        "xxx": {
            "@type": "string",
            "@validator": {
                "@name": "betweenLength",
                "@constraints": {
                    "min": 3,
                    "max": 30
                }
            }
        }
    }
}
```

#### Schema property templates

[](#schema-property-templates)

Use can use templates to reuse on different properties. The templates are defined at the root of the schema and is an object contains multiple names templates.

```
{
    "@type": "object",
    "@properties": {
        "books": {
            "@type": "array",
            "@property": {
                "@template": "book"
            }
        }
    },
    "@templates": {
        "book": {
            "@type": "object",
            "@properties": {
                "name": {
                    "@type": "string",
                    "@required": true
                },
                "description": {
                    "@type": "string"
                },
                "summary": "string",
                "pages": "integer"
            }
        }
    }
}
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.1% 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 ~38 days

Total

9

Last Release

2209d ago

### Community

Maintainers

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

---

Top Contributors

[![bloodhunterd](https://avatars.githubusercontent.com/u/43681086?v=4)](https://github.com/bloodhunterd "bloodhunterd (113 commits)")[![davidlung](https://avatars.githubusercontent.com/u/30243811?v=4)](https://github.com/davidlung "davidlung (50 commits)")[![BKlemm](https://avatars.githubusercontent.com/u/1234178?v=4)](https://github.com/BKlemm "BKlemm (25 commits)")

---

Tags

assertassertioncomponentframeworklibraryphpschemaschemetesttestingvalidationvalidatorframeworkvalidatorvalidationassertassertionphp-validatorphp-assert

### Embed Badge

![Health badge](/badges/vection-framework-validator/health.svg)

```
[![Health](https://phpackages.com/badges/vection-framework-validator/health.svg)](https://phpackages.com/packages/vection-framework-validator)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.7k](/packages/cakephp-cakephp)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

170227.3k3](/packages/davidepastore-slim-validation)[runn/validation

Runn Me! Validation and Sanitization Library

1027.6k2](/packages/runn-validation)[nilportugues/assert

A simple and elegant assertion and guard methods library for input validation.

1066.1k7](/packages/nilportugues-assert)[krzysztofrewak/laravel-oop-validator

Laravel Validator object-oriented wrapper

805.9k](/packages/krzysztofrewak-laravel-oop-validator)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)

PHPackages © 2026

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