SlideShare une entreprise Scribd logo
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 !

Contenu connexe

ODP
03 presentation-builder-normal
PDF
CQRS and Event Sourcing in a Symfony application
PDF
Behat c'est plus que ça | Behat is more than that
PDF
Introduction to CQRS and Event Sourcing
PDF
When cqrs meets event sourcing
PDF
Speed up your Symfony2 application and build awesome features with Redis
PPTX
JMS Serializer quick tour
03 presentation-builder-normal
CQRS and Event Sourcing in a Symfony application
Behat c'est plus que ça | Behat is more than that
Introduction to CQRS and Event Sourcing
When cqrs meets event sourcing
Speed up your Symfony2 application and build awesome features with Redis
JMS Serializer quick tour

En vedette (20)

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

Plus de Les-Tilleuls.coop (15)

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

Symfony 2 : Performances et Optimisations