ManagerConfigurator.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Doctrine Bundle
  4. *
  5. * The code was originally distributed inside the Symfony framework.
  6. *
  7. * (c) Fabien Potencier <fabien@symfony.com>
  8. * (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
  9. *
  10. * For the full copyright and license information, please view the LICENSE
  11. * file that was distributed with this source code.
  12. */
  13. namespace Doctrine\Bundle\DoctrineBundle;
  14. use Doctrine\ORM\EntityManager;
  15. /**
  16. * Configurator for an EntityManager
  17. *
  18. * @author Christophe Coevoet <stof@notk.org>
  19. */
  20. class ManagerConfigurator
  21. {
  22. private $enabledFilters = array();
  23. /**
  24. * Construct.
  25. *
  26. * @param array $enabledFilters
  27. */
  28. public function __construct(array $enabledFilters)
  29. {
  30. $this->enabledFilters = $enabledFilters;
  31. }
  32. /**
  33. * Create a connection by name.
  34. *
  35. * @param EntityManager $entityManager
  36. */
  37. public function configure(EntityManager $entityManager)
  38. {
  39. $this->enableFilters($entityManager);
  40. }
  41. /**
  42. * Enable filters for an given entity manager
  43. *
  44. * @param EntityManager $entityManager
  45. *
  46. * @return null
  47. */
  48. private function enableFilters(EntityManager $entityManager)
  49. {
  50. if (empty($this->enabledFilters)) {
  51. return;
  52. }
  53. $filterCollection = $entityManager->getFilters();
  54. foreach ($this->enabledFilters as $filter) {
  55. $filterCollection->enable($filter);
  56. }
  57. }
  58. }