Skip to content
Easy to use PHP validator
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Core/Validator
test
.drone.yml
.gitignore
Makefile
README.md
composer.json

README.md

Build Status

core-validator

Install

Install via composer

{
	"require": {
		"core/validator"  : "dev-master"
	}
}

Simple Way to Validate Data

Using the builder class, you can chain together clear business logic to validate values:

<?php

use Core\Validator as val;

try {
	$val = new val\Builder('Philip Whitt');
	$val->notEmpty()->isOnlyAlpha()->hasLengthGt(2)->get();

} catch (val\EmptyValueException $e) {
	// Handle empty value error
} catch (val\AlphaException $e) {
	// Handle non alpha error
} catch (val\InvalidLengthException $e) {
	// Handle length error
}

See test/BuilderTest.php for more working examples

Validate User Input

Using the ParamFactory, its very easy to validate user input from get, post or releated data. Example of a $_POST of name=philip&id=1:

<?php

use Core\Validator as val;

$validator = new val\ParamFactory($_REQUEST);

// Validate "id"
try {
	$id = $validator->getVar('id')->notEmpty()->isOnlyNum()->get();
} catch (val\Exception $e) {
	// Handle id error
}

// Validate "name"
try {
	$name = $validator->getVar('name')->notEmpty()->isOnlyAlpha()->hasLengthGt(2)->get();
} catch (val\Exception $e) {
	// Handle name error
}

See test/ParamFactoryTest.php for more working examples

Unit Tests

Run tests using:

$ phpunit test
You can’t perform that action at this time.