从昨天开始我就一直在使用 Symfony 3,但在自动布线方面遇到了困难。
出于某种原因,FileLoader 无法找到我的类,而它确实存在。
在 services.yml 我有以下内容:
services:
_defaults:
autowire: true
autoconfigure: true
public: true
RideShare\Infrastructure\:
resource: '../../src/RideShare/Infrastructure/*'
文件夹src/RideShare/Infrastructure/EventStore/Doctrine
中有DoctrineEventStore.php
包含以下内容的文件:
<?php
namespace RideShare\Infrastructure\EventStore\Doctrine;
use ...;
class DoctrineEventStore extends EntityRepository implements EventStore
但是当我尝试运行时php bin/console
,出现以下异常:
Symfony\Component\Config\Exception\FileLoaderLoadException:
Expected to find class "RideShare\Infrastructure\EventStore\Doctrine\DoctrineEventStore" in file "[....]src/RideShare/Infrastructure/EventStore/Doctrine/DoctrineEventStore.php" while importing services from resource
"../../src/RideShare/Infrastructure/*", but it was not found! Check the namespace prefix used with the resource in [...]/app/config/services.yml (which is being imported from "[...]/app/config/config.yml"). in [...]/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 179
对于我看到的这个声明是正确的,我在 stackoverflow 或 Symfony 文档中没有看到这样的问题,我也不知道它为什么会失败。
完整代码可以在Github上找到。