PHPackages                             ebidtech/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. ebidtech/validator

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

ebidtech/validator
==================

A validator on top of Symfony validator

v0.1.4.1(12y ago)048.1k1[1 PRs](https://github.com/ebidtech/validator/pulls)MITPHPPHP &gt;=5.3.3

Since Jan 12Pushed 10y ago13 watchersCompare

[ Source](https://github.com/ebidtech/validator)[ Packagist](https://packagist.org/packages/ebidtech/validator)[ Docs](http://github.com/ebidtech/validator)[ RSS](/packages/ebidtech-validator/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (4)Dependencies (5)Versions (9)Used By (0)

Validator
=========

[](#validator)

A validator on top of Symfony validator.

[![Latest Stable Version](https://camo.githubusercontent.com/0915b6b2f47cb9e559ef8f63ba8bf9a3467c2d30ed1c3ad6a874a1347434d80f/68747470733a2f2f706f7365722e707567782e6f72672f65626964746563682f76616c696461746f722f762f737461626c652e706e67)](https://packagist.org/packages/ebidtech/validator)[![Build Status](https://camo.githubusercontent.com/c7f48faafd1d9eef9fd8fb2ac2b487dd1aef41c321be751fbd1cc74d88880fea/68747470733a2f2f7472617669732d63692e6f72672f65626964746563682f76616c696461746f722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/ebidtech/validator) [![Coverage Status](https://camo.githubusercontent.com/9a7cbeb33d25139a12cb937cebb4335dcbbb7d3939fdc1573f9fe419c9092050/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f65626964746563682f76616c696461746f722f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/ebidtech/validator?branch=master) [![Scrutinizer Quality Score](https://camo.githubusercontent.com/4e33a7e540096d8c6451424db03bf072b9eeba9e0813e9bd5062a6a82bde1dc6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f65626964746563682f76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f733d33386462323866396663336237623432383663343739633737326634666364386234383535323832)](https://scrutinizer-ci.com/g/ebidtech/validator/) [![Dependency Status](https://camo.githubusercontent.com/e5c630acf56fa4c80b5dec223d71cb7da79dab9fe1fb6311cb8f9d5ea2579a74/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3532646135633463656331333735313062663030303338302f62616467652e706e67)](https://www.versioneye.com/user/projects/52da5c4cec137510bf000380)

Why to use?
-----------

[](#why-to-use)

Using Symfony validator with annotations or configuration (yml or xml) is just fine, but for simple cases, eg: validation of argument methods and throw exception is too verbose.

Eg:

### Symfony way

[](#symfony-way)

```
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints\Type;

class Test {
    public function getByName($name)
    {
        $violations = Validation::createValidator()->validateValue(
            $name,
            new Type(array('type' => 'string'))
        );

        if (count($violations) != 0) {
          throw new \InvalidArgumentException((string) $violations);
        }
    }
}
```

### EBTValidator way

[](#ebtvalidator-way)

```
use EBT\Validator\ValidatorBasicExtended;

class Test {
    public function getByName($name)
    {
        if (!ValidatorBasicExtended::isTypeString($name)) {
            throw new \InvalidArgumentException(ValidatorBasicExtended::getViolationsAsShortString());
        }
    }
}
```

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

[](#requirements)

- PHP &gt;= 5.3.3

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

[](#installation)

The recommended way to install is through composer.

Just create a `composer.json` file for your project:

```
{
    "require": {
        "ebidtech/validator": "@stable"
    }
}
```

**Tip:** browse [`ebidtech/validator`](https://packagist.org/packages/ebidtech/validator) page to choose a stable version to use, avoid the `@stable` meta constraint.

And run these two commands to install it:

```
$ curl -sS https://getcomposer.org/installer | php
$ composer install
```

Now you can add the autoloader, and you will have access to the library:

```
