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

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

pklink/validator-chain
======================

Perform validation in a chain

1.0.0(10y ago)014MITPHPPHP &gt;=5.6.0

Since Mar 15Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pklink/ValidatorChain)[ Packagist](https://packagist.org/packages/pklink/validator-chain)[ RSS](/packages/pklink-validator-chain/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

ValidatorChain [![Build Status](https://camo.githubusercontent.com/eb9c9392d05f282f9fe4284fd46e0021552015765578c5c95c5bb46ccc0f4c43/68747470733a2f2f7472617669732d63692e6f72672f706b6c696e6b2f56616c696461746f72436861696e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/pklink/ValidatorChain)
=============================================================================================================================================================================================================================================================================================================

[](#validatorchain-)

A library to perform several validations in a chain.

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

[](#installation)

Install `ValidationChain` with Composer

Create or update your composer.json

```
{
    "require": {
        "pklink/validation-chain": "0.*"
    }
}
```

And run Composer

```
php composer.phar install
```

Finally include Composers autoloader

```
include __DIR__ . '/vendor/autoload.php';
```

Basic Usage
-----------

[](#basic-usage)

Create an instance of `Chain` with the value you like to check

```
$chain = \Validation\Chain('check me');
```

Now, run some tests in a chain

```
$chain
    ->isString()  // return instance of Chain
    ->isInteger() // return instance of Chain
    ->isArray()   // return instance of Chain
;
```

If you want to know if all validations run fine use the `isValid`-method

```
$chain->isValid(); // return false
```

Alternatively you can use this in one statement:

```
(new \Validation\Chain('check me'))
    ->isString()
    ->isInteger()
    ->isArray()
    ->isValid()
```

### Reset chain

[](#reset-chain)

Use `reset()` to reset your chain.

```
$chain = new \Validator\Chain('value');

$chain->isInteger()->isString()->isValid(); // returns false
$chain->isValid();                          // returns false
$chain->isString()->isValid();              // returns false
$chain->reset()->isString()->isValid();     // returns true
```

Options
-------

[](#options)

You can set different options with instantiation or the setter for the appropriate option.

```
$chain = new \Validator\Chain('value', ['option' => 'value']);
```

### throwExceptionOnFailure

[](#throwexceptiononfailure)

If this option is set to `true` then `Chain` will throw a `Validator\Exception` if a validation failed.

Default is set to `false`

```
$chain = new \Validator\Chain('value', ['throwExceptionOnFailure' => true]);

try {
    $chain
        ->isString()         // everything fine
        ->minimumLengthOf(2) // everything fine
        ->isArray()          // \Validator\Exception will be thrown
        ->isArray();         // will not perform
} catch (\Validator\Excetion $e) {
    echo 'validation failed!';
}
```

The setter for this option is `throwExceptionOnFailure()`

```
$chain->throwExceptionOnFailure(true);
$chain->throwExceptionOnFailure(false);
$chain->throwExceptionOnFailure(); // set this option to true
```

### stopValidationOnFailure

[](#stopvalidationonfailure)

If this option is set to `true` then `Chain` will not perform any further validation.

Default is set to `true`

```
$chain = new \Validator\Chain('value', ['stopValidationOnFailure' => true]);

$chain
    ->isString()    // everthing fine
    ->isArray()     // validation fail
    ->isInteger();  // will not perform
```

The setter for this option is `stopValidationOnFailure()`

```
$chain->stopValidationOnFailure(true);
$chain->stopValidationOnFailure(false);
$chain->stopValidationOnFailure(); // set this option to true
```

Listener for failures
---------------------

[](#listener-for-failures)

You can add Closures to get notifications on failures.

```
$chain = new \Validator\Chain('value');

$chain->addValidationFailureListener(function() {
    echo 'failure';
});

$chain->isInteger();
```

This example will output: `failure`

If you like you can use the failed `\Validator\Rule` in your listener

```
$chain->addValidationFailureListener(function(\Validation\Rule $rule) {
    echo get_class($rule);
});
```

Rules
-----

[](#rules)

### hasKey()

[](#haskey)

### hasKeys()

[](#haskeys)

### isArray()

[](#isarray)

### isInteger()

[](#isinteger)

### isInt()

[](#isint)

Alias for isInteger()

### isNull()

[](#isnull)

### isNull()

[](#isnull-1)

### isNumeric()

[](#isnumeric)

### isObject()

[](#isobject)

### isScalar()

[](#isscalar)

### isString()

[](#isstring)

### lengthOf( int $length )

[](#lengthof-int-length-)

### maximumLengthOf( int $length )

[](#maximumlengthof-int-length-)

### minumumLengthOf( int $length )

[](#minumumlengthof-int-length-)

Add your own rule
-----------------

[](#add-your-own-rule)

Run Tests
---------

[](#run-tests)

You can use PHPUnit from the vendor-folder.

```
php composer.phar install --dev
php vendor/bin/phpunit tests/
```

or with code-coverage-report

```
php composer.phar install --dev
php vendor/bin/phpunit --coverage-html output tests/
```

License
-------

[](#license)

This package is licensed under the MIT License. See the LICENSE file for details.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~346 days

Total

4

Last Release

3768d ago

Major Versions

0.2.1 → 1.0.02016-01-20

PHP version history (2 changes)0.1PHP &gt;=5.4.0

1.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c8c5e958e572c9805a2746a44c66ffd72fdfb22f1f5c7f0723a40afee9ec176?d=identicon)[pklink](/maintainers/pklink)

---

Top Contributors

[![pklink](https://avatars.githubusercontent.com/u/753350?v=4)](https://github.com/pklink "pklink (11 commits)")

---

Tags

validationChain

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pklink-validator-chain/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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