Skip to content

Commit d7c3bc9

Browse files
author
Dale Sikkema
committed
MAGETWO-33609: pull request for stories in this sprint
- separate Store logic from Base router
1 parent a27ba27 commit d7c3bc9

File tree

6 files changed

+124
-64
lines changed

6 files changed

+124
-64
lines changed

app/code/Magento/Backend/App/Router.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ class Router extends \Magento\Framework\App\Router\Base
5353
* @param \Magento\Framework\App\ResponseFactory $responseFactory
5454
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
5555
* @param \Magento\Framework\UrlInterface $url
56-
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
5756
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
58-
* @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
5957
* @param string $routerId
6058
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
6159
* @param \Magento\Framework\App\Config\ScopeConfigInterface $coreConfig
6260
* @param \Magento\Backend\App\ConfigInterface $backendConfig
61+
* @param \Magento\Framework\App\Router\SecureUrlInterface $secureUrl
6362
*
6463
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6564
*/
@@ -70,13 +69,12 @@ public function __construct(
7069
\Magento\Framework\App\ResponseFactory $responseFactory,
7170
\Magento\Framework\App\Route\ConfigInterface $routeConfig,
7271
\Magento\Framework\UrlInterface $url,
73-
\Magento\Framework\Store\StoreManagerInterface $storeManager,
7472
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
75-
\Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo,
7673
$routerId,
7774
\Magento\Framework\Code\NameBuilder $nameBuilder,
7875
\Magento\Framework\App\Config\ScopeConfigInterface $coreConfig,
79-
\Magento\Backend\App\ConfigInterface $backendConfig
76+
\Magento\Backend\App\ConfigInterface $backendConfig,
77+
\Magento\Framework\App\Router\SecureUrlInterface $secureUrl
8078
) {
8179
parent::__construct(
8280
$actionList,
@@ -85,11 +83,10 @@ public function __construct(
8583
$responseFactory,
8684
$routeConfig,
8785
$url,
88-
$storeManager,
8986
$scopeConfig,
90-
$urlSecurityInfo,
9187
$routerId,
92-
$nameBuilder
88+
$nameBuilder,
89+
$secureUrl
9390
);
9491
$this->_coreConfig = $coreConfig;
9592
$this->_backendConfig = $backendConfig;

app/code/Magento/DesignEditor/Controller/Varien/Router/Standard.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ class Standard extends \Magento\Framework\App\Router\Base
4747
* @param \Magento\Framework\App\ResponseFactory $responseFactory
4848
* @param \Magento\Framework\App\Route\Config $routeConfig
4949
* @param \Magento\Framework\UrlInterface $url
50-
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
5150
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
52-
* @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
5351
* @param string $routerId
5452
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
53+
* @param \Magento\Framework\App\Router\SecureUrlInterface $secureUrl
5554
* @param \Magento\Framework\App\RouterListInterface $routerList
5655
* @param \Magento\DesignEditor\Helper\Data $designEditorHelper
5756
* @param \Magento\DesignEditor\Model\State $designEditorState
@@ -66,11 +65,10 @@ public function __construct(
6665
\Magento\Framework\App\ResponseFactory $responseFactory,
6766
\Magento\Framework\App\Route\Config $routeConfig,
6867
\Magento\Framework\UrlInterface $url,
69-
\Magento\Framework\Store\StoreManagerInterface $storeManager,
7068
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
71-
\Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo,
7269
$routerId,
7370
\Magento\Framework\Code\NameBuilder $nameBuilder,
71+
\Magento\Framework\App\Router\SecureUrlInterface $secureUrl,
7472
\Magento\Framework\App\RouterListInterface $routerList,
7573
\Magento\DesignEditor\Helper\Data $designEditorHelper,
7674
\Magento\DesignEditor\Model\State $designEditorState,
@@ -83,11 +81,10 @@ public function __construct(
8381
$responseFactory,
8482
$routeConfig,
8583
$url,
86-
$storeManager,
8784
$scopeConfig,
88-
$urlSecurityInfo,
8985
$routerId,
90-
$nameBuilder
86+
$nameBuilder,
87+
$secureUrl
9188
);
9289
$this->_routerList = $routerList;
9390
$this->_designEditorHelper = $designEditorHelper;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Store\Helper;
7+
8+
use Magento\Framework\Store\StoreManagerInterface;
9+
use Magento\Framework\Store\ScopeInterface;
10+
11+
class SecureUrl implements \Magento\Framework\App\Router\SecureUrlInterface
12+
{
13+
/** @var \Magento\Framework\App\Config\ScopeConfigInterface */
14+
private $scopeConfig;
15+
/** @var \Magento\Framework\Url\SecurityInfoInterface */
16+
private $urlSecurityInfo;
17+
/** @var StoreManagerInterface */
18+
private $storeManager;
19+
20+
/**
21+
* @param \Magento\Framework\App\ResponseFactory $responseFactory
22+
* @param \Magento\Framework\UrlInterface $url
23+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
24+
* @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
25+
* @param StoreManagerInterface $storeManager
26+
*/
27+
public function __construct(
28+
\Magento\Framework\App\ResponseFactory $responseFactory,
29+
\Magento\Framework\UrlInterface $url,
30+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
31+
\Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo,
32+
StoreManagerInterface $storeManager
33+
) {
34+
35+
$this->scopeConfig = $scopeConfig;
36+
$this->urlSecurityInfo = $urlSecurityInfo;
37+
$this->storeManager = $storeManager;
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*
43+
* @param \Magento\Framework\App\RequestInterface $request
44+
* @return string
45+
*/
46+
public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request)
47+
{
48+
$alias = $request->getAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS) || $request->getPathInfo();
49+
return $this->storeManager->getStore()->getBaseUrl('link', true) . ltrim($alias, '/');
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*
55+
* @param string $path
56+
* @return bool
57+
*/
58+
public function shouldBeSecure($path)
59+
{
60+
return parse_url(
61+
$this->scopeConfig->getValue(
62+
StoreManagerInterface::XML_PATH_UNSECURE_BASE_URL,
63+
ScopeInterface::SCOPE_STORE
64+
),
65+
PHP_URL_SCHEME
66+
) === 'https'
67+
|| $this->scopeConfig->isSetFlag(
68+
StoreManagerInterface::XML_PATH_SECURE_IN_FRONTEND,
69+
ScopeInterface::SCOPE_STORE
70+
) && parse_url(
71+
$this->scopeConfig->getValue(
72+
StoreManagerInterface::XML_PATH_SECURE_BASE_URL,
73+
ScopeInterface::SCOPE_STORE
74+
),
75+
PHP_URL_SCHEME
76+
) == 'https' && $this->urlSecurityInfo->isSecure($path);
77+
}
78+
}

app/code/Magento/Store/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<preference for="Magento\Framework\App\Config\Scope\ReaderPoolInterface" type="Magento\Store\Model\Config\Reader\ReaderPool"/>
5454
<preference for="Magento\Framework\App\ScopeResolverInterface" type="Magento\Store\Model\Resolver\Store" />
5555
<preference for="Magento\Framework\Stdlib\CookieManagerInterface" type="Magento\Framework\Stdlib\Cookie\PhpCookieManager" />
56+
<preference for="Magento\Framework\App\Router\SecureUrlInterface" type="Magento\Store\Helper\SecureUrl" />
5657
<type name="Magento\Framework\App\Action\Action">
5758
<plugin name="storeCheck" type="Magento\Store\App\Action\Plugin\StoreCheck" sortOrder="10"/>
5859
<plugin name="designLoader" type="Magento\Framework\App\Action\Plugin\Design" sortOrder="30"/>

lib/internal/Magento/Framework/App/Router/Base.php

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,21 @@ class Base implements \Magento\Framework\App\RouterInterface
110110
*/
111111
protected $actionList;
112112

113+
/** @var SecureUrlInterface */
114+
private $secureUrl;
115+
113116
/**
114117
* @param \Magento\Framework\App\Router\ActionList $actionList
115118
* @param \Magento\Framework\App\ActionFactory $actionFactory
116119
* @param \Magento\Framework\App\DefaultPathInterface $defaultPath
117120
* @param \Magento\Framework\App\ResponseFactory $responseFactory
118121
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
119122
* @param \Magento\Framework\UrlInterface $url
120-
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
121123
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
122-
* @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo
123124
* @param string $routerId
124125
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
126+
* @param \Magento\Framework\App\Router\SecureUrlInterface $secureUrl
127+
*
125128
* @throws \InvalidArgumentException
126129
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
127130
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -133,22 +136,20 @@ public function __construct(
133136
\Magento\Framework\App\ResponseFactory $responseFactory,
134137
\Magento\Framework\App\Route\ConfigInterface $routeConfig,
135138
\Magento\Framework\UrlInterface $url,
136-
\Magento\Framework\Store\StoreManagerInterface $storeManager,
137139
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
138-
\Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo,
139140
$routerId,
140-
\Magento\Framework\Code\NameBuilder $nameBuilder
141+
\Magento\Framework\Code\NameBuilder $nameBuilder,
142+
\Magento\Framework\App\Router\SecureUrlInterface $secureUrl
141143
) {
142144
$this->actionList = $actionList;
143145
$this->actionFactory = $actionFactory;
144146
$this->_responseFactory = $responseFactory;
145147
$this->_defaultPath = $defaultPath;
146148
$this->_routeConfig = $routeConfig;
147-
$this->_urlSecurityInfo = $urlSecurityInfo;
148149
$this->_scopeConfig = $scopeConfig;
149150
$this->_url = $url;
150-
$this->_storeManager = $storeManager;
151151
$this->nameBuilder = $nameBuilder;
152+
$this->secureUrl = $secureUrl;
152153
}
153154

154155
/**
@@ -363,8 +364,8 @@ protected function _checkShouldBeSecure(\Magento\Framework\App\RequestInterface
363364
return;
364365
}
365366

366-
if ($this->_shouldBeSecure($path) && !$request->isSecure()) {
367-
$url = $this->_getCurrentSecureUrl($request);
367+
if ($this->secureUrl->shouldBeSecure($path) && !$request->isSecure()) {
368+
$url = $this->secureUrl->getCurrentSecureUrl($request);
368369
if ($this->_shouldRedirectToSecure()) {
369370
$url = $this->_url->getRedirectUrl($url);
370371
}
@@ -383,44 +384,4 @@ protected function _shouldRedirectToSecure()
383384
{
384385
return $this->_url->getUseSession();
385386
}
386-
387-
/**
388-
* Retrieve secure url for current request
389-
*
390-
* @param \Magento\Framework\App\RequestInterface $request
391-
* @return string
392-
*/
393-
protected function _getCurrentSecureUrl($request)
394-
{
395-
$alias = $request->getAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS) || $request->getPathInfo();
396-
return $this->_storeManager->getStore()->getBaseUrl('link', true) . ltrim($alias, '/');
397-
}
398-
399-
/**
400-
* Check whether given path should be secure according to configuration security requirements for URL
401-
* "Secure" should not be confused with https protocol, it is about web/secure/*_url settings usage only
402-
*
403-
* @param string $path
404-
* @return bool
405-
*/
406-
protected function _shouldBeSecure($path)
407-
{
408-
return parse_url(
409-
$this->_scopeConfig->getValue(
410-
StoreManagerInterface::XML_PATH_UNSECURE_BASE_URL,
411-
ScopeInterface::SCOPE_STORE
412-
),
413-
PHP_URL_SCHEME
414-
) === 'https'
415-
|| $this->_scopeConfig->isSetFlag(
416-
StoreManagerInterface::XML_PATH_SECURE_IN_FRONTEND,
417-
ScopeInterface::SCOPE_STORE
418-
) && parse_url(
419-
$this->_scopeConfig->getValue(
420-
StoreManagerInterface::XML_PATH_SECURE_BASE_URL,
421-
ScopeInterface::SCOPE_STORE
422-
),
423-
PHP_URL_SCHEME
424-
) == 'https' && $this->_urlSecurityInfo->isSecure($path);
425-
}
426387
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\App\Router;
7+
8+
interface SecureUrlInterface
9+
{
10+
/**
11+
* Retrieve secure url for current request
12+
*
13+
* @param \Magento\Framework\App\RequestInterface $request
14+
* @return string
15+
*/
16+
public function getCurrentSecureUrl(\Magento\Framework\App\RequestInterface $request);
17+
18+
/**
19+
* Check whether given path should be secure according to configuration security requirements for URL
20+
* "Secure" should not be confused with https protocol, it is about web/secure/*_url settings usage only
21+
*
22+
* @param string $path
23+
* @return bool
24+
*/
25+
public function shouldBeSecure($path);
26+
}

0 commit comments

Comments
 (0)