Execute laminas-cli command from MVC

I finally took the time to migrate to laminas-cli.

From a controller, I wish to call one of my commands directly (I used dispatch() from within an AbstractActionController) before. Is there a built-in-method to execute a command directly from within a MVC-Controller?

Hello and welcome to our forums! :smiley:

The controller handles an HTTP request, and now you want to call a CLI command of the same application?! It works with plain PHP but it is the same application, therefore I think it should be something like this:

class MyCommand
{
    private MyService $service;

    // …

    protected function execute(…)
    {
        $this->service->doSomething();
    }
}
class MyController
{
    private MyService $service;

    // …

    protected function someAction()
    {
        $this->service->doSomething();
    }
}

Thanks!

This is what I will do. I was first looking for another (more complicated, granted) way such as explained in How to Call a Command from a Controller (Symfony Docs).