UrlBuilder.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ReleaseNotification\Model\ContentProvider\Http;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. /**
  9. * Builder to build Url to retrieve the notification content.
  10. */
  11. class UrlBuilder
  12. {
  13. /**
  14. * Path to the configuration value which contains an URL that provides the release notification data.
  15. *
  16. * @var string
  17. */
  18. private static $notificationContentUrlConfigPath = 'system/release_notification/content_url';
  19. /**
  20. * Path to the configuration value indicates if use https in notification content request.
  21. *
  22. * @var string
  23. */
  24. private static $useHttpsFlagConfigPath = 'system/release_notification/use_https';
  25. /**
  26. * @var ScopeConfigInterface
  27. */
  28. private $config;
  29. /**
  30. * @param ScopeConfigInterface $config
  31. */
  32. public function __construct(ScopeConfigInterface $config)
  33. {
  34. $this->config = $config;
  35. }
  36. /**
  37. * Builds the URL to request the release notification content data based on passed parameters.
  38. *
  39. * @param string $version
  40. * @param string $edition
  41. * @param string $locale
  42. * @return string
  43. */
  44. public function getUrl($version, $edition, $locale)
  45. {
  46. $scheme = $this->config->isSetFlag(self::$useHttpsFlagConfigPath) ? 'https://' : 'http://';
  47. $baseUrl = $this->config->getValue(self::$notificationContentUrlConfigPath);
  48. if (empty($baseUrl)) {
  49. return '';
  50. } else {
  51. $url = $scheme . $baseUrl;
  52. $url .= empty($version) ? '' : '/' . $version;
  53. $url .= empty($edition) ? '' : '/' . $edition;
  54. $url .= empty($locale) ? '' : '/' . $locale;
  55. return $url . '.json';
  56. }
  57. }
  58. }