Skip to content

Commit 4ef070f

Browse files
committed
Merge remote-tracking branch 'origin/AC-3036-fix-deprecation-error-for-admin-url' into delivery-bunch-w20
2 parents 5da5995 + 688168d commit 4ef070f

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

app/code/Magento/Backend/App/Area/FrontNameResolver.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
<?php
22
/**
3-
* Backend area front name resolver. Reads front name from configuration
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
6+
87
namespace Magento\Backend\App\Area;
98

9+
use Laminas\Uri\Uri;
10+
use Magento\Backend\App\Config;
1011
use Magento\Backend\Setup\ConfigOptionsList;
12+
use Magento\Framework\App\Area\FrontNameResolverInterface;
1113
use Magento\Framework\App\Config\ScopeConfigInterface;
1214
use Magento\Framework\App\DeploymentConfig;
1315
use Magento\Framework\App\ObjectManager;
1416
use Magento\Framework\App\RequestInterface;
1517
use Magento\Store\Model\ScopeInterface;
1618
use Magento\Store\Model\Store;
17-
use Laminas\Uri\Uri;
1819

1920
/**
20-
* Class to get area front name.
21+
* Front name resolver for backend area.
2122
*
2223
* @api
2324
* @since 100.0.2
2425
*/
25-
class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface
26+
class FrontNameResolver implements FrontNameResolverInterface
2627
{
27-
const XML_PATH_USE_CUSTOM_ADMIN_PATH = 'admin/url/use_custom_path';
28+
public const XML_PATH_USE_CUSTOM_ADMIN_PATH = 'admin/url/use_custom_path';
2829

29-
const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path';
30+
public const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path';
3031

31-
const XML_PATH_USE_CUSTOM_ADMIN_URL = 'admin/url/use_custom';
32+
public const XML_PATH_USE_CUSTOM_ADMIN_URL = 'admin/url/use_custom';
3233

33-
const XML_PATH_CUSTOM_ADMIN_URL = 'admin/url/custom';
34+
public const XML_PATH_CUSTOM_ADMIN_URL = 'admin/url/custom';
3435

3536
/**
3637
* Backend area code
3738
*/
38-
const AREA_CODE = 'adminhtml';
39+
public const AREA_CODE = 'adminhtml';
3940

4041
/**
4142
* @var array
@@ -75,14 +76,14 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
7576
private $request;
7677

7778
/**
78-
* @param \Magento\Backend\App\Config $config
79+
* @param Config $config
7980
* @param DeploymentConfig $deploymentConfig
8081
* @param ScopeConfigInterface $scopeConfig
8182
* @param Uri $uri
8283
* @param RequestInterface $request
8384
*/
8485
public function __construct(
85-
\Magento\Backend\App\Config $config,
86+
Config $config,
8687
DeploymentConfig $deploymentConfig,
8788
ScopeConfigInterface $scopeConfig,
8889
Uri $uri = null,
@@ -131,8 +132,10 @@ public function isHostBackend()
131132
);
132133
}
133134
}
134-
$host = $this->request->getServer('HTTP_HOST', '');
135-
return stripos($this->getHostWithPort($backendUrl), (string) $host) !== false;
135+
$host = (string) $this->request->getServer('HTTP_HOST', '');
136+
$hostWithPort = $this->getHostWithPort($backendUrl);
137+
138+
return !($hostWithPort === null || $host === '') && stripos($hostWithPort, $host) !== false;
136139
}
137140

138141
/**
@@ -149,8 +152,8 @@ private function getHostWithPort($url)
149152
$port = $this->uri->getPort();
150153

151154
if (!$port) {
152-
$port = isset($this->standardPorts[$scheme]) ? $this->standardPorts[$scheme] : null;
155+
$port = $this->standardPorts[$scheme] ?? null;
153156
}
154-
return isset($port) ? $host . ':' . $port : $host;
157+
return $port !== null ? $host . ':' . $port : $host;
155158
}
156159
}

app/code/Magento/Backend/Test/Unit/App/Area/FrontNameResolverTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testIfCustomPathNotUsed(): void
108108

109109
/**
110110
* @param string $url
111-
* @param string $host
111+
* @param string|null $host
112112
* @param string $useCustomAdminUrl
113113
* @param string $customAdminUrl
114114
* @param bool $expectedValue
@@ -118,7 +118,7 @@ public function testIfCustomPathNotUsed(): void
118118
*/
119119
public function testIsHostBackend(
120120
string $url,
121-
string $host,
121+
?string $host,
122122
string $useCustomAdminUrl,
123123
string $customAdminUrl,
124124
bool $expectedValue
@@ -180,6 +180,23 @@ function () use (&$urlParts) {
180180
$this->assertEquals($this->model->isHostBackend(), $expectedValue);
181181
}
182182

183+
/**
184+
* Test the case when backend url is not set.
185+
*
186+
* @return void
187+
*/
188+
public function testIsHostBackendWithEmptyHost(): void
189+
{
190+
$this->request->expects($this->any())
191+
->method('getServer')
192+
->willReturn('magento2.loc');
193+
$this->uri->expects($this->once())
194+
->method('getHost')
195+
->willReturn(null);
196+
197+
$this->assertEquals($this->model->isHostBackend(), false);
198+
}
199+
183200
/**
184201
* @return array
185202
*/
@@ -241,6 +258,13 @@ public function hostsDataProvider(): array
241258
'useCustomAdminUrl' => '1',
242259
'customAdminUrl' => 'https://myhost.loc/',
243260
'expectedValue' => false
261+
],
262+
'withEmptyHost' => [
263+
'url' => 'http://magento2.loc/',
264+
'host' => null,
265+
'useCustomAdminUrl' => '0',
266+
'customAdminUrl' => '',
267+
'expectedValue' => false
244268
]
245269
];
246270
}

0 commit comments

Comments
 (0)