doctrine.rst 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. Doctrine Integration
  2. ====================
  3. .. versionadded : 1.1
  4. Doctrine Integration was added.
  5. Configuration
  6. -------------
  7. Doctrine integration is enabled by default. However, you can easily disable it
  8. in your configuration:
  9. .. configuration-block ::
  10. .. code-block :: yaml
  11. jms_di_extra:
  12. doctrine_integration: false
  13. .. code-block :: xml
  14. <jms-di-extra doctrine-integration="false" />
  15. Injecting Dependencies Into Repositories
  16. ----------------------------------------
  17. If you have enabled Doctrine integration, you can now inject dependencies into
  18. repositories using annotations:
  19. .. code-block :: php
  20. use JMS\DiExtraBundle\Annotation as DI;
  21. class MyRepository extends EntityRepository
  22. {
  23. private $uuidGenerator;
  24. /**
  25. * @DI\InjectParams({
  26. * "uuidGenerator" = @DI\Inject("my_uuid_generator"),
  27. * })
  28. */
  29. public function setUuidGenerator(UUidGenerator $uuidGenerator)
  30. {
  31. $this->uuidGenerator = $uuidGenerator;
  32. }
  33. // ...
  34. }
  35. .. note ::
  36. If you do not want to use annotations, you can also implement
  37. ``Symfony\Component\DependencyInjection\ContainerAwareInterface`` in your
  38. repositories to receive the entire service container.