Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit c016bba

Browse files
authored
Merge pull request #23 from programmatordev/1.x
1.x
2 parents 7da4127 + ec2ce8b commit c016bba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2807
-1
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/composer.lock
2+
/composer.phar
3+
/phpunit.xml
4+
/.phpunit.result.cache
5+
/vendor/
6+
/logs/
7+
/.idea
8+
/index.php

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
1-
# yet-another-php-validator
1+
# Yet Another PHP Validator
2+
3+
PHP validator focused on validating development code with expressive error messages.
4+
5+
> **Note**
6+
> This library is not in version 1.x mainly because there are few available rules.
7+
> Hopefully, that will change in the near future.
8+
9+
## Requirements
10+
11+
- PHP 8.1 or higher.
12+
13+
## Installation
14+
15+
You can install the library via [Composer](https://getcomposer.org/):
16+
17+
```bash
18+
composer require programmatordev/yet-another-php-validator
19+
```
20+
21+
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
22+
23+
```php
24+
require_once 'vendor/autoload.php';
25+
```
26+
27+
## Basic Usage
28+
29+
Simple usage looks like:
30+
31+
```php
32+
use ProgrammatorDev\YetAnotherPhpValidator\Rule;
33+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
34+
35+
// Do this...
36+
$validator = Validator::notBlank()->greaterThanOrEqual(18);
37+
38+
// Or this...
39+
$validator = new Validator(
40+
new Rule\NotBlank(),
41+
new Rule\GreaterThanOrEqual(18)
42+
);
43+
44+
// Validate with these:
45+
$validator->validate(16); // returns bool: false
46+
$validator->assert(16, 'Age'); // throws exception: The "Age" value should be greater than or equal to "18", "16" given.
47+
```
48+
49+
## Documentation
50+
51+
- [Get Started](docs/01-get-started.md)
52+
- [Usage](docs/02-usage.md)
53+
- [Usage](docs/02-usage.md#usage)
54+
- [Methods](docs/02-usage.md#methods)
55+
- [Error Handling](docs/02-usage.md#error-handling)
56+
- [Custom Error Messages](docs/02-usage.md#custom-error-messages)
57+
- [Rules](docs/03-rules.md)
58+
- [Custom Rules](docs/04-custom-rules.md)
59+
60+
## Contributing
61+
62+
Any form of contribution to improve this library (including requests) will be welcome and appreciated.
63+
Make sure to open a pull request or issue.
64+
65+
## Acknowledgments
66+
67+
This library is inspired by [respect/validation](https://github.com/Respect/Validation) and [symfony/validator](https://github.com/symfony/validator).
68+
69+
## License
70+
71+
This project is licensed under the MIT license.
72+
Please see the [LICENSE](LICENSE) file distributed with this source code for further information regarding copyright and licensing.

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "programmatordev/yet-another-php-validator",
3+
"description": "PHP validator focused on validating development code with expressive error messages",
4+
"type": "library",
5+
"keywords": ["PHP", "PHP8", "Validator", "Validation"],
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "André Pimpão",
10+
"email": "[email protected]",
11+
"homepage": "https://programmator.dev/"
12+
}
13+
],
14+
"require": {
15+
"php": ">=8.1"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "^10.0",
19+
"symfony/var-dumper": "^6.3"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"ProgrammatorDev\\YetAnotherPhpValidator\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"ProgrammatorDev\\YetAnotherPhpValidator\\Test\\": "tests/"
29+
}
30+
},
31+
"config": {
32+
"optimize-autoloader": true,
33+
"sort-packages": true
34+
}
35+
}

docs/01-get-started.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Get Started
2+
3+
- [Requirements](#requirements)
4+
- [Installation](#installation)
5+
- [Basic Usage](#basic-usage)
6+
7+
## Requirements
8+
9+
- PHP 8.1 or higher.
10+
11+
## Installation
12+
13+
You can install the library via [Composer](https://getcomposer.org/):
14+
15+
```bash
16+
composer require programmatordev/yet-another-php-validator
17+
```
18+
19+
To use the library, use Composer's [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading):
20+
21+
```php
22+
require_once 'vendor/autoload.php';
23+
```
24+
25+
## Basic Usage
26+
27+
Simple usage looks like:
28+
29+
```php
30+
use ProgrammatorDev\YetAnotherPhpValidator\Rule;
31+
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
32+
33+
// Do this...
34+
$validator = Validator::notBlank()->greaterThanOrEqual(18);
35+
36+
// Or this...
37+
$validator = new Validator(
38+
new Rule\NotBlank(),
39+
new Rule\GreaterThanOrEqual(18)
40+
);
41+
42+
// Validate with these:
43+
$validator->validate(16); // returns bool: false
44+
$validator->assert(16, 'Age'); // throws exception: The "Age" value should be greater than or equal to "18", "16" given.
45+
```

0 commit comments

Comments
 (0)