-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathAreaList.php
102 lines (85 loc) · 2.8 KB
/
AreaList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\UpwardConnector\Plugin\Magento\Framework\App;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Request\Http as Request;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\ScopeInterface;
use Magento\UpwardConnector\Api\UpwardPathManagerInterface;
class AreaList
{
public const UPWARD_HEADER = 'UpwardProxied';
public const UPWARD_ENV_HEADER = 'UPWARD_PHP_PROXY_HEADER';
/**
* @var \Magento\Framework\App\Request\Http
*/
private $request;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var \Magento\UpwardConnector\Api\UpwardPathManagerInterface
*/
private $pathManager;
/**
* Controller or frontname to load from default magento frontend
*/
const UPWARD_CONFIG_PATH_FRONT_NAMES_TO_SKIP = 'web/upward/front_names_to_skip';
/**
* @param Request $httpRequest
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\UpwardConnector\Api\UpwardPathManagerInterface|null $pathManager
*/
public function __construct(
Request $httpRequest,
ScopeConfigInterface $scopeConfig,
?UpwardPathManagerInterface $pathManager = null
) {
$this->request = $httpRequest;
$this->scopeConfig = $scopeConfig;
$this->pathManager = $pathManager ?: ObjectManager::getInstance()->get(UpwardPathManagerInterface::class);
}
/**
* Add pwa area code by front name
*
* @param \Magento\Framework\App\AreaList $subject
* @param string|null $result
* @param string $frontName
*
* @return string|null
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetCodeByFrontName(
\Magento\Framework\App\AreaList $subject,
$result,
$frontName
) {
if ($result !== 'frontend') {
return $result;
}
if (!$this->pathManager->getPath()) {
return $result;
}
$frontNamesToSkip = explode(
"\r\n",
$this->scopeConfig->getValue(
self::UPWARD_CONFIG_PATH_FRONT_NAMES_TO_SKIP,
ScopeInterface::SCOPE_STORE
) ?? ''
);
$upwardProxyEnv = getenv(self::UPWARD_ENV_HEADER);
/** $upwardProxyEnv needs to be truthy because getenv returns "false" if it didn't find it */
if ($upwardProxyEnv && $this->request->getHeader(self::UPWARD_HEADER) === $upwardProxyEnv) {
return $result;
}
if ($frontName && in_array($frontName, $frontNamesToSkip)) {
return $result;
}
return 'pwa';
}
}