PHP Classes

Valideto: Validate data values with preset and custom rules

Recommend this page to a friend!
  Info   View files Documentation   View files View files (16)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 64 This week: 1All time: 10,371 This week: 560Up
Version License PHP version Categories
valideto 1.0Custom (specified...5PHP 5, Validation
Description 

Author

This package can validate data values with preset and custom rules.

It can take an associative array with data values to be validated and performs validation checks according to a list of rules.

The validation rules can those common rules implemented by the class like: required, email address, numeric, array, distinct, integer, float, comparison, date, etc..

It also supports custom validation rules that can be implemented by custom classes that implement the custom rule interface.

Picture of Hashemi Rafsan
  Performance   Level  
Name: Hashemi Rafsan <contact>
Classes: 7 packages by
Country: Bangladesh Bangladesh
Age: 28
All time rank: 382646 in Bangladesh Bangladesh
Week rank: 416 Up9 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 1x

Documentation

Valideto

A simple PHP package for data validation with extensive preset rules and custom rules.

Installation

You can start it from composer. Go to your terminal and run this command from your project root directory.

composer require hashemi/valideto

Usage

After Complete installation, It's time to check how to use Valideto easily.

<?php

use Hashemi\Valideto\Valideto;

$data = [
    'first_name' => "Hashemi",
    'last_name'  => "Rafsan" ,
    'email' => 'rafsan@xyz.com'
];

$validator = new Valideto($data, [
   'first_name' => ['required', 'string'],
   'last_name'  => ['required', 'string'],
   'email' => ['required', 'email']
]);

// Call "validate" for validating your data
$validator->validate();

if ($validator->success()) {
    // do something...
}

if ($validator->fails()) {
    // do something if fails
}

You should be use that when you want to validate your data. Valideto expose many default rules for validation but if user need to make by own they can also do that. Already there is option to change the default rules logic if you don't like to use. Valideto provide an interface for change default validation rules logic.

Then let's check how you can do that but recommended to not change it, Once if you change it's you will be liable to result

<?php

use Hashemi\Valideto\Rules\DefaultRulesInterface;
use Hashemi\Valideto\Valideto;

class OwnRulesClass implements DefaultRulesInterface
{
    public function setData(array $data): self {}
    public function isRequired(string $key): bool {}
    public function isNullable(string $key): bool {}
    public function isArray(string $key, bool $nullable = false): bool {}
    public function isAssoc(string $key, bool $nullable = false): bool {}
    public function isString(string $key, bool $nullable = false): bool {}
    public function isNumeric(string $key, bool $nullable = false): bool {}
    public function isDistinct(string $key, bool $nullable = false): bool {}
    public function isInteger(string $key, bool $nullable = false): bool {}
    public function isFloat(string $key, bool $nullable = false): bool {}
    public function isBoolean(string $key, bool $nullable = false): bool {}
    public function isSize(string $key, int $length, bool $nullable = false): bool {}
    public function isMax(string $key, int $value, bool $nullable = false): bool {}
    public function isMin(string $key, int $value, bool $nullable = false): bool {}
}

$data = [
    'first_name' => "Hashemi",
    'last_name'  => "Rafsan" ,
    'email' => 'rafsan@xyz.com'
];

$validator = new Valideto($data, [
   'first_name' => ['required', 'string'],
   'last_name'  => ['required', 'string'],
   'email' => ['required', 'email']
]);

// Call "validate" for validating your data
$validator->setRulesClass(new OwnRulesClass());

$validator->validate();

Do it, your own risk :D

List of Default Rules:

required

required should be use for when you expect that value in your data

Example:

$validator = new Valideto($data, [
   'first_name' => ['required'],
]);

max

max should be use for when you need to check if value exceed max value or not

Example:

$validator = new Valideto($data, [
   'age' => ['max:24'],
]);

min

min should be use for when you need to check if value have at least minimum value or not

Example:

$validator = new Valideto($data, [
   'age' => ['min:24'],
]);

gt

gt should be use for when you need to check if value greater than or not

Example:

$validator = new Valideto($data, [
   'age' => ['gt:24'],
]);

gte

gte should be use for when you need to check if value greater than or equal

Example:

$validator = new Valideto($data, [
   'age' => ['gte:24'],
]);

lt

lt should be use for when you need to check if value less than or not

Example:

$validator = new Valideto($data, [
   'age' => ['lt:24'],
]);

lte

lte should be use for when you need to check if value less than or equal

Example:

$validator = new Valideto($data, [
   'age' => ['lte:24'],
]);

eq

eq should be use for when you need to check if value equal

Example:

$validator = new Valideto($data, [
   'age' => ['eq:integer|float|string|boolean:24'],
]);

nullable

nullable should be use for when value is not required

Example:

$validator = new Valideto($data, [
   'age' => ['nullable'],
]);

distinct

distinct should be use for when you don't duplicate value in array

Example:

$validator = new Valideto($data, [
   'hobbies' => ['array', 'distinct'],
]);

date

date should be use for when you check date is valid or not

Example:

$validator = new Valideto($data, [
   'start_date' => ['date'],
]);

date_format

date_format should be use for when you check date format is valid or not

Example:

$validator = new Valideto($data, [
   'start_date' => ['date_format:Y-m-d'],
]);

array

array should be use for when you check the data is array or not

Example:

$validator = new Valideto($data, [
   'start_date' => ['date_format:Y-m-d'],
]);

url

url should be use for when you check the data is url or not

Example:

$validator = new Valideto($data, [
   'website' => ['url'],
]);

ip

ip should be use for when you check the data is ip or not

Example:

$validator = new Valideto($data, [
   'ip' => ['ip'],
]);

boolean

boolean should be use for when you check the data is boolean or not

Example:

$validator = new Valideto($data, [
   'is_enable' => ['boolean'],
]);

email

email should be use for when you check the data is email or not

Example:

$validator = new Valideto($data, [
   'email' => ['email'],
]);

string

string should be use for when you check the data is string or not

Example:

$validator = new Valideto($data, [
   'first_name' => ['string'],
]);

numeric

numeric should be use for when you check the data is numeric or not

Example:

$validator = new Valideto($data, [
   'id' => ['numeric'],
]);

integer

integer should be use for when you check the data is integer or not

Example:

$validator = new Valideto($data, [
   'id' => ['integer'],
]);

float

float should be use for when you check the data is float or not

Example:

$validator = new Valideto($data, [
   'price' => ['float'],
]);

assoc

assoc should be use for when you check the data is associative array or not

Example:

$validator = new Valideto($data, [
   'hobbies' => ['array', 'assoc'],
]);

Contributing

Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 2 directories)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
Files folder imageEngine (1 file)
Files folder imageRules (2 files, 1 directory)
  Plain text file Valideto.php Class Class source

  Files folder image Files  /  src  /  Engine  
File Role Description
  Plain text file ValidetoEngine.php Class Class source

  Files folder image Files  /  src  /  Rules  
File Role Description
Files folder imageCustomRule (1 file)
  Plain text file DefaultRules.php Class Class source
  Plain text file DefaultRulesInterface.php Class Class source

  Files folder image Files  /  src  /  Rules  /  CustomRule  
File Role Description
  Plain text file CustomRuleInterface.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageHelpers (1 file)
Files folder imageValideto (5 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  Helpers  
File Role Description
  Plain text file MyCustomRule.php Class Class source

  Files folder image Files  /  tests  /  Valideto  
File Role Description
  Plain text file ValidetoArrayTest.php Class Class source
  Plain text file ValidetoEngineTest.php Class Class source
  Plain text file ValidetoMiscTest.php Class Class source
  Plain text file ValidetoNumberTest.php Class Class source
  Plain text file ValidetoStringTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:64
This week:1
All time:10,371
This week:560Up