首页 > 解决方案 > 预计在从资源导入服务时在文件中找到类...,但没有找到

问题描述

因此,我目前尝试使用 SyliusandFriendsImportExport-Plugin 添加 CustomerPorcessor,但是当我尝试通过 docker 启动项目时出现此错误:

Expected to find class "App\Processor\CustomerProcessor" in file "/srv/sylius/src/Processor/CustomerProcessor.php" while importing services from resource "../src/*", but it was not found! Check the namespace prefix used with the resource in /srv/sylius/config/services.yaml (which is loaded in resource "/srv/sylius/config/services.yaml").

我已经尝试过更改命名空间,但没有成功,但在 git 示例中,它们的操作与我相同:

https://github.com/FriendsOfSylius/SyliusImportExportPlugin/blob/master/src/Processor/PaymentMethodProcessor.php#L14

https://github.com/FriendsOfSylius/SyliusImportExportPlugin/blob/master/src/Resources/config/services_import_csv.yml#L34

https://github.com/FriendsOfSylius/SyliusImportExportPlugin/blob/master/src/Resources/config/services.yml#L245

services_ImportExportPlugin.yaml:

sylius.processor.customer:
        class: FriendsOfSylius\SyliusImportExportPlugin\Processor\CustomerProcessor
        arguments:
            - "@sylius.factory.customer"
            - "@sylius.repository.customer"
            - "@sylius.importer.metadata_validator"
            - "@doctrine.orm.entity_manager"
            - '["id", "customer_group_id", "email", "first_name", "last_name", "birthday", "gender", "phone_number", "since", "title", "verificationCode", "hasApp", "street", "street_number", "postcode", "city", "opt_in_post", "opt_in_phone", "opt_in_email"]'

客户处理器.php:


<?php

namespace FriendsOfSylius\SyliusImportExportPlugin\Processor;

use Doctrine\ORM\EntityManagerInterface;
use FriendsOfSylius\SyliusImportExportPlugin\Exception\ImporterException;
use Payum\Core\Model\GatewayConfigInterface;
use Sylius\Component\Core\Factory\CustomerMethodFactoryInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
final class CustomerProcessor implements ResourceProcessorInterface
{
    /** @var CustomerMethodFactoryInterface */
    private $resourceFactory;
    /** @var RepositoryInterface */
    private $resourceRepository;
    /** @var MetadataValidatorInterface */
    private $metadataValidator;
    /** @var EntityManagerInterface */
    private $entityManager;
    /** @var string[] */
    private $headerKeys;
    /**
     * @param string[] $headerKeys
     */
    public function __construct(
        CustomerMethodFactoryInterface $factory,
        RepositoryInterface $repository,
        MetadataValidatorInterface $metadataValidator,
        EntityManagerInterface $entityManager,
        array $headerKeys
    ) {
        $this->resourceFactory = $factory;
        $this->resourceRepository = $repository;
        $this->metadataValidator = $metadataValidator;
        $this->headerKeys = $headerKeys;
        $this->entityManager = $entityManager;
    }
    public function process(array $data): void
    {
        $this->metadataValidator->validateHeaders($this->headerKeys, $data);
        $CustomerMethod = $this->getCustomerMethod($data['Code'], $data['Gateway']);
        $gatewayConfig = $this->getGatewayConfig($data, $CustomerMethod);
        $gatewayConfig->setGatewayName($data['Name']);
        $CustomerMethod->setGatewayConfig($gatewayConfig);
        $CustomerMethod->setName($data['Name']);
        $CustomerMethod->setInstructions($data['Instructions']);
        $this->entityManager->persist($CustomerMethod);
    }
    private function getCustomerMethod(string $code, string $gateway): CustomerInterface
    {
        /** @var CustomerInterface|null $CustomerMethod */
        $CustomerMethod = $this->resourceRepository->findOneBy(['code' => $code]);
        if ($CustomerMethod === null) {
            /** @var CustomerInterface $CustomerMethod */
            $CustomerMethod = $this->resourceFactory->createWithGateway($gateway);
            $CustomerMethod->setCode($code);
        }
        return $CustomerMethod;
    }
    /**
     * @param mixed[] $data
     */
    private function getGatewayConfig(array $data, CustomerInterface $CustomerMethod): GatewayConfigInterface
    {
        $gatewayConfig = $CustomerMethod->getGatewayConfig();
        if (null === $gatewayConfig) {
            throw new ImporterException('Gateway does not exist:' . $data['Gateway']);
        }
        return $gatewayConfig;
    }
}

所以我的预期结果将是一个无错误的运行,但我仍然收到上述错误。

标签: csvsymfonysymfony4syliuscsv-import

解决方案


推荐阅读