Laminas-cli: There are no commands defined in the "order" namespace

I somehow don’t understand the intro fully. I added the configurations either directly as described in the first four steps at Introduction - laminas-cli - Laminas Docs or I added in the module configuration. I always get the error message There are no commands defined in the "order" namespace. The command I want to implement is order:import-orders. Is the namespace written here about the PHP namespace? Because in the linked documentation it is written as “package”. So somehow I assume it is something totally different.

Can someone enlighten me?

Can you show us your config?

Sure. The module.config.php has the following entries:

    'dependencies' => [
        'factories' => [
            \Order\Console\OrderImport::class => \Order\Console\Factory\OrderImportFactory::class,
        ],
    ],
    'laminas-cli' => [
        'commands' => [
            'order:import-orders' => Console\OrderImport::class,
             ],
    ]

I already tried to move the dependencies to the file config/autoload/dependencies.global.php but this didn’t help much either. Then I tried to move the "laminas-cli array to the global.php config but this didn’t help either.

Shouldn’t one be using FCQN everywhere rather than in some cases? In your opinion both below FCQN are the same?

'some-factory' => \Order\Console\OrderImport:class,
'I-call-it-like' => Console\OrderImport::class 

Thanks!

I already tried both versions. I tried the FCQN because i moved this part of the code once to the dependencies.global.php as written above. So this is not the solution. But thanks anyway.

Hey …

The exception was thrown directly from the symfony console component, from which laminas-cli inherits. Symfony console tries to fiend a namespace, which is obviously not defined.

First of all … you are using Laminas MVC and not the middleware components of Mezzio, right? The service manager used with Laminas MVC does not use a dependency config entry. Have you tried a service_manager config entry instead?

// config/module.config.php
namespace Order;
return [
    'service_manager' => [
        'factories' => [
            Console\OrderImport::class => Console\Factory\OrderImportFactory::class,
        ],
    ],
    'laminas_cli' => [
        'commands' => [
            'order:import-orders' => Console\OrderImport::class,
         ],
    ]
];

The given example from Introduction - laminas-cli - Laminas Docs works with a global config/autoload/dependencies.global.php file, which is stated out in the given components example.

1 Like

Thanks @ezkimo. Yes, I do use Laminas MVC. I tried it now with the service_manager but no luck either. Do I have to write now a ConfigProvider or is this only needed for Mezzio? It looks to me like a lot in there is configured like what I already have in the module.config.php

@modir,
One of the differences between Mezzio and Laminas MVC is that Laminas MVC reads/registers a module via Module.php file and Mezzio with ModuleName:space::ConfigProvider::class. If you want your module to be used in Mezzio then and only then use the ConfigProvider::class otherwise everything is fine.

If you analyze the code it is doing exactly the something when you configure a module via a module.config.php file. As I’ve said above the usage of ConfigProvider class is there if you want to use/reuse your module in Mezzio. Even then it will not be a walk in the park.

From what I’ve understood from your conversation is that you’ve only followed the what is written in the tutorial and that is the code itself. It might be the case that you’ve not registered your Module in composer.json file. Have you add this line in your composer.json file?

//composer.json file
{
     ...
    "autoload": {
        "psr-4": {
            //Do you've got this line in your composer.json file?
            "Order\\": "module/Order/src/"
        },
    }
}

If not, then after adding the above line do the following.

composer autoload-dump
composer clear-config-cache

I hope I’ve answered your question.

Yes, I have this code in my composer.json file. My module is working for already 5 years. I am in the process of moving from laminas-console to laminas-cli. And I just can’t get laminas-cli to work.

I got it working now. The problem was a mix of not having the service_manager config plus then forgetting to clear the config cache at the end. Stupid me. Thanks everyone.

Thanks for letting me know I was speaking an alien language.

Typical problem. The development mode helps:

@ALTAMASH80 When two developers are not on the same level then it can indeed happen that some text from one person is to the other like alien language. Now in retrospective it makes sense what you wrote. I just couldn’t connect it with my problem.

Very good point from you @froschdesign At the moment we are slowly getting more modern with the code. At one time I will clean this up as well.

@modir
The

“order:”

portion here is the namespace.

Take the following example

    public function getConsoleConfig(): array
    {
        return [
            'commands' => [
                'axleus:db:write-config' => Console\Command\DbConfigCommand::class,
                'axleus:db:create'       => Console\Command\BuildDbCommand::class,
            ],
        ];
    }

Those commands live in the Php namespace:
namespace Axleus\DevTools\Console\Command;

The command namespace is axleus:db: which is independent of the Php namespace.

This allows you to aggregate commands from many different “modules/components” into a single “suite” of commands exposed by the application.

In this example they are all for the axleus application, the example targets the db component.

Thanks. This was an important part of the information I was missing. The documentation was just not very clear on this.