Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How to dynamically validate data with Symfony
Search
Marion Hurteau
November 18, 2022
Programming
930
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How to dynamically validate data with Symfony
Symfony Con 2022
Marion Hurteau
November 18, 2022
Transcript
87 slides
How to dynamically validate data with Symfony Marion Hurteau github.com/MarionLeHerisson/validation
@MarionHerisson / 📧
[email protected]
1
Hello World 👋 Marion Hurteau @MarionHerisson /MarionLeHerisson 📧
[email protected]
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 📧
[email protected]
85
Questions? 86 @MarionHerisson /MarionLeHerisson/validation 📧
[email protected]
https://lparchive.org/Pokemon-Emerald-(by-Crosspei ce)/Update%2034/ 87
More Decks by Marion Hurteau
See All by Marion Hurteau
MCP : Votre API a un nouvel utilisateur (Et ce n’est pas un humain)
marionleherisson
0
100
Les chaînes de caractères 101
marionleherisson
0
160
String usage: so many tools are already in your hands!
marionleherisson
1
250
Valider dynamiquement de la donnée avec Symfony
marionleherisson
2
1.2k
La microtypographie au service de la lisibilité
marionleherisson
0
270
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
330
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
260
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
200
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
350
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
400
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
250
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
620
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
210
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
350
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k
Six Lessons from altMBA
skipperchong
29
4.6k
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
580
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
300
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
1
300
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
The Art of Programming - Codeland 2020
erikaheidi
57
15k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.4k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
HDC tutorial
michielstock
2
1k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
670