Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (16) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-09-16 (16 days ago) | Not yet rated by the users | Total: Not yet counted | Not yet ranked |
Version | License | PHP version | Categories | |||
valideto 1.0 | Custom (specified... | 5 | PHP 5, Validation |
Description | Author | |
This package can validate data values with preset and custom rules. |
A simple PHP package for data validation with extensive preset rules and custom rules.
You can start it from composer. Go to your terminal and run this command from your project root directory.
composer require hashemi/valideto
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
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'],
]);
Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file, 2 directories) | ||||
tests (1 file, 2 directories) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Engine (1 file) | ||||
Rules (2 files, 1 directory) | ||||
Valideto.php | Class | Class source |
Files | / | src | / | Rules |
File | Role | Description | ||
---|---|---|---|---|
CustomRule (1 file) | ||||
DefaultRules.php | Class | Class source | ||
DefaultRulesInterface.php | Class | Class source |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
Helpers (1 file) | ||||
Valideto (5 files) | ||||
bootstrap.php | Aux. | Auxiliary script |
Files | / | tests | / | Valideto |
File | Role | Description |
---|---|---|
ValidetoArrayTest.php | Class | Class source |
ValidetoEngineTest.php | Class | Class source |
ValidetoMiscTest.php | Class | Class source |
ValidetoNumberTest.php | Class | Class source |
ValidetoStringTest.php | Class | Class source |
Version Control | Unique User Downloads | |||||||
100% |
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.