PHPackages                             mcvalidator/mcvalidator-php - 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. mcvalidator/mcvalidator-php

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

mcvalidator/mcvalidator-php
===========================

It's always \[undefined index\] somewhere in PHP

v0.0.12-alpha(8y ago)33.8k[3 issues](https://github.com/mcvalidator/mcvalidator-php/issues)MITPHP

Since Apr 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mcvalidator/mcvalidator-php)[ Packagist](https://packagist.org/packages/mcvalidator/mcvalidator-php)[ RSS](/packages/mcvalidator-mcvalidator-php/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (4)Versions (13)Used By (0)

McValidator(PHP) [![Build Status](https://camo.githubusercontent.com/012f4a0673d7366e7fb4c83d3123144deb74b0a20c43b991cf8fa45c13ff3c4b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6376616c696461746f722f6d6376616c696461746f722d7068702e737667)](https://travis-ci.org/mcvalidator/mcvalidator-php) [![Latest Stable Version](https://camo.githubusercontent.com/03a3d0503d3815aff417a72d7765069a3173184a6ce7fe0cf71c2193748667f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6376616c696461746f722f6d6376616c696461746f722d7068702e737667)](https://packagist.org/packages/mcvalidator/mcvalidator-php) [![Total Downloads](https://camo.githubusercontent.com/f61c522e11dc53e05d9aeb213e49a6e6b5bad5ea716dec38ff15b90dfc889dc9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6376616c696461746f722f6d6376616c696461746f722d7068702e737667)](https://packagist.org/packages/mcvalidator/mcvalidator-php) [![Latest Unstable Version](https://camo.githubusercontent.com/92f57d5e4472042814222f2b1ff3ba3344b3cd60a0a2ef3b90e09d257721b406/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6d6376616c696461746f722f6d6376616c696461746f722d7068702e737667)](https://packagist.org/packages/mcvalidator/mcvalidator-php) [![License](https://camo.githubusercontent.com/d371b835c493db137e5a7f3fcdb89111043b6bd2a32e248c6ca3a02435380fac/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6376616c696461746f722f6d6376616c696461746f722d7068702e737667)](https://github.com/mcvalidator/mcvalidator-php/blob/master/LICENSE)
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#mcvalidatorphp-----)

It's always \[undefined index\] somewhere in PHP.

McValidator is written to provide a way to validate and sanitize data

Example 1:

```
use McValidator as MV;

// Builder is important because we can chain validator with them without
// too much work.
$builder = MV\valid('rule/is-string');

// Build the pipe
$pipe = $builder->build();

// Pump the value through the pipe
// Result contains the value and also informations about
// the runtime, such as errors and messages
$result = $pipe->pump(10);

// Gets the runtime state
$state = $result->getState();

// Gets the message of the head(first item) of errors
echo $state->getErrors()->head()->getMessage(); // Value is not a string

// We need more!
$builder2 = MV\shape_of([
    'a' => $builder
]);

$pipe2 = $builder2->build();

$result2 = $pipe2->pump(dict([
    'a' => 10
]));

// Gets the runtime state
$state2 = $result2->getState();

// Gets the message of the head(first item) of errors
echo $state2->getErrors()->head()->getMessage(); // outputs `Value is not a string`

// Gets the field path of the error!
echo $state2->getErrors()->head()->getStringPath('/' //
