MapperFactoryProxy.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Api\Utility;
  7. use Magento\Store\Model\ScopeInterface;
  8. use Vertex\Mapper\MapperFactory;
  9. use Vertex\Tax\Model\Api\ConfigBuilder;
  10. use Vertex\Utility\VersionDeterminer;
  11. /**
  12. * Retrieve a mapper based on Magento configuration
  13. */
  14. class MapperFactoryProxy
  15. {
  16. /** @var ConfigBuilder */
  17. private $configBuilder;
  18. /** @var MapperFactory */
  19. private $factory;
  20. /** @var VersionDeterminer */
  21. private $versionDeterminer;
  22. /**
  23. * @param MapperFactory $factory
  24. * @param VersionDeterminer $versionDeterminer
  25. * @param ConfigBuilder $configBuilder
  26. */
  27. public function __construct(
  28. MapperFactory $factory,
  29. VersionDeterminer $versionDeterminer,
  30. ConfigBuilder $configBuilder
  31. ) {
  32. $this->factory = $factory;
  33. $this->versionDeterminer = $versionDeterminer;
  34. $this->configBuilder = $configBuilder;
  35. }
  36. /**
  37. * Retrieve a mapper instance given a MapperInterface
  38. *
  39. * @param string $mapperInterface Mapper Interface to create
  40. * @param string|null $scopeCode Scope ID to use for configuration
  41. * @param string $scopeType Scope Type
  42. * @return mixed
  43. * @throws \Vertex\Exception\ConfigurationException
  44. */
  45. public function getForClass($mapperInterface, $scopeCode = null, $scopeType = ScopeInterface::SCOPE_STORE)
  46. {
  47. $config = $this->configBuilder
  48. ->setScopeCode($scopeCode)
  49. ->setScopeType($scopeType)
  50. ->build();
  51. $version = $this->versionDeterminer->execute($config->getTaxAreaLookupWsdl());
  52. return $this->factory->getForClass($mapperInterface, $version);
  53. }
  54. }