Trouble getting started with laminas-cli and mvc app

I’ve read the instructions but clearly I’m missing something. I installed laminas-cli via composer as instructed. Then I created this config and put it in config/autoload/laminas-cli.global.php:

<?php
return [
    'laminas-cli' => [
        'commands' => [
            'admin:test' => \InterpretersOffice\Admin\Service\TestCommand::class,
        ],
    ],
];

and confirmed that this config was being read.

Then I created a module/Admin/src/Service/TestCommand.php:

<?php
namespace InterpretersOffice\Admin\Service;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class TestCommand extends Command {
    public function configure()
    {

    }
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input,$output);
        $io->success("Test has succeeded.");
        return 0;
    }
}

and I confirmed that the composer’s autoloader was able to load it. Then I said:

vendor/bin/laminas admin:test

and got

The command "admin:test" does not exist.

and I can’t say I’m surprised. It feels like I’m missing a step or two but haven’t been able to figure it out.

btw I’ve read this thread about setting up cli more than once and have considered trying some of that advice, but I thought maybe the laminas-cli does some of that for us.

Thanks.

I didn’t look at your code, but please remember: at the moment laminas-cli is under development and so far there is no release. It is therefore possible that not everything works as described or the description itself is incorrect.

Ah, OK thanks. That would explain it :wink:

You can test version 0.1.0 now:

Did you make a factory for the command? or add it to ‘invokables’?

return [
  'invokables' => [
    Command::class => Command::class,
  ],
];

Yes, sort of — it looks like I omitted something from the snippets I put in the original post. The config I have is

<?php
return [

    'laminas-cli' => [
        'commands' => [
            'admin:test' => InterpretersOffice\Admin\Service\TestCommand::class,

        ],
    ],
    'dependencies' => [
        'invokables' => [
            InterpretersOffice\Admin\Service\TestCommand::class =>  InterpretersOffice\Admin\ServiceTestCommand::class,
        ],
    ],   
];

because that’s what the instructions seemed to say, although “dependencies” sounds more like Mezzio than MVC.

Yes, sorry, I don’t really use MVC anymore - I was here writing this RFC when I saw your post and thought “Aha, maybe that’s it!”

I see two things:

  • Use the service_manager key instead of the dependencies key in your configuration. dependencies is used by Mezzio, while the MVC uses service_manager (the reason is because Mezzio allows any PSR-11 container, while the MVC currently only allows laminas-servicemanager).

  • configure() and execute both need to be declared as protected, IIRC.

Thanks! I bet that will do the trick. I’ve since moved on and just solved what I was dealing with by other, more crude methods, even discarded some of the code I was playing with. Soon as I get a chance I will give it another go. Maybe even come up with a PR to add this point to the documentation :slight_smile: