1

How to use factory to create services with 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

How to use "setFactory" method now in my case ? Docs: http://symfony.com/doc/master/components/dependency_injection/factories.html

Thanks!

acubens
  • 472
  • 1
  • 8
  • 17

1 Answers1

2

I think related documentation is clear. Try this configuration:

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

Deprecated errors are an preparation for upcomming Symfony 3.0. Some features (like factory_service|factory_method) will be removed. Here is a thread where you can find solutions to disabling Symfony deprecated errors if you really don't need it.

Community
  • 1
  • 1
kba
  • 4,190
  • 2
  • 15
  • 24