Code snippets

You will find here 108 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 the previous snippet, we saw how to list files of a directory and its subfolders with the RecursiveDirectoryIterator SPL class...

Symfony

Published on 2024-02-13 • Modified on 2024-02-13

 View the code


This snippet shows how to test a new Symfony major beta version. We saw how to try the "next" minor version in the previous snippe...

Symfony

Published on 2023-11-01 • Modified on 2023-11-01

 View the code


This snippet shows how to install a Symfony beta version with the Symfony binary. Note that if a new major version is released, it...

Symfony

Published on 2023-10-28 • Modified on 2023-10-28

 View the code


In the previous snippet, we saw how to inject the Symfony project root directory in the services with a bind. We can also use a P...

Symfony

Published on 2023-09-29 • Modified on 2023-09-29

 View the code


This snippet shows how to inject the Symfony project root directory in your services (or your controllers) with a bind. In a previ...

Symfony

Published on 2023-09-28 • Modified on 2023-09-28

 View the code


In a previous snippet, we saw how to validate an array using the existing validator service manually. In this snippet, we manuall...

Symfony

Published on 2023-08-09 • Modified on 2023-08-09

 View the code


This snippet shows how to generate a random token for a mail confirmation link using PHP and Symfony. The final length of the gene...

PHP

Published on 2023-07-01 • Modified on 2023-07-01

 View the code


This snippet shows how to use role constants with the IsGranted Symfony attribute instead of using raw strings. We can use the Aut...

Symfony

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

 View the code


This snippet shows how to create a Meilisearch adapter for the Pagerfanta PHP library. As you can see, it is quite straightforwa...

PHP

Published on 2023-05-21 • Modified on 2023-05-21

 View the code


This snippet shows how to debug a variable with a concise stack trace with the Symfony VarDumper. The debug_print_backtrace() func...

Symfony

Published on 2023-04-28 • Modified on 2023-04-28

 View the code