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
890
0
Share
How to dynamically validate data with Symfony
Symfony Con 2022
Marion Hurteau
November 18, 2022
More Decks by Marion Hurteau
See All by Marion Hurteau
Les chaînes de caractères 101
marionleherisson
0
140
String usage: so many tools are already in your hands!
marionleherisson
1
200
Valider dynamiquement de la donnée avec Symfony
marionleherisson
2
1.1k
La microtypographie au service de la lisibilité
marionleherisson
0
230
Other Decks in Programming
See All in Programming
tRPCの概要と少しだけパフォーマンス
misoton665
2
200
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
130
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
210
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
190
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
200
ファインチューニングせずメインコンペを解く方法
pokutuna
0
310
CDK Deployのための ”反響定位”
watany
4
760
Coding as Prompting Since 2025
ragingwind
0
830
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
250
ハンズオンで学ぶクラウドネイティブ
tatsukiminami
0
130
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
3
340
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
270
Leo the Paperboy
mayatellez
7
1.7k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
270
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Building an army of robots
kneath
306
46k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
200
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
[SF Ruby Conf 2025] Rails X
palkan
2
960
Evolving SEO for Evolving Search Engines
ryanjones
0
180
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Transcript
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