📜 ⬆️ ⬇️

Symfony Flex Private Recipes: Creating, Customizing, and Using

Hi, Habr.

I bring to your attention a brief article-instructions for creating, customizing and using personal recipes (private recipes). For this we need: a project, a repository with a bundle, a repository with our recipes.

The article contains many images, so the links to the repositories are placed here, and everything else will end up under the cat.
')
Bundle: symfony-acme-bundle
Recipes: symfony-recipes

So let's go.

1) Create a new project or use an existing one. The main condition is to have Symfony Flex installed. I decided to create a project from scratch.

To create a new project, use the command

composer create-project symfony/skeleton symfony-acme-project 



The project was successfully created, and in the installed packages we see symfony / flex.

2) Create a new bundle (symfony-acme-bundle) or use an existing one. I decided to create a simple bundle from scratch and register it with packagist.org. A link to the repository can be found at the beginning of the article. I lowered the processes of creating and registering a bundle, since there is nothing complicated about them.

3) Connect and configure symfony Flex Server. To do this, go to Symfony Recipes Server and click on the "register" link in the "Private Recipes BETA" section. You can also register through the symfony Flex Server .

Choose our repository with recipes and click "Install".



After that, we should see a page with congratulations.



4) Create a recipe.
This item I broke into 2 parts. First, we will create a repository, and then add a new recipe via pull request.

4.1) Create a new repository (symfony-recipes) and add the files: LICENSE, config.json, README.md (optional). A link to the repository can be found at the beginning of the article.

We are very important config.json, namely the data that it contains.

 { "projects": { "01C1K60FQVPP7FN6C3YB6639RZ": "Symfony Acme Project" } } 

“01C1K60FQVPP7FN6C3YB6639RZ” is the ID of our symfony project. You can find it in the composer.json file of the project created in claim 1.

 { "extra": { "symfony": { "id": "01C1K60FQVPP7FN6C3YB6639RZ", "allow-contrib": false } } } 

or running in the project folder

 composer config extra.symfony.id 

4.2) Add a recipe. To do this, create a new branch (add-acme-recipe) and add 3 files: manifest.json, post-install.txt and config / packages / acme.yaml. The important point is that the name of the folder with the recipe must match the name of the package (bundle) in packagist.org, and the versions must match. In our case, this is “yurijbogdanov / acme-bundle” and version “1.0”.

Sample file contents:

yurijbogdanov / acme-bundle / 1.0 / manifest.json

 { "bundles": { "Acme\\AcmeBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "ACME_FOO": "hello", "ACME_BAR": "world" } } 

yurijbogdanov / acme-bundle / 1.0 / post-install.txt

 <bg=blue;fg=white> </> <bg=blue;fg=white> Next: Configuration </> <bg=blue;fg=white> </> * Modify your ACME_FOO config in <fg=green>.env</> * Modify your ACME_BAR config in <fg=green>.env</> * Configure your parameters in <fg=green>config/packages/acme.yaml</> 

yurijbogdanov / acme-bundle / 1.0 / config / packages / acme.yaml

 acme: foo: hello bar: world 

Next, we add our branch with the recipe to the remote repository and do a pull request.





Now a few words why it is better to add recipes via pull request, and not directly to the master (even if you are working alone).

Every time you make a pull request, your code will be checked by the symfony-flex-server bot and even the smallest deviations from the requirements will be recorded.



By clicking on the “Details” link, you can see exactly which errors were found by the bot.



If successful, you will see approve from the bot and you can make a merge in master.



The branch is successful, and it is now possible to go to installing the package (bundle).



5) Add a bundle to our project. To do this, go to the folder with the project and execute the command

 composer require yurijbogdanov/acme-bundle 



The bundle was successfully installed using our recipe.

 Symfony operations: 1 recipe (7302152d871c6cc69ec5de45f91d1b38) - Configuring yurijbogdanov/acme-bundle (>=1.0): From github.com/yurijbogdanov/symfony-recipes:master 

The recipe made the following changes to the project:

1) added a bundle in config / bundles.php

 <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Acme\AcmeBundle::class => ['all' => true], ]; 

2) added environment variables to .env.dist

 ###> yurijbogdanov/acme-bundle ### ACME_FOO=hello ACME_BAR=world ###< yurijbogdanov/acme-bundle ### 

3) added acme.yaml configuration file to config / packages /

Thanks for attention.

Source: https://habr.com/ru/post/345382/


All Articles