GetDistanceFromSourceToAddress.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryDistanceBasedSourceSelection\Model\DistanceProvider;
  8. use Magento\InventoryApi\Api\Data\SourceInterface;
  9. use Magento\InventorySourceSelectionApi\Api\Data\AddressInterface;
  10. use Magento\InventoryDistanceBasedSourceSelectionApi\Api\GetDistanceInterface;
  11. use Magento\InventoryDistanceBasedSourceSelectionApi\Api\GetLatLngFromAddressInterface;
  12. /**
  13. * Class GetDistanceFromSourceToAddress
  14. */
  15. class GetDistanceFromSourceToAddress
  16. {
  17. /**
  18. * @var GetLatLngFromSource
  19. */
  20. private $getLatLngFromSource;
  21. /**
  22. * @var GetLatLngFromAddressInterface
  23. */
  24. private $getLatLngFromAddress;
  25. /**
  26. * @var GetDistanceInterface
  27. */
  28. private $getDistance;
  29. /**
  30. * GetDistanceFromSourceToAddress constructor.
  31. *
  32. * @param GetLatLngFromSource $getLatLngFromSource
  33. * @param GetLatLngFromAddressInterface $getLatLngFromAddress
  34. * @param GetDistanceInterface $getDistance
  35. */
  36. public function __construct(
  37. GetLatLngFromSource $getLatLngFromSource,
  38. GetLatLngFromAddressInterface $getLatLngFromAddress,
  39. GetDistanceInterface $getDistance
  40. ) {
  41. $this->getLatLngFromSource = $getLatLngFromSource;
  42. $this->getLatLngFromAddress = $getLatLngFromAddress;
  43. $this->getDistance = $getDistance;
  44. }
  45. /**
  46. * Get distance from source to address
  47. *
  48. * @param SourceInterface $source
  49. * @param AddressInterface $address
  50. * @return float
  51. */
  52. public function execute(SourceInterface $source, AddressInterface $address): float
  53. {
  54. return $this->getDistance->execute(
  55. $this->getLatLngFromSource->execute($source),
  56. $this->getLatLngFromAddress->execute($address)
  57. );
  58. }
  59. }