Code snippets
You will find here 285 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 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
This snippet show how to calculate the number of days until the end of the year with PHP. PHP correctly calculates the "z" format ...
PHP
Published on 2023-06-21 • Modified on 2023-06-21
This snippet shows how to index a PHP array of objects by their class name. We can use the array_reduce function instead of doing ...
PHP
Published on 2023-06-17 • Modified on 2023-06-17
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
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
Here is a working docker compose file for the min.io S3 storage service ready to copy/paste into your project. Access the GUI at t...
Docker
Published on 2023-06-05 • Modified on 2023-06-05
This snippet shows how to order a PHP array of objects by a given property. The sort function is in the snippet class, but if we w...
PHP
Published on 2023-05-31 • Modified on 2023-05-31
Here is a working docker compose file for Meilisearch ready to copy/paste into your project. Access the GUI at the http://127.0.0....
Docker
Published on 2023-05-22 • Modified on 2023-05-27
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
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