PathConfig.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /***
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Model;
  7. class PathConfig implements \Magento\Framework\App\Router\PathConfigInterface
  8. {
  9. /**
  10. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  11. */
  12. private $scopeConfig;
  13. /**
  14. * @var \Magento\Framework\Url\SecurityInfoInterface
  15. */
  16. private $urlSecurityInfo;
  17. /**
  18. * @var \Magento\Store\Model\StoreManagerInterface
  19. */
  20. private $storeManager;
  21. /**
  22. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  23. * @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
  24. * @param StoreManagerInterface $storeManager
  25. */
  26. public function __construct(
  27. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  28. \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo,
  29. StoreManagerInterface $storeManager
  30. ) {
  31. $this->scopeConfig = $scopeConfig;
  32. $this->urlSecurityInfo = $urlSecurityInfo;
  33. $this->storeManager = $storeManager;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. *
  38. * @param \Magento\Framework\App\RequestInterface $request
  39. * @return string
  40. */
  41. public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request)
  42. {
  43. $alias = $request->getAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS) ?: $request->getPathInfo();
  44. return $this->storeManager->getStore()->getBaseUrl('link', true) . ltrim($alias, '/');
  45. }
  46. /**
  47. * {@inheritdoc}
  48. *
  49. * @param string $path
  50. * @return bool
  51. */
  52. public function shouldBeSecure($path)
  53. {
  54. return parse_url(
  55. $this->scopeConfig->getValue(
  56. Store::XML_PATH_UNSECURE_BASE_URL,
  57. ScopeInterface::SCOPE_STORE
  58. ),
  59. PHP_URL_SCHEME
  60. ) === 'https'
  61. || $this->scopeConfig->isSetFlag(
  62. Store::XML_PATH_SECURE_IN_FRONTEND,
  63. ScopeInterface::SCOPE_STORE
  64. ) && parse_url(
  65. $this->scopeConfig->getValue(
  66. Store::XML_PATH_SECURE_BASE_URL,
  67. ScopeInterface::SCOPE_STORE
  68. ),
  69. PHP_URL_SCHEME
  70. ) == 'https' && $this->urlSecurityInfo->isSecure($path);
  71. }
  72. /**
  73. * {@inheritdoc}
  74. *
  75. * @return string
  76. */
  77. public function getDefaultPath()
  78. {
  79. $store = $this->storeManager->getStore();
  80. $value = $this->scopeConfig->getValue('web/default/front', ScopeInterface::SCOPE_STORE, $store);
  81. return $value;
  82. }
  83. }