core / validator
Installs: 274
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/core/validator
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2025-09-26 10:14:34 UTC
README
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