Module installer actions by composer scripts

Hello people

I want to add some actions for installing/updating/removing modules by composer, for example when anyone installs a module by composer, the installer creates a database and imports access information for RBAC to the database. in update process do new changes in database and more and same

I see I can use composer script like this

  "scripts": {
    "post-install-cmd": [
      "php -r 'if (file_exists(\"bin/post-install.php\")) include \"bin/post-install.php\";'"
    ],
    "post-update-cmd": [
      "php -r 'if (file_exists(\"bin/post-update.php\")) include \"bin/post-update.php\";'"
    ],
    "post-package-uninstall": [
      "php -r 'if (file_exists(\"bin/post-remove.php\")) include \"bin/post-remove.php\";'"
    ]
  },

I have some questions:
1- Do you have any plan to add features like this for managing modules in MVC?
2- What is the best practice?
3- In bin/post-install.php, I run PHP codes out of MVC, If I write installer service in my modules and want to call it in this PHP file, it’s very hard and I have to load most of my written class in the file. Does any shortcut or method available for doing it?

thanks

I have been thinking that I wanted to do something similar, but am now wondering if it would be easier to accomplish it via adding console support.

1 Like

It’s a good idea, I had a problem running scripts via composer, too many dependencies are necessary.

did you have time to test it? its work for you?

Use laminas-cli and you can use the entire service container of your application.

1 Like

The current plan is to use CLI commands.

Use laminas-cli. (see my previous comment)

1 Like

Thank you very much, I work on it in the next few days

We start work on some new simple applications with laminas and worked on writing (converting) some modules to laminas.

My plan is to publish all of them as open-source, then I want all of them to be a standard for general usage by everyone

Best

Sorry I was short of time when I replied earlier. As @froschdesign pointed out the cli loads like any other component so you have access to everything you will need. Ive only barely tested it but from the initial testing I did it will work exactly as you need it too. I am 100% certain it will meet my needs, which is pretty much the same as yours.

1 Like

Thank you very much, In next week I will start work on writing the installer on CLI.
I just read CLI docs very short and I see it’s very useful. I can handle some of my problems by using it

thank you very much for help me @Tyrsson @froschdesign , I will tell you result