keyboard

Hugo Soltys

Symfony developer

Since 2013

Write your own recipes for your Composer packages with Symfony Flex

Posted on by Hugo - 437 views - 0 Comments


Symfony recipes allow the automation of Composer packages configuration via the Symfony Flex Composer plugin.

It is pretty useful to avoid boring rituals like writing packages configuration, routes, parameters...

In this article we will learn how to write your own recipes for your private repositories.


Come on, let's do this !

The main disadvantage of the official recipes repository is that you are forced to contribute to add your own recipes but they will be public.

Fortunately, there is a proxy-application for symfony/flex called Symfony Flex Server. This Flex plugin allows you to use your own 3rd party recipes very easily.

How does it works ?

Let's assume that you developed a package called myvendor/mypackage.

If you want to install it in your Symfony project, you will do the following command :

$ composer req myvendor/mypackage

By doing it, Composer will download the source code from your Git repository and then the Flex component will call the symfony.sh API to see if a recipe for your package is available.

It's possible to configure your composer.json to call another endpoint that the official one by adding the following line:

{
    "extra": {
        "symfony": {
            "id": "01BNAS3890XQPHCYXQ127296J0",
            "allow-contrib": false,
            "endpoint": "http://127.0.0.1:8080",
        }
    }
}

Unfortunately by doing it you will call exclusively your custom endpoint, and you will no more be able to use the official recipes.

Now I invite you to clone the Symfony Flex Server and launch it (documentation in the Readme.md file).

The strength of the Symfony Flex Server is it will search for a recipe firstly on the symfony.sh API and then on the Flex Server one.

Two calls are made and the two responses are merged.

So, if you have written a recipe for your package, just place it under the recipes/ directory but respect the vendor/package/version architecture. Once done, run the following command :

$ bin/flex build

You are now able to use Symfony recipes for your own private repositories as much as the official ones.

 

The Flex Server I'm providing to you is a pull request of the Aurimas Niekis's one.

 

Thanks for reading,

Hugo.


Hugo Soltys

My name is Hugo, I'm 25 and I'm a Symfony developer since 2013. I love to create websites by myself to learn new technologies or increase my skills.
I love movies, books, music and video games. I also like to drink a few beers with my friends. I'm from Lille (France) and I currently work as Symfony developer at Decathlon since 2016. Before that, I worked as Symfony developer for the IT Room company, in Roubaix, France.


Older articles