MapperFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DB;
  7. /**
  8. * Class MapperFactory
  9. * @package Magento\Framework\DB
  10. */
  11. class MapperFactory
  12. {
  13. /**
  14. * @var \Magento\Framework\ObjectManagerInterface
  15. */
  16. protected $objectManager;
  17. /**
  18. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  19. */
  20. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  21. {
  22. $this->objectManager = $objectManager;
  23. }
  24. /**
  25. * Create Mapper object
  26. *
  27. * @param string $className
  28. * @param array $arguments
  29. * @return MapperInterface
  30. * @throws \Magento\Framework\Exception\LocalizedException
  31. */
  32. public function create($className, array $arguments = [])
  33. {
  34. $mapper = $this->objectManager->create($className, $arguments);
  35. if (!$mapper instanceof MapperInterface) {
  36. throw new \Magento\Framework\Exception\LocalizedException(
  37. new \Magento\Framework\Phrase(
  38. '%1 doesn\'t implement \Magento\Framework\DB\MapperInterface',
  39. [$className]
  40. )
  41. );
  42. }
  43. return $mapper;
  44. }
  45. }