2016-08-03 40 views
0

我正在嘗試編寫一個郵件隊列包,用於將電子郵件事件存儲到某個位置,並在稍後檢索並處理它們,因爲我們不使用像mandrill或類似的服務。如何編寫一個依賴於Doctrine並提供實體的symfony包?

對於(和我的確切用例在這裏沒有真正的興趣),我喜歡在我的包中提供額外的實體,因爲我的包提供了一個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在YamlFileLoader.php行404:沒有 擴展能夠加載「原則」的配置

研究指出,PrependExtensionInterface可能以某種方式幫助我。但我不知道如何正確使用和配置它。這樣我的Bundle可以基於教義。

我該怎麼做?

+1

通常這一類的東西,會去在應用程序的config.yml。 – Cerad

+0

好的,但捆綁XY的商店實體是一個捆綁interna不是嗎? –

+0

大多數軟件包要求用戶在config.yml中添加這些行。請參閱第3步:https://symfony.com/doc/master/bundles/StofDoctrineExtensionsBundle/index.html – Alsatian

回答

0

我設法它使用此代碼:

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


    } 
} 
相關問題