Code snippets

You will find here 26 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.

In a previous snippet, we saw how to ignore platform requirements globally. Composer now allows ignoring specific requirement par...

composer

Published on 2023-06-10 • Modified on 2023-06-10

 View the code


This snippet shows how to convert an array into an object with the Symfony serializer. That's a common need to denormalize an ar...

Symfony

Published on 2023-04-13 • Modified on 2023-04-13

 View the code


This snippet shows how to display a money amount with Twig. There's a filter for that, and it handles the current locale. The fol...

Twig

Published on 2023-02-25 • Modified on 2023-02-25

 View the code


This snippet shows how to cache data with the Symfony CacheItemPoolInterface service. In a previous snippet, we saw how to cache ...

Symfony

Published on 2023-02-14 • Modified on 2023-02-14

 View the code


This snippet shows how to select an invalid choice value of a select form field in a Symfony functional test. Indeed, if you try t...

Symfony

Published on 2022-08-19 • Modified on 2022-08-19

 View the code


This snippet shows how to get the id of a Symfony form inside a Twig template. This is useful when wanting to give a particular at...

Symfony

Published on 2022-08-06 • Modified on 2022-08-06

 View the code


In this snippet, we see how to test the presence of keys in a JSON API response. We can use the PHPUnit assertEqualsCanonicalizing...

api

Published on 2022-06-28 • Modified on 2022-06-28

 View the code


This snippet shows how to translate the day and month of a date with PHP. We use the intl extension and its IntlDateFormatter clas...

PHP

Published on 2022-04-12 • Modified on 2022-04-12

 View the code


In this snippet, we see how to remove useless decimal of number_format with PHP. This trick is only helpful if you want to have lo...

PHP

Published on 2022-04-04 • Modified on 2022-04-04

 View the code


This snippet shows how to get the IRI of an entity with API Platform (and the opposite!). I have added this snippet because I noti...

API Platform

Published on 2022-03-14 • Modified on 2022-03-14

 View the code