PHPackages                             graze/config-validation - 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. graze/config-validation

ActiveLibrary

graze/config-validation
=======================

validate and populate arrays and objects

0.2(7y ago)18951MITPHPPHP ^5.6 | ^7.0

Since Oct 2Pushed 7y ago10 watchersCompare

[ Source](https://github.com/graze/config-validation)[ Packagist](https://packagist.org/packages/graze/config-validation)[ Docs](https://github.com/graze/config-validation)[ RSS](/packages/graze-config-validation/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (1)

config-validation
=================

[](#config-validation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0992064bdbabd41bf80fa199fd7e68c8a98bfac0787a1489c729b46300bfb526/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a652f636f6e6669672d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/config-validation)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/05575497a64e3014e2e8ceb20a0eeefdaa6bc2ecc91aac8f9442d1477a5d0446/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6772617a652f636f6e6669672d76616c69646174696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/graze/config-validation)[![Coverage Status](https://camo.githubusercontent.com/ed37c8dcdb6eff98266efd835d4c5d34180e5ed8585132d709bf3d26785d67df/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6772617a652f636f6e6669672d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/config-validation/code-structure)[![Quality Score](https://camo.githubusercontent.com/7f11cf195b3f95a756a03eeabd4b89fc80c65eb9cce6f4fe5f2966c8056f5454/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6772617a652f636f6e6669672d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/config-validation)[![Total Downloads](https://camo.githubusercontent.com/67d24aa9cc1e8985ff19c326325620da883b1ebf7191c853903a2373a27b0243/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a652f636f6e6669672d76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/config-validation)

Config Validation checks an input against a code defined schema for validation using short notation syntax.

It then populates optional fields with default data.

Install
-------

[](#install)

Via Composer

```
composer require graze/config-validation
```

Usage
-----

[](#usage)

### Long path definition

[](#long-path-definition)

```
use Respect\Validation\Validator as v;

$validator = (new ArrayValidator())
    ->required('key', v::stringType())
    ->optional('parent.child', v::intVal(), 1)
    ->optional('parent.second', v::stringType()->date());
```

### Using children

[](#using-children)

```
$validator = Validator::arr()
    ->required('key', v::stringType())
    ->addChild('parent', Validator::arr()
        ->optional('child', v::intVal(), 1)
        ->optional('second', v::stringType()->date()
    );
```

### Validating with your validator

[](#validating-with-your-validator)

```
function thing (array $input) {
    return $validator->validate($input);
}

thing(['key' => 'value'])
// ['key' => 'value', 'parent' => ['child' => 1, 'second' => null]]
thing();
// throws new ConfigValidationFailed
thing(['key' => 'input', ['parent' => ['child' => 2]])
// ['key' => 'input', ['parent' => ['child' => 2, 'second' => null]]
thing(['key' => 'input', ['parent' => ['second' => '111']])
// throws new ConfigValidationFailed('expected data for parent.second')
thing(['key' => 'input', ['parent' => ['second' =>
```

### Validating array items with variable keys

[](#validating-array-items-with-variable-keys)

```
$childValidator = Validate::object()
    ->required('key->item', v::intVal()->min(2)->max(4))
    ->optional('key->second', v::stringType(), 'name');
$validator = Validate::object()
    ->required('items', v::arrayVal()->each(
        $childValidator->getValidator()
    ));

function thing ($input) {
    return $validator->validate($input);
}

thing((object) ['items' => [
    (object) ['key' => 3],
    ]]);
// (object) ['items' => [
//     (object) ['key' => (object) ['item' => 3, 'second' => 'name']]
// ]]
```

Testing
-------

[](#testing)

```
make build test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Harry Bragg](https://github.com/h-bragg)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Total

3

Last Release

2839d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/637788?v=4)[graze.com](/maintainers/graze)[@graze](https://github.com/graze)

---

Tags

grazeconfig-validation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graze-config-validation/health.svg)

```
[![Health](https://phpackages.com/badges/graze-config-validation/health.svg)](https://phpackages.com/packages/graze-config-validation)
```

###  Alternatives

[graze/dog-statsd

DataDog StatsD Client

413.1M3](/packages/graze-dog-statsd)[graze/parallel-process

run a pool of processes simultaneously

103214.3k1](/packages/graze-parallel-process)[graze/telnet-client

Telnet client written in PHP

50233.9k4](/packages/graze-telnet-client)

PHPackages © 2026

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