SlideShare a Scribd company logo
1 of 20
Download to read offline
Symfony2:
Sérialisation
SfPot 12/06

Samuel ROZE
Serializer
Abstraction du format de sortie et
d’entrée
Composant Serializer
Sérialisation et désérialisation
Fonctionnalités limitées
JMS Serializer
JMSSerializerBundle
(Dé)sérialisation
JSON
XML
YAML
JMS Serializer
Les groupes de sérialisation
Comment
retourner des
attributs
différents en
fonction du
context ?
JMS Serializer
Les groupes de sérialisation
Sérialisation
d’un User
Intérêt de
Media:user ?
Sérialisation
d’un Media
Intérêt de
User:medias ?
JMS Serializer
Les groupes de sérialisation
1. Configuration des groupes
via annotations
2. Sérialisation avec un des
groupes définis
3. Sérialisation voulue
JMS Serializer
Le versioning
Faire co-habiter
différentes
versions d’une
même entité ?
JMS Serializer
Le versioning
Configuration “simple” Configuration avec le “accessType”
JMS Serializer
Le versioning
NB: Utilise “version_compare”
Sérialisation avec context de version
JMS Serializer
Custom handlers
Comment sérialiser
“à la main” un type
“privé” ?
JMS Serializer
Custom handlers
FileEntry gère le stockage de nos
fichiers, sur différents providers
(local, ftp, cdn, …)
JMS Serializer
Custom handlers
Ajout de l’handler via services
de Symfony
JMS Serializer
Custom handlers
Un objet FileEntry devient une chaine de caractères à la sérialisation
JMS Serializer
(De)serialize events
Accès aux données
Avant désérialisation

pre_serialize
Après désérialisation

post_serialize
Avant sérialisation

pre_deserialize
Après sérialisation

post_deserialize
JMS Serializer
(De)serialize events
Problématique: retourner une
thumbnail optimisée pour le
client
Avoir accès à la requête client
Avoir notre thumbnailManager
Pouvoir modifier l’entité avant
la sérialization
JMS Serializer
(De)serialize events
Création du subscriber JMS, grâce au
tag jms_serializer.event_subscriber
Ajout du subscriber via le builder
JMS Serializer
(De)serialize events
Si le paramètre
deviceWidth est
dans la requête,
on récupère le
thumbnail le
plus optimisé
pour le client,
qui sera
sérialisé
JMS Serializer
(De)serialize events
De nombreuses applications possibles :
Transformation de données sensibles
Cartes bleues
Adresses email
Modifications diverses
Génération d’URLs
….
JMS Serializer
Intégration avec FOSRestBundle
Groupes de sérialisation Versioning
Configuration générale
fos_rest.serializer.version
Format version listener
fos_rest.format_listener.media_
type.version_regex
‘/(v|version)=(?
P<version>[0-9.]+)/'
Merci à tous !

More Related Content

More from Samuel ROZE

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patternsSamuel ROZE
 
Symfony Messenger (Symfony Live San Francisco)
Symfony Messenger (Symfony Live San Francisco)Symfony Messenger (Symfony Live San Francisco)
Symfony Messenger (Symfony Live San Francisco)Samuel ROZE
 
Micro services may not be the best idea
Micro services may not be the best ideaMicro services may not be the best idea
Micro services may not be the best ideaSamuel ROZE
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingSamuel ROZE
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patternsSamuel ROZE
 
Take care of our micro services
Take care of our micro servicesTake care of our micro services
Take care of our micro servicesSamuel ROZE
 
(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et Tolerance(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et ToleranceSamuel ROZE
 
Using continuouspipe to speed up our workflows
Using continuouspipe to speed up our workflowsUsing continuouspipe to speed up our workflows
Using continuouspipe to speed up our workflowsSamuel ROZE
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form componentSamuel ROZE
 
Behat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatBehat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatSamuel ROZE
 
Docker orchestration with Kubernetes
Docker orchestration with KubernetesDocker orchestration with Kubernetes
Docker orchestration with KubernetesSamuel ROZE
 

More from Samuel ROZE (12)

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
Symfony Messenger (Symfony Live San Francisco)
Symfony Messenger (Symfony Live San Francisco)Symfony Messenger (Symfony Live San Francisco)
Symfony Messenger (Symfony Live San Francisco)
 
Micro services may not be the best idea
Micro services may not be the best ideaMicro services may not be the best idea
Micro services may not be the best idea
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
Take care of our micro services
Take care of our micro servicesTake care of our micro services
Take care of our micro services
 
(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et Tolerance(micro)services avec Symfony et Tolerance
(micro)services avec Symfony et Tolerance
 
Using continuouspipe to speed up our workflows
Using continuouspipe to speed up our workflowsUsing continuouspipe to speed up our workflows
Using continuouspipe to speed up our workflows
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form component
 
Behat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatBehat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than that
 
Docker orchestration with Kubernetes
Docker orchestration with KubernetesDocker orchestration with Kubernetes
Docker orchestration with Kubernetes
 

Symfony et serialization avec JMS serializer