PHPackages                             phramework/validate - 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. phramework/validate

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

phramework/validate
===================

phramework's validation library

1.3.0(7y ago)335.5k—0%2[16 issues](https://github.com/phramework/validate/issues)[7 PRs](https://github.com/phramework/validate/pulls)3Apache-2.0PHPPHP ^7.1|^8.0.0CI failing

Since Nov 28Pushed 4y ago4 watchersCompare

[ Source](https://github.com/phramework/validate)[ Packagist](https://packagist.org/packages/phramework/validate)[ Docs](https://phramework.github.io/)[ RSS](/packages/phramework-validate/feed)WikiDiscussions dev-1.x Synced 2mo ago

READMEChangelog (10)Dependencies (4)Versions (54)Used By (3)

phramework/validate
===================

[](#phrameworkvalidate)

> phramework's validation library

[![Coverage Status](https://camo.githubusercontent.com/c11fde82be4a6c6d08cae3fb3f0ff3348b28f5ba65f25d529f4fb72c0eca0e9e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f706872616d65776f726b2f76616c69646174652f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/phramework/validate?branch=master) [![Build Status](https://camo.githubusercontent.com/aad5d0ab5c08e8b3b27f04f7fed1b52c60bdfa9d22180dc71a385cbf1734b125/68747470733a2f2f7472617669732d63692e6f72672f706872616d65776f726b2f76616c69646174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phramework/validate)[![StyleCI](https://camo.githubusercontent.com/1619d56625ebce66207c823c9d3945a7b8b9bee2882e11d495eca427ec2658a6/68747470733a2f2f7374796c6563692e696f2f7265706f732f34363933383333312f736869656c64)](https://styleci.io/repos/46938331)[![Stories in Ready](https://camo.githubusercontent.com/0b179448784eb2ef1a3032eda1f12d877dace1771ecfa9dc7f7bf2ac647799cd/68747470733a2f2f62616467652e776166666c652e696f2f706872616d65776f726b2f76616c69646174652e7376673f6c6162656c3d7265616479267469746c653d5265616479)](http://waffle.io/phramework/validate)

Usage
-----

[](#usage)

Require package using composer

```
composer require phramework/validate
```

### Parse an integer value

[](#parse-an-integer-value)

```
require './vendor/autoload.php';

use \Phramework\Validate\IntegerValidator;

$validator = new IntegerValidator(-1, 1);

$value = $validator->parse('0');

var_dump($value);
```

The above example will output:

```
int(0)

```

### Parse an object of strings

[](#parse-an-object-of-strings)

```
$personalInformationValidator = new ObjectValidator(
    (object) [
        'name' => new StringValidator(2, 30),
        'city' => new StringValidator(2, 30),
        'age' => new IntegerValidator(1, 200),
    ],
    ['name', 'city', 'age'], //required properties
    false //no additional properties allowed
);

$personalInformation = $validationModel->parse((object) [
    'name' => 'Jane Doe',
    'city' => 'Athens',
    'age' => 28
]);

print_r($personalInformation);
```

The above example will output:

```
stdClass Object
(
    [name] => Jane Doe
    [city] => Athens,
    [age] => 28
)

```

### Validating an array of enum strings

[](#validating-an-array-of-enum-strings)

```
    /*
     * A validator that allows you to pick one or two colors between blue, green and red
     */
    $colorsValidator = new ArrayValidator(
        1, //minItems
        2, //maxItems
        (new StringValidator()) //items
            ->setEnum([
                'blue',
                'green',
                'red',
            ]),
        true //unique items
    );

    /*
     * $parsedOneItem will be validated successfully
     */
    $parsedOneItem = $colorsValidator->parse(['blue']); //will be [blue]

    /*
     * $parsedTwoItems will be validated successfully
     */
    $parsedTwoItems = $colorsValidator->parse(['blue', 'red']); //will be [blue, red]

    /*
     * $resultOfZeroItemsStatus cannot be validated true the validator requires minItems of 1
     */
    $resultOfZeroItemsStatus = $colorsValidator->validate([]);
    $resultOfZeroItemsStatus->getStatus(); // will be false because validation failed
    /** @var \Phramework\Exceptions\IncorrectParameterException $exception in this case */
    $exception = $resultOfZeroItemsStatus->getException();
    $exception->getFailure(); // will be minItems

    /*
     * $resultOfIncorrectItemsStatus cannot be validated true because "yellow" is not an allowed item
     */
    $resultOfIncorrectItemsStatus = $colorsValidator->validate(['yellow']);
    $resultOfIncorrectItemsStatus->getStatus(); // will be false because validation failed
    /** @var \Phramework\Exceptions\IncorrectParameterException $exception in this case */
    $exception = $resultOfIncorrectItemsStatus->getException();
    $exception->getFailure(); // will be items

    /*
     * Following will throw \Phramework\Exceptions\IncorrectParameterException
     * with failure maxItems because validator requires maxItems 2
     */
    $colorsValidator
        ->parse([
            'blue',
            'green',
            'red'
        ]);
```

Check [wiki](https://github.com/phramework/validate/wiki) for more examples.

Development
-----------

[](#development)

### Install dependencies

[](#install-dependencies)

```
composer update
```

### Test and lint code

[](#test-and-lint-code)

```
composer test
composer lint
```

### Generate documentation

[](#generate-documentation)

```
composer doc
```

License
-------

[](#license)

Copyright 2015-2019 Xenofon Spafaridis

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

```
http://www.apache.org/licenses/LICENSE-2.0

```

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 98.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 ~58 days

Recently: every ~274 days

Total

41

Last Release

1465d ago

Major Versions

0.8.0 → 1.0.0-RC12016-05-22

0.9.0 → 1.0.0-RC32016-05-25

0.10.1 → 1.0.0-RC42017-10-24

0.10.2 → 1.1.02018-05-17

0.10.3 → 1.0.0-RC52019-03-08

PHP version history (6 changes)0.0.0PHP &gt;=5.6

1.0.0-RCPHP &gt;=7

0.10.3PHP ^7

1.2.0PHP ^7.1|^8.0.0

0.11.0PHP ^7.1

v0.12.0PHP ^7.1 || ^8.0.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/432379?v=4)[Xenofon Spafaridis](/maintainers/nohponex)[@nohponex](https://github.com/nohponex)

---

Top Contributors

[![nohponex](https://avatars.githubusercontent.com/u/432379?v=4)](https://github.com/nohponex "nohponex (157 commits)")[![alkallio](https://avatars.githubusercontent.com/u/1079045?v=4)](https://github.com/alkallio "alkallio (2 commits)")[![akalineskou](https://avatars.githubusercontent.com/u/3526365?v=4)](https://github.com/akalineskou "akalineskou (1 commits)")

---

Tags

json-schemaphpvalidation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phramework-validate/health.svg)

```
[![Health](https://phpackages.com/badges/phramework-validate/health.svg)](https://phpackages.com/packages/phramework-validate)
```

###  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)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[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)

PHPackages © 2026

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