CompositeMapper.php 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\EntityManager;
  7. /**
  8. * Class CompositeMapper
  9. */
  10. class CompositeMapper implements MapperInterface
  11. {
  12. /**
  13. * @var MapperInterface[]
  14. */
  15. private $mappers;
  16. /**
  17. * @param MapperInterface[] $mappers
  18. */
  19. public function __construct(
  20. $mappers
  21. ) {
  22. $this->mappers = $mappers;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function entityToDatabase($entityType, $data)
  28. {
  29. foreach ($this->mappers as $mapper) {
  30. $data = $mapper->entityToDatabase($entityType, $data);
  31. }
  32. return $data;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function databaseToEntity($entityType, $data)
  38. {
  39. foreach ($this->mappers as $mapper) {
  40. $data = $mapper->databaseToEntity($entityType, $data);
  41. }
  42. return $data;
  43. }
  44. }