AdminPathConfig.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Model;
  7. use Magento\Framework\App\Router\PathConfigInterface;
  8. use Magento\Store\Model\Store;
  9. /**
  10. * Path config to be used in adminhtml area
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class AdminPathConfig implements PathConfigInterface
  15. {
  16. /**
  17. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  18. */
  19. protected $coreConfig;
  20. /**
  21. * @var \Magento\Backend\App\ConfigInterface
  22. */
  23. protected $backendConfig;
  24. /**
  25. * @var \Magento\Framework\UrlInterface
  26. */
  27. protected $url;
  28. /**
  29. * Constructor
  30. *
  31. * @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
  32. * @param \Magento\Backend\App\ConfigInterface $backendConfig
  33. * @param \Magento\Framework\UrlInterface $url
  34. */
  35. public function __construct(
  36. \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
  37. \Magento\Backend\App\ConfigInterface $backendConfig,
  38. \Magento\Framework\UrlInterface $url
  39. ) {
  40. $this->coreConfig = $coreConfig;
  41. $this->backendConfig = $backendConfig;
  42. $this->url = $url;
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request)
  48. {
  49. return $this->url->getBaseUrl('link', true) . ltrim($request->getPathInfo(), '/');
  50. }
  51. /**
  52. * @inheritdoc
  53. */
  54. public function shouldBeSecure($path)
  55. {
  56. $baseUrl = (string)$this->coreConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
  57. if (parse_url($baseUrl, PHP_URL_SCHEME) === 'https') {
  58. return true;
  59. }
  60. if ($this->backendConfig->isSetFlag(Store::XML_PATH_SECURE_IN_ADMINHTML)) {
  61. if ($this->backendConfig->isSetFlag('admin/url/use_custom')) {
  62. $adminBaseUrl = (string)$this->coreConfig->getValue('admin/url/custom', 'default');
  63. } else {
  64. $adminBaseUrl = (string)$this->coreConfig->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default');
  65. }
  66. return parse_url($adminBaseUrl, PHP_URL_SCHEME) === 'https';
  67. }
  68. return false;
  69. }
  70. /**
  71. * @inheritdoc
  72. */
  73. public function getDefaultPath()
  74. {
  75. return $this->backendConfig->getValue('web/default/admin');
  76. }
  77. }