|
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. |
0 commit comments