如何编写依赖于 Doctrine 并提供实体的 symfony 包?

Jak*_*ler 6 php symfony doctrine-orm

我正在尝试编写一个邮件队列包,用于将电子邮件事件存储到某个位置并稍后检索并处理它们,因为我们不使用像 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
Run Code Online (Sandbox Code Playgroud)

不管怎样,我最终得到了这个错误消息:

YamlFileLoader.php 第 404 行中的 InvalidArgumentException:没有扩展能够加载“doctrine”的配置

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

我怎么做?

Jak*_*ler 4

我使用这段代码管理它:

<?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
                )
            );
        }


    }
}
Run Code Online (Sandbox Code Playgroud)