Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Valider dynamiquement de la donnée avec Symfony
Search
Marion Hurteau
April 07, 2022
Programming
2
1k
Valider dynamiquement de la donnée avec Symfony
Symfony Live Paris - Avril 2022
Marion Hurteau
April 07, 2022
Tweet
Share
More Decks by Marion Hurteau
See All by Marion Hurteau
Les chaînes de caractères 101
marionleherisson
0
110
String usage: so many tools are already in your hands!
marionleherisson
1
150
How to dynamically validate data with Symfony
marionleherisson
0
630
La microtypographie au service de la lisibilité
marionleherisson
0
170
Other Decks in Programming
See All in Programming
リアクティブシステムの変遷から理解するalien-signals / Learning alien-signals from the evolution of reactive systems
yamanoku
2
1.2k
新卒から4年間、20年もののWebサービスと 向き合って学んだソフトウェア考古学
oguri
8
7.1k
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
370
Compose Hot Reload is here, stop re-launching your apps! (Android Makers 2025)
zsmb
1
120
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
610
パスキーのすべて / 20250324 iddance Lesson.5
kuralab
0
140
Day0 初心者向けワークショップ実践!ソフトウェアテストの第一歩
satohiroyuki
0
780
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
2.2k
爆速スッキリ! Rspack 移行の成果と道のり - Muddy Web #11
dora1998
1
210
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
170
Develop Faster With FrankenPHP
dunglas
2
3k
AI Coding Agent Enablement - エージェントを自走させよう
yukukotani
12
4.2k
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
12
1.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
135
33k
Testing 201, or: Great Expectations
jmmastey
42
7.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
500
Faster Mobile Websites
deanohume
306
31k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.6k
Building an army of robots
kneath
304
45k
Building a Modern Day E-commerce SEO Strategy
aleyda
39
7.2k
Transcript
Valider dynamiquement de la donnée avec Symfony Marion Hurteau github.com/MarionLeHerisson/validation
1
Hello World 👋 Marion Hurteau @MarionHerisson /MarionLeHerisson 📧
[email protected]
Architecture Logicielle @ESGI JoliCode depuis 2019 2
Hello World 👋 Nessie & Oscar 🐈 🌱 ~40
plantes 🖥💻 RPG 3
La Validation ? 4
5
Principe Objet Contrainte Validateur 6
Principe Objet Contrainte Validateur ✅ Violation[ ] ❌ Violation[...] 7
Contrainte Validateur Entité Contrainte Validateur 8
Violations ? 9
Les contraintes 10
Il en existe beaucoup ! Blank, NotBlank IsNull, NotNull IsTrue,
IsFalse Type, Length 11
Il en existe beaucoup ! Email, Regex Url, Hostname, Ip
CssColor NotCompromisedPassword 12
Il en existe beaucoup ! Date, DateTime, Time, Timezone Choice
Language, Locale, Country File, Image 13
Il en existe beaucoup ! Bic, Ibn, CardScheme Isbn, Issn,
Isin All, AtLeastOneOf, Sequentially 14
Il en existe beaucoup ! Compound 15
Il en existe beaucoup ! Compound Callback 16
Il en existe beaucoup ! Compound Callback Expression 17
Il en existe beaucoup ! Compound Callback Expression Valid 18
Aller un peu plus loin 19
UniqueEntity 20
Auto-mapping validation 21
Auto-mapping validation 22
Différentes manières de valider 23
Sur une propriété 24
Dans un formulaire 25
Sur une méthode (un getter ou autre) 26
Sur une classe entière 27
Sur une classe entière 28
Dans mon code Lors d’un submit Quand ? 29
Groupes de validation 30
Validation personnalisée 31
Contrainte personnalisée 32
Contrainte personnalisée Une contrainte Un validateur 33
Contrainte personnalisée 34
Contrainte personnalisée 35
Dynamiques ? 36
Attends, c’est quoi un Pokémon ? 37
Attends, c’est quoi un Pokémon ? plante feu eau 38
Attends, c’est quoi un Pokémon ? niv. 18 niv. 36
39
Attends, c’est quoi un Pokémon ? 40
Attends, c’est quoi un Pokémon ? 41
Attends, c’est quoi un Pokémon ? 42
Attends, c’est quoi un Pokémon ? 43
niv. 18 niv. 36 Cas d’utilisation 44
Cas d’utilisation POST /evolution/create 45
Cas d’utilisation 46
Cas d’utilisation 47
Avec une Callback 48
Dans le controller 49
L’entité 50
Les contraintes dans l’entité 51
Les contraintes dans l’entité 52
Les contraintes dans l’entité 53
Les contraintes dans l’entité 54
Les contraintes dans l’entité 55
La callback (1/2) 56
La callback (2/2) 57
La callback (2/2) 58
ExecutionContextInterface ? 59
Design 👍 Rapide 60
Design 👍 Rapide 👎 Réutilisabilité 👎 Taille de la méthode
/ classe 👎 Testabilité 61
62
Design 👉 Externaliser les contraintes 👉 DIC 63
Avec des contraintes externes 64
La Constraint 65
La Constraint 66
Ajoutons une interface ✨ 67
Définition d’un type 68
Définition d’un type 69
On ajoute des tags 70
ContainerInterface 71
Le ConstraintValidator (1/2) 72
Le ConstraintValidator (2/2) 73
74
75 D’autres cas d’utilisation
TL;DR: 👉 Validez ! ✨ $context->getValidator()->inContext($context) 👉 Contrainte externe :
- Maintenable - Testable - Réutilisable 👉 _instanceof & !tagged_locator - + default_index_method 76
Et ensuite ? ✅ Validées 👉 Persister Avec Doctrine ?
En json ? 77
Merci ! github.com/MarionLeHerisson/validation 78
Des questions ? github.com/MarionLeHerisson/validation @MarionHerisson
[email protected]
79