digitalrevolution / symfony-validation-shorthand
Validation shorthand for symfony
Installs: 62 449
Dependents: 2
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 3
Open Issues: 3
Type:symfony-bundle
Requires
- php: >=8.1
- symfony/validator: ^6.2||^7.0
Requires (Dev)
- digitalrevolution/phpunit-file-coverage-inspection: ^v2.0
- phpmd/phpmd: ^2.14
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-12-11 07:55:13 UTC
README
Symfony Validation Shorthand
A validation shorthand component for Symfony, similar to the syntax in the "illuminate/validator" package for Laravel.
Installation
Include the library as dependency in your own project via:
composer require "digitalrevolution/symfony-validation-shorthand"
Usage
Example
$rules = [ 'name.first_name' => 'required|string|min:5', 'name.last_name' => 'string|min:6', // last name is optional 'email' => 'required|email', 'password' => 'required|string|between:7,40', 'phone_number' => 'required|regex:/^020\d+$/', 'news_letter' => 'required|bool', 'tags?.*' => 'required|string' // if tags is set, must be array of all strings with count > 0 ]; // transform the rules into a Symfony Constraint tree $constraint = (new ConstraintFactory)->fromRuleDefinitions($rules); // validate the data $violations = \Symfony\Component\Validator\Validation::createValidator()->validate($data, $constraint);
Validates:
[
'name' => [
'first_name' => 'Peter',
'last_name' => 'Parker'
],
'email' => 'example@example.com',
'password' => 'hunter8',
'phone_number' => '0201234678',
'news_letter' => 'on',
'tags' => ['sports', 'movies', 'music']
]
Documentation
Full syntax and examples:
About us
At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? We are looking for developers.