Skip to content

Commit fcb5dda

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 5e5f183 + 56eae2a commit fcb5dda

File tree

1 file changed

+64
-46
lines changed

1 file changed

+64
-46
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,46 @@
55
*/
66
namespace Magento\Config\App\Config\Type;
77

8+
use Magento\Framework\App\Config\ConfigSourceInterface;
89
use Magento\Framework\App\Config\ConfigTypeInterface;
10+
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
11+
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
912
use Magento\Framework\App\ObjectManager;
1013
use Magento\Config\App\Config\Type\System\Reader;
14+
use Magento\Framework\App\ScopeInterface;
15+
use Magento\Framework\Cache\FrontendInterface;
16+
use Magento\Framework\Serialize\SerializerInterface;
17+
use Magento\Store\Model\Config\Processor\Fallback;
18+
use Magento\Store\Model\ScopeInterface as StoreScope;
1119

1220
/**
1321
* System configuration type
22+
*
1423
* @api
1524
* @since 100.1.2
1625
*/
1726
class System implements ConfigTypeInterface
1827
{
1928
const CACHE_TAG = 'config_scopes';
20-
2129
const CONFIG_TYPE = 'system';
2230

23-
/**
24-
* @var \Magento\Framework\App\Config\ConfigSourceInterface
25-
*/
26-
private $source;
27-
2831
/**
2932
* @var array
3033
*/
3134
private $data = [];
3235

3336
/**
34-
* @var \Magento\Framework\App\Config\Spi\PostProcessorInterface
37+
* @var PostProcessorInterface
3538
*/
3639
private $postProcessor;
3740

3841
/**
39-
* @var \Magento\Framework\App\Config\Spi\PreProcessorInterface
40-
*/
41-
private $preProcessor;
42-
43-
/**
44-
* @var \Magento\Framework\Cache\FrontendInterface
42+
* @var FrontendInterface
4543
*/
4644
private $cache;
4745

4846
/**
49-
* @var int
50-
*/
51-
private $cachingNestedLevel;
52-
53-
/**
54-
* @var \Magento\Store\Model\Config\Processor\Fallback
55-
*/
56-
private $fallback;
57-
58-
/**
59-
* @var \Magento\Framework\Serialize\SerializerInterface
47+
* @var SerializerInterface
6048
*/
6149
private $serializer;
6250

@@ -79,36 +67,34 @@ class System implements ConfigTypeInterface
7967
*
8068
* @var array
8169
*/
82-
private $availableDataScopes = null;
70+
private $availableDataScopes;
8371

8472
/**
85-
* @param \Magento\Framework\App\Config\ConfigSourceInterface $source
86-
* @param \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor
87-
* @param \Magento\Store\Model\Config\Processor\Fallback $fallback
88-
* @param \Magento\Framework\Cache\FrontendInterface $cache
89-
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
90-
* @param \Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor
73+
* @param ConfigSourceInterface $source
74+
* @param PostProcessorInterface $postProcessor
75+
* @param Fallback $fallback
76+
* @param FrontendInterface $cache
77+
* @param SerializerInterface $serializer
78+
* @param PreProcessorInterface $preProcessor
9179
* @param int $cachingNestedLevel
9280
* @param string $configType
9381
* @param Reader $reader
82+
*
83+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
9484
*/
9585
public function __construct(
96-
\Magento\Framework\App\Config\ConfigSourceInterface $source,
97-
\Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor,
98-
\Magento\Store\Model\Config\Processor\Fallback $fallback,
99-
\Magento\Framework\Cache\FrontendInterface $cache,
100-
\Magento\Framework\Serialize\SerializerInterface $serializer,
101-
\Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor,
86+
ConfigSourceInterface $source,
87+
PostProcessorInterface $postProcessor,
88+
Fallback $fallback,
89+
FrontendInterface $cache,
90+
SerializerInterface $serializer,
91+
PreProcessorInterface $preProcessor,
10292
$cachingNestedLevel = 1,
10393
$configType = self::CONFIG_TYPE,
10494
Reader $reader = null
10595
) {
106-
$this->source = $source;
10796
$this->postProcessor = $postProcessor;
108-
$this->preProcessor = $preProcessor;
10997
$this->cache = $cache;
110-
$this->cachingNestedLevel = $cachingNestedLevel;
111-
$this->fallback = $fallback;
11298
$this->serializer = $serializer;
11399
$this->configType = $configType;
114100
$this->reader = $reader ?: ObjectManager::getInstance()->get(Reader::class);
@@ -136,27 +122,52 @@ public function get($path = '')
136122
{
137123
if ($path === '') {
138124
$this->data = array_replace_recursive($this->loadAllData(), $this->data);
125+
139126
return $this->data;
140127
}
128+
129+
return $this->getWithParts($path);
130+
}
131+
132+
/**
133+
* Proceed with parts extraction from path.
134+
*
135+
* @param string $path
136+
* @return array|int|string|boolean
137+
*/
138+
private function getWithParts($path)
139+
{
141140
$pathParts = explode('/', $path);
142-
if (count($pathParts) === 1 && $pathParts[0] !== 'default') {
141+
142+
if (count($pathParts) === 1 && $pathParts[0] !== ScopeInterface::SCOPE_DEFAULT) {
143143
if (!isset($this->data[$pathParts[0]])) {
144144
$data = $this->readData();
145145
$this->data = array_replace_recursive($data, $this->data);
146146
}
147+
147148
return $this->data[$pathParts[0]];
148149
}
150+
149151
$scopeType = array_shift($pathParts);
150-
if ($scopeType === 'default') {
152+
153+
if ($scopeType === ScopeInterface::SCOPE_DEFAULT) {
151154
if (!isset($this->data[$scopeType])) {
152155
$this->data = array_replace_recursive($this->loadDefaultScopeData($scopeType), $this->data);
153156
}
157+
154158
return $this->getDataByPathParts($this->data[$scopeType], $pathParts);
155159
}
160+
156161
$scopeId = array_shift($pathParts);
162+
157163
if (!isset($this->data[$scopeType][$scopeId])) {
158-
$this->data = array_replace_recursive($this->loadScopeData($scopeType, $scopeId), $this->data);
164+
$scopeData = $this->loadScopeData($scopeType, $scopeId);
165+
166+
if (!isset($this->data[$scopeType][$scopeId])) {
167+
$this->data = array_replace_recursive($scopeData, $this->data);
168+
}
159169
}
170+
160171
return isset($this->data[$scopeType][$scopeId])
161172
? $this->getDataByPathParts($this->data[$scopeType][$scopeId], $pathParts)
162173
: null;
@@ -170,11 +181,13 @@ public function get($path = '')
170181
private function loadAllData()
171182
{
172183
$cachedData = $this->cache->load($this->configType);
184+
173185
if ($cachedData === false) {
174186
$data = $this->readData();
175187
} else {
176188
$data = $this->serializer->unserialize($cachedData);
177189
}
190+
178191
return $data;
179192
}
180193

@@ -187,12 +200,14 @@ private function loadAllData()
187200
private function loadDefaultScopeData($scopeType)
188201
{
189202
$cachedData = $this->cache->load($this->configType . '_' . $scopeType);
203+
190204
if ($cachedData === false) {
191205
$data = $this->readData();
192206
$this->cacheData($data);
193207
} else {
194208
$data = [$scopeType => $this->serializer->unserialize($cachedData)];
195209
}
210+
196211
return $data;
197212
}
198213

@@ -206,6 +221,7 @@ private function loadDefaultScopeData($scopeType)
206221
private function loadScopeData($scopeType, $scopeId)
207222
{
208223
$cachedData = $this->cache->load($this->configType . '_' . $scopeType . '_' . $scopeId);
224+
209225
if ($cachedData === false) {
210226
if ($this->availableDataScopes === null) {
211227
$cachedScopeData = $this->cache->load($this->configType . '_scopes');
@@ -221,6 +237,7 @@ private function loadScopeData($scopeType, $scopeId)
221237
} else {
222238
$data = [$scopeType => [$scopeId => $this->serializer->unserialize($cachedData)]];
223239
}
240+
224241
return $data;
225242
}
226243

@@ -244,7 +261,7 @@ private function cacheData(array $data)
244261
[self::CACHE_TAG]
245262
);
246263
$scopes = [];
247-
foreach (['websites', 'stores'] as $curScopeType) {
264+
foreach ([StoreScope::SCOPE_WEBSITES, StoreScope::SCOPE_STORES] as $curScopeType) {
248265
foreach ($data[$curScopeType] ?? [] as $curScopeId => $curScopeData) {
249266
$scopes[$curScopeType][$curScopeId] = 1;
250267
$this->cache->save(
@@ -256,7 +273,7 @@ private function cacheData(array $data)
256273
}
257274
$this->cache->save(
258275
$this->serializer->serialize($scopes),
259-
$this->configType . "_scopes",
276+
$this->configType . '_scopes',
260277
[self::CACHE_TAG]
261278
);
262279
}
@@ -279,6 +296,7 @@ private function getDataByPathParts($data, $pathParts)
279296
return null;
280297
}
281298
}
299+
282300
return $data;
283301
}
284302

0 commit comments

Comments
 (0)