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

Viewers also liked

Symfony et serialization avec JMS serializer
Symfony et serialization avec JMS serializer Symfony et serialization avec JMS serializer
Symfony et serialization avec JMS serializer Samuel ROZE
 
Paris Job Talk
Paris Job TalkParis Job Talk
Paris Job TalkmeeticTech
 
Meetup scala paris user group - conflation like @ meetic
Meetup scala paris user group - conflation like @ meeticMeetup scala paris user group - conflation like @ meetic
Meetup scala paris user group - conflation like @ meeticmeeticTech
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDAleix Vergés
 
Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)GOG.com dev team
 
Meetic Backend Mutation With Symfony
Meetic Backend Mutation With SymfonyMeetic Backend Mutation With Symfony
Meetic Backend Mutation With SymfonymeeticTech
 
Very lastroom symfony1 vers symfony2 en douceur
Very lastroom   symfony1 vers symfony2 en douceurVery lastroom   symfony1 vers symfony2 en douceur
Very lastroom symfony1 vers symfony2 en douceurSébastien Houzé
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2Ahmed ABATAL
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les ProfessionnelsFabien Potencier
 
Drupal 8 + Symfony 2 = une équipe gagnante
Drupal 8 + Symfony 2 = une équipe gagnanteDrupal 8 + Symfony 2 = une équipe gagnante
Drupal 8 + Symfony 2 = une équipe gagnanteVanessa David
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesNoel GUILBERT
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfonyJeremy Gachet
 
Design patterns avec Symfony
Design patterns avec SymfonyDesign patterns avec Symfony
Design patterns avec SymfonyMohammed Rhamnia
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2Hugo Hamon
 
Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringGiulio De Donato
 
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ss
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ssAlphorm.com Support de la Formation Symfony 3 , les fondamentaux-ss
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ssAlphorm
 
Symfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigSymfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigAbdelkader Rhouati
 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesAbdelkader Rhouati
 
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2Abdelkader Rhouati
 
Symfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleSymfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleAbdelkader Rhouati
 

Viewers also liked (20)

Symfony et serialization avec JMS serializer
Symfony et serialization avec JMS serializer Symfony et serialization avec JMS serializer
Symfony et serialization avec JMS serializer
 
Paris Job Talk
Paris Job TalkParis Job Talk
Paris Job Talk
 
Meetup scala paris user group - conflation like @ meetic
Meetup scala paris user group - conflation like @ meeticMeetup scala paris user group - conflation like @ meetic
Meetup scala paris user group - conflation like @ meetic
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 
Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)Event sourcing w PHP (by Piotr Kacała)
Event sourcing w PHP (by Piotr Kacała)
 
Meetic Backend Mutation With Symfony
Meetic Backend Mutation With SymfonyMeetic Backend Mutation With Symfony
Meetic Backend Mutation With Symfony
 
Very lastroom symfony1 vers symfony2 en douceur
Very lastroom   symfony1 vers symfony2 en douceurVery lastroom   symfony1 vers symfony2 en douceur
Very lastroom symfony1 vers symfony2 en douceur
 
Presentation Symfony2
Presentation Symfony2Presentation Symfony2
Presentation Symfony2
 
symfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnelssymfony : Un Framework Open-Source pour les Professionnels
symfony : Un Framework Open-Source pour les Professionnels
 
Drupal 8 + Symfony 2 = une équipe gagnante
Drupal 8 + Symfony 2 = une équipe gagnanteDrupal 8 + Symfony 2 = une équipe gagnante
Drupal 8 + Symfony 2 = une équipe gagnante
 
Symfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiquesSymfony2: 30 astuces et bonnes pratiques
Symfony2: 30 astuces et bonnes pratiques
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfony
 
Design patterns avec Symfony
Design patterns avec SymfonyDesign patterns avec Symfony
Design patterns avec Symfony
 
Introduction à Symfony2
Introduction à Symfony2Introduction à Symfony2
Introduction à Symfony2
 
Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoring
 
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ss
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ssAlphorm.com Support de la Formation Symfony 3 , les fondamentaux-ss
Alphorm.com Support de la Formation Symfony 3 , les fondamentaux-ss
 
Symfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en TwigSymfony 2 : chapitre 2 - Les vues en Twig
Symfony 2 : chapitre 2 - Les vues en Twig
 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulaires
 
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
 
Symfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleSymfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation Générale
 

More from Les-Tilleuls.coop

Symfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, PantherSymfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, PantherLes-Tilleuls.coop
 
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...Les-Tilleuls.coop
 
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...Les-Tilleuls.coop
 
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...Les-Tilleuls.coop
 
Panther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsersPanther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsersLes-Tilleuls.coop
 
API Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven ProjectsAPI Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven ProjectsLes-Tilleuls.coop
 
API Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven ProjectsAPI Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven ProjectsLes-Tilleuls.coop
 
API Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionAPI Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionLes-Tilleuls.coop
 
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)Les-Tilleuls.coop
 
Creating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkCreating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkLes-Tilleuls.coop
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Les-Tilleuls.coop
 
Workshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantiqueWorkshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantiqueLes-Tilleuls.coop
 
Atelier #3 intégration html
Atelier #3 intégration htmlAtelier #3 intégration html
Atelier #3 intégration htmlLes-Tilleuls.coop
 
Atelier #2 initiation à css
Atelier #2 initiation à cssAtelier #2 initiation à css
Atelier #2 initiation à cssLes-Tilleuls.coop
 

More from Les-Tilleuls.coop (15)

Symfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, PantherSymfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, Panther
 
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
 
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
 
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
 
Panther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsersPanther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsers
 
API Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven ProjectsAPI Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven Projects
 
API Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven ProjectsAPI Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven Projects
 
API Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionAPI Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework Resurrection
 
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
 
Creating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkCreating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform framework
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014
 
Workshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantiqueWorkshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantique
 
Atelier #3 intégration html
Atelier #3 intégration htmlAtelier #3 intégration html
Atelier #3 intégration html
 
Atelier #2 initiation à css
Atelier #2 initiation à cssAtelier #2 initiation à css
Atelier #2 initiation à css
 
Atelier initiation au html5
Atelier initiation au html5Atelier initiation au html5
Atelier initiation au html5
 

Symfony 2 : Performances et Optimisations