1
votes

I'm building a new bundle for my Symfony 4.2 application and I want to run a specific code only once after the bundle installation to set up some skeleton class in the root project. Like the maker bundle but without manual interaction. The installed bundle should modify existing configuration yaml of another bundle (of course, once after installed).

I've tried to use the bundle's composer.json script section without luck. I've not found any references in the official documentation how to solve this.

Are there any method to solve this?

3

3 Answers

1
votes

Symfony Flex is a tool to automate installing and removing bundles and other dependencies.

You need to add a recipe for your bundle here: https://github.com/symfony/recipes-contrib

If your bundle is private you may use Private Symfony Flex Recipes Repository

Update: @Mitesh Vasava approach will not work because, first of all, you need to setup scripts manually into your project's composer.json, not into a bundle's composer.json. Second, this scripts will run after every installation, not just after installation of your bundle.

1
votes

You can either create an official recipe for Symfony Flex as mentioned by @BoShurik or you can create a composer plugin, which you can read about here.

The basic approach would be to create a separate package that would serve as the installer and then require it in your bundle.

Your plugin can then modify the source as you see fit.

0
votes

You have to define your script in composer.json while execute composer install or update command:

{
    "scripts": {
        "auto-scripts": [
        ],
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    }
}

You will get more details in this link