https://github.com/fey/php-oop-project-lvl1
Data validator is a library that can be used to check the correctness of any data.
https://github.com/fey/php-oop-project-lvl1
data-validator hexlet oop php validator
Last synced: 7 months ago
JSON representation
Data validator is a library that can be used to check the correctness of any data.
- Host: GitHub
- URL: https://github.com/fey/php-oop-project-lvl1
- Owner: fey
- Created: 2021-01-29T16:22:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-04T05:05:27.000Z (almost 5 years ago)
- Last Synced: 2025-02-01T01:52:16.623Z (12 months ago)
- Topics: data-validator, hexlet, oop, php, validator
- Language: PHP
- Homepage: https://ru.hexlet.io/programs/php-oop/projects/60
- Size: 30.3 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/fey/php-oop-project-lvl1/actions)
[](https://codeclimate.com/github/fey/php-oop-project-lvl1/maintainability)
[](https://codeclimate.com/github/fey/php-oop-project-lvl1/test_coverage)
### Description
Data validator is a library that can be used to check the correctness of any data.
### Prequesites
* PHP >=7.4
* Composer
### Commands
```shell
$ make start
$ make test
```
### Usage
```php
required()->string();
$schema->isValid('what does the fox say'); // true
$schema->isValid(''); // false
// числа
$schema = $v->required()->number()->positive();
$schema->isValid(-10); // false
$schema->isValid(10); // true
// массив с поддержкой проверки структуры
$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
// Добавление нового валидатора
$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
```