Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to move the console "Command" folder from it's default directory and avoiding the Exception: Command "name" is not defined?

By default the console command folder is in: MyProject\MyBundle\Command and all works as expected, but if I move the folder in another directory like :MyProject\MyBundle\MyFolder\Command on command execution it thrown an: [InvalidArgumentException] Command "command_name" is not defined.

I haven't been able to find anything useful after searching over the internet and reading all the documentation possibly related to this problem...

The question is: Exist a mode to move that folder or I'll be forced to use the default folder?

Thanks!

like image 628
gp_sflover Avatar asked Jan 08 '23 20:01

gp_sflover


2 Answers

You can define it as a service:

my_command:
    class: MyProject\MyBundle\MyFolder\Command\MyCommand
    tags:
        -  { name: console.command }

You can read more about this method in Symfony documentation.

like image 91
chapay Avatar answered Jan 16 '23 09:01

chapay


Take a look at Symfony\Component\HttpKernel\Bundle\Bundle::registerCommands

As you can see, the Command directory is hard wired in. There is no option for changing it via configuration. If you really really really wanted to change the folder then override and clone this method in your MyBundle class. But it hardly seems worth the effort.

Using services (as @Andrey Sobkanyuk) suggested is probably a better long term solution.

like image 31
Cerad Avatar answered Jan 16 '23 09:01

Cerad