Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/123inkt/symfony-validation-shorthand
Validation shorthand notation for symfony
https://github.com/123inkt/symfony-validation-shorthand
symfony symfony-bundle validation
Last synced: 9 days ago
JSON representation
Validation shorthand notation for symfony
- Host: GitHub
- URL: https://github.com/123inkt/symfony-validation-shorthand
- Owner: 123inkt
- License: mit
- Created: 2019-10-15T18:04:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T07:46:43.000Z (about 2 months ago)
- Last Synced: 2024-11-15T21:59:54.593Z (about 1 month ago)
- Topics: symfony, symfony-bundle, validation
- Language: PHP
- Homepage:
- Size: 287 KB
- Stars: 9
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF)](https://php.net/)
[![Minimum Symfony Version](https://img.shields.io/badge/symfony-%3E%3D%206.2-brightgreen)](https://symfony.com/doc/current/validation.html)
![Run tests](https://github.com/123inkt/symfony-validation-shorthand/actions/workflows/test.yml/badge.svg)# 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**
```php
$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' => '[email protected]',
'password' => 'hunter8',
'phone_number' => '0201234678',
'news_letter' => 'on',
'tags' => ['sports', 'movies', 'music']
]
```## Documentation
Full syntax and examples:
- [Shorthands](docs/available-shorthands.md)
- [Data validation](docs/data-validation.md)
- [Traversable data](docs/traversable-data.md)
- [Examples](docs/examples.md)## 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](https://www.werkenbij123inkt.nl/zoek-op-afdeling/it).