2015-06-04 70 views
1

如何使用工廠創建symfony2.7服務?使用工廠創建symfony2.7服務

#service.yml 
#in symfony 2.6 
my.repository.photo: 
    class: My\AppBundle\Repository\PhotoRepository 
    factory_method: getRepository 
    factory_service: doctrine 
    arguments: [My\AppBundle\Entity\Photo] 

#I have some errors like this 
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryMethod(getRepository) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in /my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 137 
Deprecated: Symfony\Component\DependencyInjection\Definition::setFactoryService(doctrine) is deprecated since version 2.6 and will be removed in 3.0. Use Definition::setFactory() instead. in my/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php on line 208 

如何在我的情況下使用「setFactory」方法? Docs:http://symfony.com/doc/master/components/dependency_injection/factories.html

謝謝!

回答

2

我認爲相關文件很清楚。試試這個配置:

my.repository.photo: 
    class: My\AppBundle\Repository\PhotoRepository 
    factory: ["@doctrine", getRepository] 
    arguments: [My\AppBundle\Entity\Photo] 

棄用的錯誤是upcomming Symfony 3.0的準備。一些功能(如factory_service | factory_method)將被刪除。如果你真的不需要它,你可以在這裏找到解決方案to disabling Symfony deprecated errors