首页 > 解决方案 > 找不到要加载的任何夹具服务

问题描述

我知道这个问题已经被问过很多次了:

  1. Symfony 3.4 和 Fixtures Bundle 与 bundle 版本 3.0 的问题
  2. Symfony 3.4.0 找不到要加载的任何夹具服务
  3. Symfony Doctrine 找不到要加载的装置
  4. 找不到要加载的任何夹具服务 - Symfony 3.2

以上都没有真正帮助我。也就是说,这是我的配置:

作曲家.json

"require": {
"php": ">=7.0",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
....
},
    "require-dev": {
        ....
        "doctrine/doctrine-fixtures-bundle": "^3.0",
}

我正在使用公司开发的 Bundle,它在上述最后一个版本之前运行良好(最后测试和工作配置有 PHP 5.6,Doctrine bundle ^1.6,doctrine orm ^2.5,fixture bundle ^3.0)。

这个包在VendorName/BundleName/DataFixtures/ORM中有一些 Fixture ,所有的 Fixture 都有以下声明:

Class MyFixture1 extends Fixture implements OrderedFixtureInterface,FixtureInterface, ContainerAwareInterface{
    ...
}

在这个包里面有一个 services.yml 文件,由这个加载:

public function load(array $configs, ContainerBuilder $container)
{
    $configuration = new Configuration();
    $config = $this->processConfiguration($configuration, $configs);

    $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
    $loader->load('services.yml');
}

VendorName/BundleName/Resources/config/Services.yml 我尝试了不同的配置:

services:
_defaults:
  autowire: true
  autoconfigure: true
  public: false

VendorName\BundleName\:
  resource: '../../*'
  # you can exclude directories or files but if a service is unused, it's removed anyway
  exclude: '../../{Entity,Repository,Tests,EventListener}'

我尝试在 DataFixtures 中显式搜索:

 VendorName/BundleName\DataFixtures\:
  resource: '../../src/VendorName/BundleName/DataFixtures'
  tags: ['doctrine.fixture.orm']

甚至手动配置服务:

VendorName\BundleName\DataFixtures\ORM\MyFixture1:
  class: VendorName/BundleNamee\DataFixtures\ORM\MyFixture1
  tags: ['doctrine.fixture.orm']

但不幸的是,它不断给出错误。知道我做错了什么吗?很久以前可以手动指定要查看哪个包的fixture命令,但现在不再可能了

更新 1: 抱歉,伙计们忘记指出错误消息:“找不到要加载的任何固定装置服务”

标签: phpsymfonydoctrinesymfony-3.4

解决方案


The accepted answer helped point me in the right direction to get this working. Though cache could indeed be a problem, having Fixtures in your own bundles does require you to register them.

Using SF 5.1.* I created a services_dev.yaml file and added in:

services:
  // other config
  Namespace\Registered\In\Composer\For\Fixtures\:
    resource: '../vendor/path/registered/in/composer/to/fixtures'
    tags: ['doctrine.fixture.orm']

Then indeed, clear cache and it should work.

Added *_dev to the services.yaml file as it's a way for Symfony to only load it in when in your in a dev environment (per APP_ENV Environment variable).


推荐阅读