Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
BaseUrlChecker Class Reference

Public Member Functions

 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
 
 execute ($uri, $request)
 
 isEnabled ()
 
 isFrontendSecure ()
 

Detailed Description

Verifies that the requested URL matches to base URL of store.

Definition at line 11 of file BaseUrlChecker.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig)
Parameters
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig

Definition at line 21 of file BaseUrlChecker.php.

23  {
24  $this->scopeConfig = $scopeConfig;
25  }

Member Function Documentation

◆ execute()

execute (   $uri,
  $request 
)

Performs verification.

Parameters
array$uri
\Magento\Framework\App\Request\Http$request
Returns
bool

Definition at line 34 of file BaseUrlChecker.php.

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  }

◆ isEnabled()

isEnabled ( )

Checks whether base URL verification is enabled or not.

Returns
bool

Definition at line 48 of file BaseUrlChecker.php.

49  {
50  return (bool) $this->scopeConfig->getValue(
51  'web/url/redirect_to_base',
53  );
54  }

◆ isFrontendSecure()

isFrontendSecure ( )

Checks whether frontend is completely secure or not.

Returns
bool

Definition at line 61 of file BaseUrlChecker.php.

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  }

The documentation for this class was generated from the following file: