https://github.com/solar05/php-oop-project-lvl1
Php library that validates data, check readme for use cases.
https://github.com/solar05/php-oop-project-lvl1
library oop php validation validator
Last synced: 12 days ago
JSON representation
Php library that validates data, check readme for use cases.
- Host: GitHub
- URL: https://github.com/solar05/php-oop-project-lvl1
- Owner: solar05
- Created: 2021-01-29T20:33:08.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-02T11:08:27.000Z (over 4 years ago)
- Last Synced: 2025-03-04T08:45:46.074Z (over 1 year ago)
- Topics: library, oop, php, validation, validator
- Language: PHP
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Hexlet tests and linter status:
[](https://github.com/solar05/php-oop-project-lvl1/actions)
## Description;
PHP library for validation.
## Usage example:
```PHP
required()->string();
$schema->isValid('what does the fox say'); // true
$schema->isValid(''); // false
// numbers
$schema = $v->required()->number()->positive();
$schema->isValid(-10); // false
$schema->isValid(10); // true
// array with checking support
$schema = $v->array()->sizeof(2)->shape([
'name' => $v->string()->required(),
'age' => $v->number()->positive(),
]);
$schema->isValid(['name' => 'kolya', 'age' => 100]); // true
$schema->isValid(['name' => '', 'age' => null]); // false
// New validator adding
$fn = fn($value, $start) => str_starts_with($value, $start);
$v->addValidator('string', 'startWith', $fn);
$schema = $v->string()->test('startWith', 'H');
$schema->isValid('exlet'); // false
$schema->isValid('Hexlet'); // true
```