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
1.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
130
String usage: so many tools are already in your hands!
marionleherisson
1
200
How to dynamically validate data with Symfony
marionleherisson
0
870
La microtypographie au service de la lisibilité
marionleherisson
0
210
Other Decks in Programming
See All in Programming
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
130
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
5
4.2k
Architectural Extensions
denyspoltorak
0
240
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
260
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Data-Centric Kaggle
isax1015
2
700
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
700
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
600
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
2
440
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
120
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
180
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
1k
Technical Leadership for Architectural Decision Making
baasie
1
220
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Abbi's Birthday
coloredviolet
1
4.5k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Designing for humans not robots
tammielis
254
26k
Done Done
chrislema
186
16k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
72
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
55
49k
The Cult of Friendly URLs
andyhume
79
6.8k
Code Review Best Practice
trishagee
74
19k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
110
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