Code snippets

You will find here 255 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 this snippet, we see how to test the current PHP version. The most straightforward way is to use the PHP_VERSION_ID constant. I...

PHP

Published on 2021-11-19 • Modified on 2021-11-19

 View the code


In this snippet, we see how to get the first character of a string with PHP and Symfony. In the first part, we see how to use the ...

PHP

Published on 2021-11-12 • Modified on 2021-11-12

 View the code


This snippet shows how to wait for a Docker container to be ready, thanks to the inspect command. This is a script you can call ju...

Docker

Published on 2021-11-01 • Modified on 2021-11-01

 View the code


In this snippet, we see how to test a JSON login with the API Platform ApiTestCase class. We pass the username and password with t...

API Platform

Published on 2021-10-31 • Modified on 2021-10-31

 View the code


This snippet shows how to create a dynamic date depending on the current fixture with nelmio/alice. The trick is to use the $curre...

alice

Published on 2021-10-24 • Modified on 2021-10-24

 View the code


In this snippet, we see how to get the activated PHP extensions list with their versions. I use a one-line statement with an arrow...

PHP

Published on 2021-10-07 • Modified on 2021-10-07

 View the code


This snippet shows how to use a stable version of a package, whatever the major version with composer. We generally use major requ...

composer

Published on 2021-10-03 • Modified on 2021-10-03

 View the code


In this snippet, we see how to use a specific branch instead of a version with composer. Sometimes, this can be useful for testing...

composer

Published on 2021-10-02 • Modified on 2021-10-02

 View the code


This snippet shows how to conditionally display stuff with a Symfony command, depending on the current verbosity level. In this ca...

Symfony

Published on 2021-09-18 • Modified on 2021-09-18

 View the code


This snippet shows how to initialize a Symfony sandbox with a given version, thanks to the Symfony binary. You have to use the --v...

Symfony

Published on 2021-09-17 • Modified on 2021-09-17

 View the code