HydratorPool.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\EntityManager;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * Class HydratorPool
  10. */
  11. class HydratorPool
  12. {
  13. /**
  14. * @var HydratorInterface[]
  15. */
  16. private $hydrators;
  17. /**
  18. * @var ObjectManagerInterface
  19. */
  20. protected $objectManager;
  21. /**
  22. * @param ObjectManagerInterface $objectManager
  23. * @param string[] $hydrators
  24. */
  25. public function __construct(
  26. ObjectManagerInterface $objectManager,
  27. $hydrators = []
  28. ) {
  29. $this->objectManager = $objectManager;
  30. $this->hydrators = $hydrators;
  31. }
  32. /**
  33. * @param string $entityType
  34. * @return HydratorInterface
  35. */
  36. public function getHydrator($entityType)
  37. {
  38. if (isset($this->hydrators[$entityType])) {
  39. return $this->objectManager->get($this->hydrators[$entityType]);
  40. } else {
  41. return $this->objectManager->get(HydratorInterface::class);
  42. }
  43. }
  44. }