GetApiKey.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\GoogleMap;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\Exception\LocalizedException;
  10. /**
  11. * Get Google API KEY
  12. */
  13. class GetApiKey
  14. {
  15. private const XML_PATH_API_KEY = 'cataloginventory/source_selection_distance_based_google/api_key';
  16. /**
  17. * @var ScopeConfigInterface
  18. */
  19. private $scopeConfig;
  20. /**
  21. * GetApiKey constructor.
  22. *
  23. * @param ScopeConfigInterface $scopeConfig
  24. */
  25. public function __construct(
  26. ScopeConfigInterface $scopeConfig
  27. ) {
  28. $this->scopeConfig = $scopeConfig;
  29. }
  30. /**
  31. * Get distance between two points
  32. *
  33. * @return string
  34. * @throws LocalizedException
  35. */
  36. public function execute(): string
  37. {
  38. $apiKey = trim((string) $this->scopeConfig->getValue(self::XML_PATH_API_KEY));
  39. if (!$apiKey) {
  40. throw new LocalizedException(__('Google API key is not defined'));
  41. }
  42. return $apiKey;
  43. }
  44. }