MapperPool.php 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 MapperPool
  10. */
  11. class MapperPool
  12. {
  13. /**
  14. * @var string[]
  15. */
  16. private $mappers;
  17. /**
  18. * @var ObjectManagerInterface
  19. */
  20. protected $objectManager;
  21. /**
  22. * @param ObjectManagerInterface $objectManager
  23. * @param string[] $mappers
  24. */
  25. public function __construct(
  26. ObjectManagerInterface $objectManager,
  27. $mappers = []
  28. ) {
  29. $this->objectManager = $objectManager;
  30. $this->mappers = $mappers;
  31. }
  32. /**
  33. * Get mapper for entity type
  34. * @param string $entityType
  35. * @return MapperInterface
  36. */
  37. public function getMapper($entityType)
  38. {
  39. $className = isset($this->mappers[$entityType]) ? $this->mappers[$entityType] : MapperInterface::class;
  40. return $this->objectManager->get($className);
  41. }
  42. }