Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: fluent-validator
type: php
docroot: ""
php_version: "8.2"
php_version: "8.4"
webserver_type: nginx-fpm
xdebug_enabled: false
additional_hostnames: []
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.2', '8.3', '8.4']
php: ['8.4', '8.5']

steps:
- name: Checkout code
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
A [Symfony Validator](https://symfony.com/doc/current/validation.html) wrapper that enables fluent-style validation for raw values,
offering an easy-to-use and intuitive API to validate user input or other data in a concise and readable manner.

> [!NOTE]
> This library will always (try to) be in sync with the latest Symfony Validator version.

## Features

- 🌊 **Fluent-style validation:** Chain validation methods for better readability and flow.
- 🤘 **Constraints autocompletion:** Enables IDE autocompletion for available constraints.
- 🔥 **Three validation methods:** Use `validate`, `assert`, or `isValid` based on the context (i.e., collect errors or throw exceptions).
- ⚙️ **Custom constraints:** Easily integrate custom validation logic with Symfony's Validator system.
- ⚙️ **Custom constraints:** Integrate custom validation logic with Symfony's Validator system.
- 💬 **Translations support:** Translate validation error messages into multiple languages.

## Table of Contents
Expand All @@ -32,7 +35,7 @@ offering an easy-to-use and intuitive API to validate user input or other data i

## Requirements

- PHP 8.2 or higher.
- PHP 8.4 or higher.

## Installation

Expand Down Expand Up @@ -60,7 +63,7 @@ if ($errors->count() > 0) {
}
```

Constraints autocompletion is available in IDEs like PhpStorm.
Constraint autocompletion is available in IDEs like PhpStorm.
The method names match Symfony constraints but with a lowercase first letter:

- `NotBlank` => `notBlank`
Expand Down Expand Up @@ -124,10 +127,10 @@ try {
Validator::notBlank()->email()->assert($email);
}
catch (ValidationFailedException $exception) {
// exception message will always be the first error thrown
// the exception message will always be the first error thrown
$message = $exception->getMessage();
// value that failed validation
$value = $exception->getInvalidValue();
$invalidValue = $exception->getInvalidValue();
// get access to all errors
// returns a ConstraintViolationList object like in the validate method
$errors = $exception->getViolations();
Expand Down Expand Up @@ -177,7 +180,7 @@ and keeps the fluent-style validation:
```php
use ProgrammatorDev\FluentValidator\Validator;

// validate that array should have at least one value
// validate that the array should have at least one value
// and each value should be between 0 and 100
$errors = Validator::count(min: 1)
->all(Validator::range(min: 0, max: 100)->toArray())
Expand Down
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require __DIR__ . '/../vendor/autoload.php';

$app = new Application();

$app->add(new CreateStaticValidatorInterfaceCommand());
$app->add(new CreateChainedValidatorInterfaceCommand());
$app->add(new CreateValidatorInterfacesCommand());
$app->addCommand(new CreateStaticValidatorInterfaceCommand());
$app->addCommand(new CreateChainedValidatorInterfaceCommand());
$app->addCommand(new CreateValidatorInterfacesCommand());

$app->run();
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"license": "MIT",
"authors": [
{
"name": "André Pimpão",
"email": "a.pimpao@programmator.dev",
"name": "Programmator",
"email": "hotline@programmator.dev",
"homepage": "https://programmator.dev"
}
],
"require": {
"php": ">=8.2",
"symfony/config": "^7.3",
"symfony/translation": "^7.3",
"symfony/validator": "^7.3"
"php": ">=8.4",
"symfony/config": "^8.0",
"symfony/translation": "^8.0",
"symfony/validator": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^11.5",
"symfony/console": "^7.3",
"symfony/var-dumper": "^7.3",
"symfony/console": "^8.0",
"symfony/var-dumper": "^8.0",
"wyrihaximus/list-classes-in-directory": "^1.7"
},
"autoload": {
Expand Down
Loading