gpt4 book ai didi

php - 如何编写一个依赖 Doctrine 并提供实体的 symfony 包?

转载 作者:行者123 更新时间:2023-12-03 23:22:04 25 4
gpt4 key购买 nike

我正在尝试编写一个邮件队列包,用于将电子邮件事件存储到一个位置并稍后检索它们并处理它们,因为我们不使用像 mandrill 之类的服务。

对于(我的确切用例在这里并不是真正感兴趣),我喜欢在我的包中提供额外的实体,因为我的包提供了一个 BufferedDatabaseMailQueue。

由于一些研究,我在包的 config.yml 中包含了以下(尚未测试的)行:

doctrine:
orm:
auto_mapping: false
mappings:
AcmeDemoBundle:
type: annotation
alias: MyMailQueueBundle
prefix: MyMailQueueBundle\Entity
dir: %kernel.root_dir%/../src/MyMailQueueBundle/Entity
is_bundle: true

无论如何,我最终会收到此错误消息:

InvalidArgumentException in YamlFileLoader.php line 404: There is no extension able to load the configuration for "doctrine"



研究表明, PrependExtensionInterface可能会以某种方式帮助我。但我不知道如何正确使用和配置它。这样我的 Bundle 就可以基于教义。

我怎么做?

最佳答案

我使用以下代码管理它:

<?php

namespace AltergearMailQueueBundle;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MyMailQueueBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
/*
* To extend the bundle to work with mongoDB and couchDB you can follow this tutorial
* http://symfony.com/doc/current/doctrine/mapping_model_classes.html
* */

parent::build($container);
$ormCompilerClass = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';

if (class_exists($ormCompilerClass))
{

$namespaces = array( 'MyMailQueueBundle\Entity' );
$directories = array( realpath(__DIR__.'/Entity') );
$managerParameters = array();
$enabledParameter = false;
$aliasMap = array('MyMailQueueBundle' => 'MyMailQueueBundle\Entity');
$container->addCompilerPass(
DoctrineOrmMappingsPass::createAnnotationMappingDriver(
$namespaces,
$directories,
$managerParameters,
$enabledParameter,
$aliasMap
)
);
}


}
}

关于php - 如何编写一个依赖 Doctrine 并提供实体的 symfony 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38745476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com