php - 找不到要加载的任何夹具服务
问题描述
我知道这个问题已经被问过很多次了:
- Symfony 3.4 和 Fixtures Bundle 与 bundle 版本 3.0 的问题
- Symfony 3.4.0 找不到要加载的任何夹具服务
- Symfony Doctrine 找不到要加载的装置
- 找不到要加载的任何夹具服务 - 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: 抱歉,伙计们忘记指出错误消息:“找不到要加载的任何固定装置服务”
解决方案
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).
推荐阅读
- bash - Bash:在不使用组 ID 的情况下杀死进程和所有子进程
- excel - 有没有办法在 UserForms 上自动增加 ID
- php - 为什么 Symfony 框架能够使用注释区域来识别实体文件?
- asynchronous - 返回响应后 Lambda 可以继续吗?
- kubernetes - 如何访问所有主机的入口?
- python - Keras ResNet -- Val acc 没有改善,val loss 波动,甚至数据集
- flutter - 如何在本地更改 Flutter 插件代码
- java - 如何翻转使用 Graphics 或 Graphics2D 创建的点相对于中心点的位置
- azure - 使用 IoT 删除已注册的设备
- c# - 如何使用 articleName=sample-article-name [MVC Core2.2] 将“www.example.com/sample-article-name”路由到 RazorPage Index.cshtmll