{"id":151,"date":"2017-10-09T09:11:12","date_gmt":"2017-10-09T07:11:12","guid":{"rendered":"https:\/\/numa-bord.com\/miniblog\/?p=151"},"modified":"2017-10-09T09:11:12","modified_gmt":"2017-10-09T07:11:12","slug":"symfony-automatiser-actions-event-listeners-de-doctrine","status":"publish","type":"post","link":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/","title":{"rendered":"Symfony : Automatiser des actions avec les \u00ab\u00a0Event listeners\u00a0\u00bb de doctrine"},"content":{"rendered":"<p>Le framework Symfony coupl\u00e9 \u00e0 l&rsquo;ORM doctrine permet de cr\u00e9er des \u00ab\u00a0Event Listeners\u00a0\u00bb, c&rsquo;est \u00e0 dire connaitre d\u00e9s qu&rsquo;il y&rsquo;a un \u00e9v\u00e9nement (cr\u00e9ation\/modification\/suppression) sur une entit\u00e9. C&rsquo;est un outil tr\u00e8s int\u00e9ressant pour automatiser des actions quand certaines propri\u00e9t\u00e9s d&rsquo;une entit\u00e9 sont mis \u00e0 jour.<\/p>\n<p>Prenons un exemple concret : Dans les semaines pr\u00e9c\u00e9dentes, nous avons vu comment <a href=\"https:\/\/numa-bord.com\/miniblog\/php-google-map-api-recuperer-coordonees-gps-depuis-adresse-format-humain\/\">r\u00e9cup\u00e9rer les coordonn\u00e9es d&rsquo;une adresse gr\u00e2ce \u00e0 l&rsquo;API google map<\/a>. Afin de limiter les appels \u00e0 l&rsquo;API google map (payants si un certain quota et d\u00e9pass\u00e9) nous allons enregistrer ces coordonn\u00e9es en base de donn\u00e9es pour pouvoir les r\u00e9utiliser directement. Il nous faut cependant les enregistrer\/mettre \u00e0 jour \u00e0 chaque fois qu&rsquo;une adresse est cr\u00e9e ou modifi\u00e9e. C&rsquo;est ici que nous faisons intervenir les Event Listener.<\/p>\n<p>Commen\u00e7ons par configurer nos listeners dans les services (fichiers services.yml du dossier \/app\/config\/) de symfony.<\/p>\n<div class=\"codecolorer-container yaml default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"yaml codecolorer\"><span class=\"co4\">services<\/span><span class=\"sy2\">:<br \/>\n<\/span> &nbsp; &nbsp;<span class=\"co1\">#...<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">#LISTENER DOCTRINE#<\/span><span class=\"co4\"><br \/>\n&nbsp; &nbsp; app.listener.doctrineevent<\/span>:<span class=\"co3\"><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; class<\/span><span class=\"sy2\">: <\/span>AppBundle\\EventListener\\DoctrineEvent<span class=\"co4\"><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; tags<\/span>:<span class=\"co3\"><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - { name<\/span><span class=\"sy2\">: <\/span>doctrine.event_listener, event<span class=\"sy2\">: <\/span>prePersist, lazy<span class=\"sy2\">: <\/span>true <span class=\"br0\">&#125;<\/span><span class=\"co3\"><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - { name<\/span><span class=\"sy2\">: <\/span>doctrine.event_listener, event<span class=\"sy2\">: <\/span>preUpdate, lazy<span class=\"sy2\">: <\/span>true <span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>La configuration indique que nous allons \u00e9couter les \u00e9v\u00e9nements \u00ab\u00a0PrePersist\u00a0\u00bb et \u00ab\u00a0PreUpdate\u00a0\u00bb. Ce qui permettra d&rsquo;effectuer notre action lors de la cr\u00e9ation d&rsquo;une adresse et lors de sa modification. Cr\u00e9ons la classe qui va g\u00e9rer tout \u00e7a. Comme indiqu\u00e9 il s&rsquo;agit du fichier : AppBundle\\EventListener\\DoctrineEvent<\/p>\n<p>Pour appr\u00e9hender la suite, consultez les commentaires dans le code<\/p>\n<div class=\"codecolorer-container php default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">namespace<\/span> AppBundle\\EventListener<span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw2\">use<\/span> Doctrine\\Common\\EventSubscriber<span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">use<\/span> Doctrine\\Common\\Persistence\\Event\\LifecycleEventArgs<span class=\"sy0\">;<\/span><br \/>\n<span class=\"co1\">\/\/les adresses de nos utilisateur sont stock\u00e9s dans une entit\u00e9 &quot;Contact&quot;<\/span><br \/>\n<span class=\"kw2\">use<\/span> AppBundle\\Entity\\Contact<span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw2\">class<\/span> DoctrineEvent <span class=\"kw2\">implements<\/span> EventSubscriber <span class=\"br0\">&#123;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> getSubscribedEvents<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> <a href=\"http:\/\/www.php.net\/array\"><span class=\"kw3\">array<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'prePersist'<\/span><span class=\"sy0\">,<\/span> <span class=\"st_h\">'preUpdate'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><span class=\"co1\">\/\/les \u00e9v\u00e9nements \u00e9cout\u00e9s<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> prePersist<span class=\"br0\">&#40;<\/span>LifecycleEventArgs <span class=\"re0\">$args<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$entity<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$args<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getEntity<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/Si c'est bien une entit\u00e9 Contact qui va \u00eatre &quot;persist\u00e9&quot;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"re0\">$entity<\/span> instanceof Contact<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$entity<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">updateGmapData<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><span class=\"co1\">\/\/on met \u00e0 jour les coordonn\u00e9es via l'appel \u00e0 google map<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> preUpdate<span class=\"br0\">&#40;<\/span>LifecycleEventArgs <span class=\"re0\">$args<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$entity<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$args<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getEntity<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$changeset<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$args<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getEntityManager<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getUnitOfWork<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getEntityChangeSet<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$entity<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/Si c'est bien une entit\u00e9 Contact qui va \u00eatre modifi\u00e9<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"re0\">$entity<\/span> instanceof Contact<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/Si il y'a eu une mise a jour sur les propri\u00e9t\u00e9s en relation avec l'adresse (ici &quot;address&quot;, &quot;city&quot; et &quot;postalCode&quot;)<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><a href=\"http:\/\/www.php.net\/array_key_exists\"><span class=\"kw3\">array_key_exists<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;address&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$changeset<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">||<\/span> <a href=\"http:\/\/www.php.net\/array_key_exists\"><span class=\"kw3\">array_key_exists<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;city&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$changeset<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">||<\/span> <a href=\"http:\/\/www.php.net\/array_key_exists\"><span class=\"kw3\">array_key_exists<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;postalCode&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$changeset<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$entity<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">updateGmapData<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><span class=\"co1\">\/\/on met \u00e0 jour les coordonn\u00e9es via l'appel \u00e0 google map<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>De cette mani\u00e8re nos coordonn\u00e9es seront toujours \u00e0 jour. Il manque pour que l&rsquo;exemple soit complet la fonction \u00ab\u00a0updateGmapData()\u00a0\u00bb de notre entit\u00e9 Contact. Cela ne concerne pas le sujet des Event Listener, mais je vous en met un exemple qui utilise bien sur la fonction \u00ab\u00a0geocodeAddress()\u00a0\u00bb d\u00e9taill\u00e9 <a href=\"https:\/\/numa-bord.com\/miniblog\/php-google-map-api-recuperer-coordonees-gps-depuis-adresse-format-humain\/\">ici<\/a><\/p>\n<div class=\"codecolorer-container php default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\">&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> updateGmapData<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$data<\/span> <span class=\"sy0\">=<\/span> \\AppBundle\\Utils\\GmapApi<span class=\"sy0\">::<\/span><span class=\"me2\">geocodeAddress<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getAddress<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">.<\/span> <span class=\"st_h\">' '<\/span> <span class=\"sy0\">.<\/span> <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getZipcode<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">.<\/span> <span class=\"st_h\">' '<\/span> <span class=\"sy0\">.<\/span> <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">getCity<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapLat<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'lat'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapLng<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'lng'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapAddress<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'address'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapPostalCode<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'postal_code'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapCity<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'city'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapDepartment<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'department'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapRegion<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'region'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setGmapCountry<\/span><span class=\"br0\">&#40;<\/span><span class=\"re0\">$data<\/span><span class=\"br0\">&#91;<\/span><span class=\"st_h\">'country'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Le framework Symfony coupl\u00e9 \u00e0 l&rsquo;ORM doctrine permet de cr\u00e9er des \u00ab\u00a0Event Listeners\u00a0\u00bb, c&rsquo;est \u00e0 dire connaitre d\u00e9s qu&rsquo;il y&rsquo;a un \u00e9v\u00e9nement (cr\u00e9ation\/modification\/suppression) sur une entit\u00e9. C&rsquo;est un outil tr\u00e8s int\u00e9ressant pour automatiser des actions quand certaines propri\u00e9t\u00e9s d&rsquo;une entit\u00e9 sont mis \u00e0 jour. Prenons un exemple concret : Dans les semaines pr\u00e9c\u00e9dentes, nous avons [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,4,3],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-developpement","category-doctrine","category-symfony"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Symfony : Automatiser des actions avec les &quot;Event listeners&quot; de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Symfony : Automatiser des actions avec les &quot;Event listeners&quot; de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web\" \/>\n<meta property=\"og:description\" content=\"Le framework Symfony coupl\u00e9 \u00e0 l&rsquo;ORM doctrine permet de cr\u00e9er des \u00ab\u00a0Event Listeners\u00a0\u00bb, c&rsquo;est \u00e0 dire connaitre d\u00e9s qu&rsquo;il y&rsquo;a un \u00e9v\u00e9nement (cr\u00e9ation\/modification\/suppression) sur une entit\u00e9. C&rsquo;est un outil tr\u00e8s int\u00e9ressant pour automatiser des actions quand certaines propri\u00e9t\u00e9s d&rsquo;une entit\u00e9 sont mis \u00e0 jour. Prenons un exemple concret : Dans les semaines pr\u00e9c\u00e9dentes, nous avons [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\" \/>\n<meta property=\"og:site_name\" content=\"Pense b\u00eate d&#039;un d\u00e9veloppeur web\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-09T07:11:12+00:00\" \/>\n<meta name=\"author\" content=\"Numa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Numa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\"},\"author\":{\"name\":\"Numa\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\"},\"headline\":\"Symfony : Automatiser des actions avec les \u00ab\u00a0Event listeners\u00a0\u00bb de doctrine\",\"datePublished\":\"2017-10-09T07:11:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\"},\"wordCount\":545,\"commentCount\":1,\"articleSection\":[\"D\u00e9veloppement\",\"Doctrine\",\"Symfony\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\",\"url\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\",\"name\":\"Symfony : Automatiser des actions avec les \\\"Event listeners\\\" de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web\",\"isPartOf\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#website\"},\"datePublished\":\"2017-10-09T07:11:12+00:00\",\"author\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\"},\"breadcrumb\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/numa-bord.com\/miniblog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Symfony : Automatiser des actions avec les \u00ab\u00a0Event listeners\u00a0\u00bb de doctrine\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#website\",\"url\":\"https:\/\/numa-bord.com\/miniblog\/\",\"name\":\"Pense b\u00eate d&#039;un d\u00e9veloppeur web\",\"description\":\"(php, javascript, Symfony, Wordpress....)\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/numa-bord.com\/miniblog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\",\"name\":\"Numa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"caption\":\"Numa\"},\"url\":\"https:\/\/numa-bord.com\/miniblog\/author\/negonner\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Symfony : Automatiser des actions avec les \"Event listeners\" de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/","og_locale":"fr_FR","og_type":"article","og_title":"Symfony : Automatiser des actions avec les \"Event listeners\" de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web","og_description":"Le framework Symfony coupl\u00e9 \u00e0 l&rsquo;ORM doctrine permet de cr\u00e9er des \u00ab\u00a0Event Listeners\u00a0\u00bb, c&rsquo;est \u00e0 dire connaitre d\u00e9s qu&rsquo;il y&rsquo;a un \u00e9v\u00e9nement (cr\u00e9ation\/modification\/suppression) sur une entit\u00e9. C&rsquo;est un outil tr\u00e8s int\u00e9ressant pour automatiser des actions quand certaines propri\u00e9t\u00e9s d&rsquo;une entit\u00e9 sont mis \u00e0 jour. Prenons un exemple concret : Dans les semaines pr\u00e9c\u00e9dentes, nous avons [&hellip;]","og_url":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/","og_site_name":"Pense b\u00eate d&#039;un d\u00e9veloppeur web","article_published_time":"2017-10-09T07:11:12+00:00","author":"Numa","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"Numa","Dur\u00e9e de lecture estim\u00e9e":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#article","isPartOf":{"@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/"},"author":{"name":"Numa","@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e"},"headline":"Symfony : Automatiser des actions avec les \u00ab\u00a0Event listeners\u00a0\u00bb de doctrine","datePublished":"2017-10-09T07:11:12+00:00","mainEntityOfPage":{"@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/"},"wordCount":545,"commentCount":1,"articleSection":["D\u00e9veloppement","Doctrine","Symfony"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/","url":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/","name":"Symfony : Automatiser des actions avec les \"Event listeners\" de doctrine - Pense b\u00eate d&#039;un d\u00e9veloppeur web","isPartOf":{"@id":"https:\/\/numa-bord.com\/miniblog\/#website"},"datePublished":"2017-10-09T07:11:12+00:00","author":{"@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e"},"breadcrumb":{"@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/numa-bord.com\/miniblog\/symfony-automatiser-actions-event-listeners-de-doctrine\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/numa-bord.com\/miniblog\/"},{"@type":"ListItem","position":2,"name":"Symfony : Automatiser des actions avec les \u00ab\u00a0Event listeners\u00a0\u00bb de doctrine"}]},{"@type":"WebSite","@id":"https:\/\/numa-bord.com\/miniblog\/#website","url":"https:\/\/numa-bord.com\/miniblog\/","name":"Pense b\u00eate d&#039;un d\u00e9veloppeur web","description":"(php, javascript, Symfony, Wordpress....)","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/numa-bord.com\/miniblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Person","@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e","name":"Numa","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","caption":"Numa"},"url":"https:\/\/numa-bord.com\/miniblog\/author\/negonner\/"}]}},"_links":{"self":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":19,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/151\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}