1

I am trying add custom command for beginning 'hello world'. I'm doing all by guide but always have this error

[ReflectionException]
Class Hesoy\HelloWorld\Console\Command\HelloWorldCommand does not exist

This is my setup steps:

  1. Clear cache
  2. setup:upgrade

This is my files

Command

namespace Hesoy\HelloWorld\Console\Command;


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

class HelloWorldCommand extends Command
{
    public function __construct($name = null)
    {
        parent::__construct($name);
    }

    protected function configure()
    {
        $this->setName('hesoy:hello-world')
            ->setDescription('Hello world');

        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Hello world!');
    }
}

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Console\CommandListInterface">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="helloWorld" xsi:type="object">Hesoy\HelloWorld\Console\Command\HelloWorldCommand</item>
            </argument>
        </arguments>
    </type>
</config>

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Hesoy_HelloWorld" setup_version="0.1.0">
    </module>
</config

registration.php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Hesoy_HelloWorld',
    __DIR__
);
1

Invalid di.xml. Please correct it.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Console\CommandListInterface">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="helloWorld" xsi:type="object">Hesoy\HelloWorld\Console\Command\HelloWorldCommand</item>
            </argument>
        </arguments>
    </type>
</config>
  • Thanks for answer, this is my typo. Edited question. – hesoy Jan 21 '18 at 0:28
0

So idiot mistake, it was wrong module [VendorName]/[ModuleName]. Was app/code/hesoy/hello-world and need app/code/Hesoy/HelloWorld.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.