Code snippets
You will find here 113 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 ™.
This snippet shows how to get the name of a Twig template inside a Twig template. Yes, this is inception! Not so hard as there is...
Twig
Published on 2023-02-18 • Modified on 2023-02-18
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
This snippet shows how to disable the translations for the test environment with Symfony. The goal is to test the translation code...
Symfony
Published on 2023-01-31 • Modified on 2023-01-31
This snippet shows a YAML template to create a Symfony tagged iterator service: 1. We activate autowiring and autoconfigure. 2. We...
Symfony
Published on 2023-01-06 • Modified on 2023-01-06
This snippet shows how to deactivate the profiler (debug bar) simultaneously wit the debug mode with Symfony. We can use this litt...
Symfony
Published on 2023-01-02 • Modified on 2023-01-02
This snippet shows how to force the output of the Symfony debug functions for CLI. When using the dd() and dump() functions, the o...
Symfony
Published on 2022-12-13 • Modified on 2022-12-13
This snippet shows how to unit test a Symfony custom constraint with the ConstraintValidatorTestCase. In the previous snippet, we ...
Symfony
Published on 2022-11-06 • Modified on 2022-11-06
This snippet shows how to unit test a custom Symfony validation constraint. One learns every day; I made this snippet inspired by ...
Symfony
Published on 2022-11-05 • Modified on 2022-11-05
This snippet shows how to anonymize an IP address with Symfony. We can use the IpUtils class which handles both V4 and V6 addresse...
Symfony
Published on 2022-10-23 • Modified on 2022-10-23
This snippet shows how to check if a Symfony route exists. We mustn't use the getRouteCollection() method because it regenerates t...
Symfony
Published on 2022-10-22 • Modified on 2022-10-22