Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BaseUrlChecker.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Store\Model;
7 
12 {
16  private $scopeConfig;
17 
21  public function __construct(
22  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
23  ) {
24  $this->scopeConfig = $scopeConfig;
25  }
26 
34  public function execute($uri, $request)
35  {
36  $requestUri = $request->getRequestUri() ? $request->getRequestUri() : '/';
37  $isValidSchema = !isset($uri['scheme']) || $uri['scheme'] === $request->getScheme();
38  $isValidHost = !isset($uri['host']) || $uri['host'] === $request->getHttpHost();
39  $isValidPath = !isset($uri['path']) || strpos($requestUri, $uri['path']) !== false;
40  return $isValidSchema && $isValidHost && $isValidPath;
41  }
42 
48  public function isEnabled()
49  {
50  return (bool) $this->scopeConfig->getValue(
51  'web/url/redirect_to_base',
53  );
54  }
55 
61  public function isFrontendSecure()
62  {
63  $baseUrl = $this->scopeConfig->getValue(
64  'web/unsecure/base_url',
66  );
67  $baseUrlParts = explode('://', $baseUrl);
68  $baseUrlProtocol = array_shift($baseUrlParts);
69  $isSecure = (bool) $this->scopeConfig->getValue(
70  'web/secure/use_in_frontend',
72  );
73 
74  return $isSecure && $baseUrlProtocol == 'https';
75  }
76 }
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)