# Laminas-cli : 'dependencies' =\>'factories' ignored

**URL:** <https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246>\
**Category:** Components & MVC\
**Tags:** laminas-cli\
**Created:** [April 14, 2021, 9:39am UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246 "2021-04-14T09:39:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pasglop](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@pasglop](https://discourse.laminas.dev/u/pasglop)\
**Post date:** [April 14, 2021, 9:39am UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246/1 "2021-04-14T09:39:09Z")

</div>

Hello

For information :  
_Laminas MVC Skeleton Application_  
_laminas/laminas-cli 1.0.2_  
_symfony/console v4.4.21_

I would like to use the dependencies in the class of a command as indicated in the laminas/laminas-cli documentation:

**// config/autoload/dependencies.global.php**

```
return [
    'dependencies' => [
        'factories' => [
            Application\Command\HelloWorldCommand::class => Application\Command\HelloWorldCommandFactory::class,
        ],
    ],
];

```

However, these dependencies are never taken:

```
root@srv:/opt/lamtest# ./vendor/bin/laminas helloworld toto
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function Application\Command\HelloWorldCommand::__construct(), 0 passed in /opt/lamtest/vendor/laminas/laminas-cli/src/AbstractContainerCommandLoader.php on line 96 and exactly 1 expected in /opt/lamtest/module/Application/src/Command/HelloWorldCommand.php:20
Stack trace:
#0 /opt/lamtest/vendor/laminas/laminas-cli/src/AbstractContainerCommandLoader.php(96): Application\Command\HelloWorldCommand->__construct()
#1 /opt/lamtest/vendor/laminas/laminas-cli/src/AbstractContainerCommandLoader.php(60): Laminas\Cli\AbstractContainerCommandLoader->createCommand()
#2 /opt/lamtest/vendor/laminas/laminas-cli/src/ContainerCommandLoaderNoTypeHint.php(25): Laminas\Cli\AbstractContainerCommandLoader->getCommand()
#3 /opt/lamtest/vendor/symfony/console/Application.php(548): Laminas\Cli\ContainerCommandLoaderNoTypeHint->get()
#4 /opt/lamtest/vendor/symfony/console/Application.php(641): Symfony\Component\Console\Application->has()
#5 /opt/lamtest/vendor/symfony/co in /opt/lamtest/module/Application/src/Command/HelloWorldCommand.php on line 20

```

I have no idea what to do to fix this.  
Can you please help me?

**Thank you so much.**

========================================================================  
My files :

```
> // config/autoload/global.php
> return [
> 'lstSrv' => ['11', '22', '33'],
> 'laminas-cli' => [
> 'commands' => [
> 'helloworld' => Application\Command\HelloWorldCommand::class,
> ],
> ],
> ];

```

// module/Apllication/src/Command/HelloWorlCommandFactory.php

```
namespace Application\Command;

use Laminas\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
use Application\Command\HelloWorldCommand;

class HelloWorldCommandFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $config = $container->get('Config');
        $lstSrv = $config['lstSrv'];
        
        return new HelloWorldCommand($lstSrv);
    }
}

```

// module/Apllication/src/Command/HelloWorlCommand.php

```
namespace Application\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class HelloWorldCommand extends Command
{
    private $lst = 'nok';
    
    public function __construct($lst)
    {
        $this->lst = $lst[0];
    }
    
    protected function configure()
    {
        $this->addArgument('message', InputArgument::REQUIRED, 'Greeting Message');
    }
 
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $message = $input->getArgument('message');
        $output->writeln(sprintf('<info>Hello to world (' . $this->lst . ') : %s<info>! ', $message));
 
        return 0;
    }
}
```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 14, 2021, 9:46am UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246/2 "2021-04-14T09:46:50Z")

</div>

> [@pasglop](#):
>
> config/autoload/dependencies.global.php

> [@pasglop](#):
>
> config/autoload/global.php

Did you mix up the contents of the files?

---

<div class="post-metadata">

**Author:** ![pasglop](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@pasglop](https://discourse.laminas.dev/u/pasglop)\
**Post date:** [April 14, 2021, 9:50am UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246/3 "2021-04-14T09:50:20Z")

</div>

Sorry  
I had reversed the two. It is corrected

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 14, 2021, 10:10am UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246/4 "2021-04-14T10:10:59Z")

</div>

In a laminas-mvc based application you must use the configuration key `service_manager` and not `dependencies`.

---

<div class="post-metadata">

**Author:** ![pasglop](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@pasglop](https://discourse.laminas.dev/u/pasglop)\
**Post date:** [April 14, 2021, 1:59pm UTC](https://discourse.laminas.dev/t/laminas-cli-dependencies-factories-ignored/2246/5 "2021-04-14T13:59:03Z")

</div>

Thank you !

Full solution :

// config/autoload/dependencies.global.php

```
return [
    'service_manager' => [
        'factories' => [
            Application\Command\HelloWorldCommand::class => Application\Command\HelloWorldCommandFactory::class,
        ],
    ],
];

```

// module/Apllication/src/Command/HelloWorlCommand.php

```
...
    public function __construct($lst)
    {
        $this->lst = $lst[0];
        parent::__construct();
    }
 ...
```
