AppBundle Command is not autoloaded?

I have created the command in AppBundle/Command/TestCommand.php. It is not loaded - I can’t see it in ./bin/console list?

The Command looks like (exactly like the one in PIMCORE docs):

namespace AppBundle\Command;

use Pimcore\Console\AbstractCommand;
use Pimcore\Console\Dumper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestCommand extends AbstractCommand
        protected function configure()
                ->setDescription('Awesome command');

    protected function execute(InputInterface $input, OutputInterface $output)
        // dump
        $this->dump("Isn't that awesome?");

        // add newlines through flags
        $this->dump("Dump #2", Dumper::NEWLINE_BEFORE | Dumper::NEWLINE_AFTER);

        // only dump in verbose mode
        $this->dumpVerbose("Dump verbose", Dumper::NEWLINE_BEFORE);

        // Output as white text on red background.
        $this->writeError('oh noes!');
} ...

PIMCORE 6.3.3, PHP 7.3.8

If I add

            - { name: 'console.command', command: 'awesome:command' }

to services.yml the command is loaded. Why isn’t it done by autoloader??

Commands aren’t registered automatically anymore when you just add them to the Command directory, you have to register them now:

The reason basically is: better performance

1 Like

@dpfaffenbauer wouldn’t another solution also be to add the autoload/autowire config as it was done for, say, Controller folder? I mean, I haven’t tried because I’m an advocate of strictly declaring services (IMO, the less magic, the better), but wouldn’t it, in theory at least, work as well?

not sure if that works for commands. they actually deprecated auto registering commands in Symfony 3.4 and removed it 4.0, not sure if they did something with autoconfigure/autowire for commands. I am on your side regarding magic: the less the better, even though I have to commit, for projects, using autowire and autoconfigure makes so much sense, not for reusable Bundles though.