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
How to dynamically validate data with Symfony
Search
Marion Hurteau
November 18, 2022
Programming
0
620
How to dynamically validate data with Symfony
Symfony Con 2022
Marion Hurteau
November 18, 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
Valider dynamiquement de la donnée avec Symfony
marionleherisson
2
1k
La microtypographie au service de la lisibilité
marionleherisson
0
170
Other Decks in Programming
See All in Programming
JavaOne 2025: Advancing Java Profiling
jbachorik
1
300
신입 안드로이드 개발자의 AI 스타트업 생존기 (+ Native C++ Code를 Android에서 사용해보기)
dygames
0
480
CQRS+ES勉強会#1
rechellatek
0
370
2025/3/18 サービスの成長で生じる幅広いパフォーマンスの問題を、 AIで手軽に解決する
shirahama_x
0
140
RCPと宣言型ポリシーについてのお話し
kokitamura
2
130
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
2
340
ベクトル検索システムの気持ち
monochromegane
25
6.9k
remix + cloudflare workers (DO) docker上でいい感じに開発する
yoshidatomoaki
0
110
DenoでOpenTelemetryに入門する
yotahada3
2
280
Cloudflare Pagesのサイトを NotebookLMから読みやすくする Cloudflare Meet-up Tokyo Vol.7
xiombatsg
0
110
アーキテクトと美学 / Architecture and Aesthetics
nrslib
11
2.8k
技術好きなエンジニアが "リーダーへの進化" によって得たものと失ったもの
pospome
5
1.3k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
172
14k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
GitHub's CSS Performance
jonrohan
1030
460k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
30
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Rails Girls Zürich Keynote
gr2m
94
13k
The Cult of Friendly URLs
andyhume
78
6.3k
Transcript
How to dynamically validate data with Symfony Marion Hurteau github.com/MarionLeHerisson/validation
@MarionHerisson / 📧 mhurteau@jolicode.com 1
Hello World 👋 Marion Hurteau @MarionHerisson /MarionLeHerisson 📧 mhurteau@jolicode.com
Software Engineering @ESGI JoliCode since 2019 2
Hello World 👋 👶 “Disney baby” Nessie & Oscar
🐈 🖥💻 RPG 3
4
Validation ? 5
6
Principle Object Constraint Validator 7
Principle Object Constraint Validator ✅ Violation[ ] ❌ Violation[...] 8
Contrainte Validateur Entity Constraint Validator 9
Violations ? 10
The constraints 11
Gotta catch’em all ! Blank, NotBlank IsNull, NotNull IsTrue, IsFalse
Type, Length 12
Gotta catch’em all ! Email, Regex Url, Hostname, Ip CssColor
NotCompromisedPassword 13
Gotta catch’em all ! Date, DateTime, Time, Timezone Choice Language,
Locale, Country File, Image 14
Gotta catch’em all ! Bic, Ibn, CardScheme Isbn, Issn, Isin
All, AtLeastOneOf, Sequentially 15
Gotta catch’em all ! Compound 16
Gotta catch’em all ! Compound Callback 17
Gotta catch’em all ! Compound Callback Expression 18
Gotta catch’em all ! Compound Callback Expression Valid 19
Going further 20
UniqueEntity 21
Auto-mapping validation 22
Auto-mapping validation 23
Auto-mapping validation 24
Differents ways to validate 25
On a property 26
On a property 27
Inside a Form 28
On a method (a getter or something else) 29
On an entire class 30
On an entire class 31
On an entire class 32
ExecutionContextInterface ? 33
In my code When submitting a form NOT when persisting
When does it happen ? 34
Custom validation 35
Custom constraint 36
Custom constraint A constraint A validator 37
Custom constraint 38
Dynamic ? 39
Wait, what is a Pokemon ? 40
Wait, what is a Pokemon ? plant fire water 41
Wait, what is a Pokemon ? lvl. 18 lvl. 36
42
Wait, what is a Pokemon ? 43
Wait, what is a Pokemon ? 44
Wait, what is a Pokemon? 45
Wait, what is a Pokemon? 46
niv. 18 niv. 36 Use case 47
Use case POST /evolution/create 48
Use case 49
Use case 50
With a Callback 51
Inside the Controller 52
The entity 53
The constraints (in the entity) 54
The constraints (in the entity) 55
The constraints (in the entity) 56
The constraints (in the entity) 57
The constraints (in the entity) 58
The Callback (1/2) 59
The Callback (2/2) 60
Let’s try it ! 61
Let’s try it ! 62
Why is it KO ? 63
Why is it KO ? 64
The Callback (2/2) - Fixed it 65
Let’s try it - again ! 66
Design 👍 Fast 67
Design 👍 Fast 👎 Reusability 👎 Method’s or class size
👎 Testability 68
69
Design 👉 Externalise the constraints 👉 DIC 70
With external constraints 71
The Constraint 72
The Constraint 73
Let’s add an interface ✨ 74
Type definition 75
Type definition 76
Add some tags 77
ServiceLocator 78
The ConstraintValidator (1/2) 79
The ConstraintValidator (2/2) 80
81
TL;DR: 👉 Validate ! ✨ $context->getValidator()->inContext($context) 👉 External constraint :
- Maintainable - Testable - Reusable 👉 _instanceof & !tagged_locator - + default_index_method 82
83 Other use cases
Level up: Conditional Constraints 84
Thank you! @MarionHerisson /MarionLeHerisson/validation 📧 mhurteau@jolicode.com 85
Questions? 86 @MarionHerisson /MarionLeHerisson/validation 📧 mhurteau@jolicode.com
https://lparchive.org/Pokemon-Emerald-(by-Crosspei ce)/Update%2034/ 87