Class Company\Module\Console\ImageImportConsole\Interceptor 不存在

Class Company\Module\Console\ImageImportConsole\Interceptor does not exist

我正在创建自定义命令行以将图像从 M1 导入到 M2。

我已经创建了一个正常工作的命令。现在,我正在尝试调用我的助手 class 进行控制台。但是出现错误 -

In ClassReader.php line 24:
Class Company\Module\Console\ImageImportConsole\Interceptor does not exist

这里是扩展命令class -

<?php
namespace Company\Module\Console;

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

class ImageImportConsole extends Command
{

    const PRODUCT_ID = 'productId'; // key of parameter

    protected $helper;

    public function __construct(
        Company\Module\Helper\Data $helper
    ) {
        $this->helper = $helper;
    }

    protected function configure(){
        $options = [
            new InputOption(
                self::PRODUCT_ID, // the option name
                '-id', // the shortcut
                InputOption::VALUE_REQUIRED, // the option mode
                'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
            ),
        ];
        $this->setName('imageimporttool:start');
        $this->setDescription('Image Import Tool');
        $this->setDefinition($options);
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output){
        $id = $input->getOption(self::PRODUCT_ID);

        // $helper = new Data();
        $this->helper->test();
        // if ($id) {
        //     // $output->writeln("Hi " . $id . ", Success!");
        // } else {
            
        // }

        $output->writeln("Success");
    }
}

当我尝试建立层次时出现此错误。

如何在命令中调用助手class?

  1. 删除 vendor/ 和 运行 composer install
  2. 检查 Company\Module\Console\ImageImportConsole\Interceptor - 它是否存在于您的项目中?也许您只是将此 class 导入其他地方但它不存在?

我觉得其他一切都还好。

运行 命令行:

php bin/magento setup:di:compile
php bin/magento c:f

经过一番研究,我终于找到了解决办法。

我们必须通过 Magento\Framework\App\State 来调用助手 class。

<?php
namespace Company\Module\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Magento\Framework\App\State;

class ImageImportConsole extends Command
{

    const PRODUCT_ID = 'productId'; // key of parameter

    protected $helper;

    public function __construct(
        Company\Module\Helper\Data $helper,
        State $state,
    ) {
        $this->helper = $helper;
        $this->state = $state;
    }

    protected function configure(){
        $options = [
            new InputOption(
                self::PRODUCT_ID, // the option name
                '-id', // the shortcut
                InputOption::VALUE_REQUIRED, // the option mode
                'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
            ),
        ];
        $this->setName('imageimporttool:start');
        $this->setDescription('Image Import Tool');
        $this->setDefinition($options);
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output){
        $id = $input->getOption(self::PRODUCT_ID);

        $this->helper->test();//this we start working

        $output->writeln("Success");
    }
}