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
890
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
String usage: so many tools are already in your hands!
marionleherisson
1
83
How to dynamically validate data with Symfony
marionleherisson
0
510
La microtypographie au service de la lisibilité
marionleherisson
0
96
Other Decks in Programming
See All in Programming
Three ways to use AI on Android: The Good, the Bad and the Ugly
marxallski
0
110
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.8k
Ruby GitHub Packages
bkuhlmann
0
640
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
440
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
220
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
220
Hanami and htmx
bkuhlmann
0
220
StoreKit2によるiOSのアプリ内課金のリニューアル
kangnux
0
120
Anthropic Cookbook のおすすめレシピ
schroneko
7
1.1k
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1k
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
760
Ruby Pattern Matching
bkuhlmann
0
930
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
43
6.8k
Typedesign – Prime Four
hannesfritz
36
2.1k
How STYLIGHT went responsive
nonsquared
92
4.8k
A better future with KSS
kneath
231
16k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
4 Signs Your Business is Dying
shpigford
176
21k
Why Our Code Smells
bkeepers
PRO
331
56k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
8
1.3k
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