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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
CSC307 Lecture 11
javiergs
PRO
0
580
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
160
AI時代の認知負荷との向き合い方
optfit
0
180
ノイジーネイバー問題を解決する 公平なキューイング
occhi
0
120
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
110
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
300
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
260
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
120
AIプロダクト時代のQAエンジニアに求められること
imtnd
1
390
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
780
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
440
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
WCS-LA-2024
lcolladotor
0
460
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Documentation Writing (for coders)
carmenintech
77
5.3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
230
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Statistics for Hackers
jakevdp
799
230k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
[SF Ruby Conf 2025] Rails X
palkan
1
780
Design in an AI World
tapps
0
150
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
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