Skip to content

Commit a748735

Browse files
committed
Merge branch 'ACP2E-1999' of https://github.com/magento-l3/magento2ce into PR-L3-2023-07-14
2 parents 584e001 + 15c74ab commit a748735

File tree

22 files changed

+2082
-151
lines changed

22 files changed

+2082
-151
lines changed

app/code/Magento/Config/App/Config/Source/RuntimeConfigSource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private function loadConfig()
100100
} else {
101101
$code = $this->scopeCodeResolver->resolve($item->getScope(), $item->getScopeId());
102102
$config[$item->getScope()][$code][$item->getPath()] = $item->getValue();
103+
$config[$item->getScope()][strtolower($code)][$item->getPath()] = $item->getValue();
103104
}
104105
}
105106

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
use Magento\Config\App\Config\Type\System;
1010
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1111
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
12-
use Magento\Framework\App\DeploymentConfig;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\Config\File\ConfigFilePool;
1516
use Magento\Framework\Console\Cli;
17+
use Magento\Framework\Exception\FileSystemException;
18+
use Magento\Framework\Exception\RuntimeException;
1619
use Symfony\Component\Console\Command\Command;
1720
use Symfony\Component\Console\Input\InputArgument;
1821
use Symfony\Component\Console\Input\InputInterface;
@@ -31,16 +34,18 @@ class ConfigSetCommand extends Command
3134
/**#@+
3235
* Constants for arguments and options.
3336
*/
34-
const ARG_PATH = 'path';
35-
const ARG_VALUE = 'value';
36-
const OPTION_SCOPE = 'scope';
37-
const OPTION_SCOPE_CODE = 'scope-code';
38-
const OPTION_LOCK = 'lock';
39-
const OPTION_LOCK_ENV = 'lock-env';
40-
const OPTION_LOCK_CONFIG = 'lock-config';
37+
public const ARG_PATH = 'path';
38+
public const ARG_VALUE = 'value';
39+
public const OPTION_SCOPE = 'scope';
40+
public const OPTION_SCOPE_CODE = 'scope-code';
41+
public const OPTION_LOCK = 'lock';
42+
public const OPTION_LOCK_ENV = 'lock-env';
43+
public const OPTION_LOCK_CONFIG = 'lock-config';
4144
/**#@-*/
4245

43-
/**#@-*/
46+
/**#@-
47+
* @var EmulatedAdminhtmlAreaProcessor
48+
*/
4449
private $emulatedAreaProcessor;
4550

4651
/**
@@ -64,22 +69,31 @@ class ConfigSetCommand extends Command
6469
*/
6570
private $deploymentConfig;
6671

72+
/**
73+
* @var LocaleEmulatorInterface
74+
*/
75+
private $localeEmulator;
76+
6777
/**
6878
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
6979
* @param ChangeDetector $changeDetector The config change detector
7080
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
7181
* @param DeploymentConfig $deploymentConfig Application deployment configuration
82+
* @param LocaleEmulatorInterface|null $localeEmulator
7283
*/
7384
public function __construct(
7485
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
7586
ChangeDetector $changeDetector,
7687
ProcessorFacadeFactory $processorFacadeFactory,
77-
DeploymentConfig $deploymentConfig
88+
DeploymentConfig $deploymentConfig,
89+
LocaleEmulatorInterface $localeEmulator = null
7890
) {
7991
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
8092
$this->changeDetector = $changeDetector;
8193
$this->processorFacadeFactory = $processorFacadeFactory;
8294
$this->deploymentConfig = $deploymentConfig;
95+
$this->localeEmulator = $localeEmulator ??
96+
ObjectManager::getInstance()->get(LocaleEmulatorInterface::class);
8397

8498
parent::__construct();
8599
}
@@ -141,8 +155,10 @@ protected function configure()
141155
*
142156
* @param InputInterface $input
143157
* @param OutputInterface $output
144-
* @since 101.0.0
145158
* @return int|null
159+
* @throws FileSystemException
160+
* @throws RuntimeException
161+
* @since 101.0.0
146162
*/
147163
protected function execute(InputInterface $input, OutputInterface $output)
148164
{
@@ -165,32 +181,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
165181

166182
try {
167183
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
168-
169-
$lock = $input->getOption(static::OPTION_LOCK_ENV)
170-
|| $input->getOption(static::OPTION_LOCK_CONFIG)
171-
|| $input->getOption(static::OPTION_LOCK);
172-
173-
$lockTargetPath = ConfigFilePool::APP_ENV;
174-
if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
175-
$lockTargetPath = ConfigFilePool::APP_CONFIG;
176-
}
177-
178-
return $this->processorFacadeFactory->create()->processWithLockTarget(
179-
$input->getArgument(static::ARG_PATH),
180-
$input->getArgument(static::ARG_VALUE),
181-
$input->getOption(static::OPTION_SCOPE),
182-
$input->getOption(static::OPTION_SCOPE_CODE),
183-
$lock,
184-
$lockTargetPath
185-
);
184+
return $this->localeEmulator->emulate(function () use ($input) {
185+
$lock = $input->getOption(static::OPTION_LOCK_ENV)
186+
|| $input->getOption(static::OPTION_LOCK_CONFIG)
187+
|| $input->getOption(static::OPTION_LOCK);
188+
189+
$lockTargetPath = ConfigFilePool::APP_ENV;
190+
if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
191+
$lockTargetPath = ConfigFilePool::APP_CONFIG;
192+
}
193+
194+
return $this->processorFacadeFactory->create()->processWithLockTarget(
195+
$input->getArgument(static::ARG_PATH),
196+
$input->getArgument(static::ARG_VALUE),
197+
$input->getOption(static::OPTION_SCOPE),
198+
$input->getOption(static::OPTION_SCOPE_CODE),
199+
$lock,
200+
$lockTargetPath
201+
);
202+
});
186203
});
187204

188205
$output->writeln('<info>' . $message . '</info>');
189206

190207
return Cli::RETURN_SUCCESS;
191208
} catch (\Exception $exception) {
192-
$output->writeln('<error>' . $exception->getMessage() . '</error>');
193-
209+
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
194210
return Cli::RETURN_FAILURE;
195211
}
196212
}

app/code/Magento/Config/Console/Command/ConfigShowCommand.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
namespace Magento\Config\Console\Command;
77

88
use Magento\Config\Console\Command\ConfigShow\ValueProcessor;
9+
use Magento\Config\Model\Config\PathValidatorFactory;
910
use Magento\Framework\App\Config\ConfigPathResolver;
1011
use Magento\Framework\App\Config\ConfigSourceInterface;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\App\Scope\ValidatorInterface;
1315
use Magento\Framework\Console\Cli;
1416
use Symfony\Component\Console\Command\Command;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Input\InputOption;
1820
use Symfony\Component\Console\Output\OutputInterface;
19-
use Magento\Framework\App\ObjectManager;
20-
use Magento\Config\Model\Config\PathValidatorFactory;
2121

2222
/**
2323
* Command provides possibility to show saved system configuration.
@@ -93,13 +93,19 @@ class ConfigShowCommand extends Command
9393
*/
9494
private $emulatedAreaProcessor;
9595

96+
/**
97+
* @var LocaleEmulatorInterface|mixed
98+
*/
99+
private mixed $localeEmulator;
100+
96101
/**
97102
* @param ValidatorInterface $scopeValidator
98103
* @param ConfigSourceInterface $configSource
99104
* @param ConfigPathResolver $pathResolver
100105
* @param ValueProcessor $valueProcessor
101106
* @param PathValidatorFactory|null $pathValidatorFactory
102107
* @param EmulatedAdminhtmlAreaProcessor|null $emulatedAreaProcessor
108+
* @param LocaleEmulatorInterface|null $localeEmulator
103109
* @internal param ScopeConfigInterface $appConfig
104110
*/
105111
public function __construct(
@@ -108,7 +114,8 @@ public function __construct(
108114
ConfigPathResolver $pathResolver,
109115
ValueProcessor $valueProcessor,
110116
?PathValidatorFactory $pathValidatorFactory = null,
111-
?EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor = null
117+
?EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor = null,
118+
?LocaleEmulatorInterface $localeEmulator = null
112119
) {
113120
parent::__construct();
114121
$this->scopeValidator = $scopeValidator;
@@ -119,6 +126,8 @@ public function __construct(
119126
?: ObjectManager::getInstance()->get(PathValidatorFactory::class);
120127
$this->emulatedAreaProcessor = $emulatedAreaProcessor
121128
?: ObjectManager::getInstance()->get(EmulatedAdminhtmlAreaProcessor::class);
129+
$this->localeEmulator = $localeEmulator
130+
?: ObjectManager::getInstance()->get(LocaleEmulatorInterface::class);
122131
}
123132

124133
/**
@@ -171,15 +180,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
171180
$this->inputPath = $inputPath !== null ? trim($inputPath, '/') : '';
172181

173182
$configValue = $this->emulatedAreaProcessor->process(function () {
174-
$this->scopeValidator->isValid($this->scope, $this->scopeCode);
175-
if ($this->inputPath) {
176-
$pathValidator = $this->pathValidatorFactory->create();
177-
$pathValidator->validate($this->inputPath);
178-
}
179-
180-
$configPath = $this->pathResolver->resolve($this->inputPath, $this->scope, $this->scopeCode);
181-
182-
return $this->configSource->get($configPath);
183+
return $this->localeEmulator->emulate(function () {
184+
$this->scopeValidator->isValid($this->scope, $this->scopeCode);
185+
if ($this->inputPath) {
186+
$pathValidator = $this->pathValidatorFactory->create();
187+
$pathValidator->validate($this->inputPath);
188+
}
189+
190+
$configPath = $this->pathResolver
191+
->resolve($this->inputPath, $this->scope, $this->scopeCode);
192+
$value = $this->configSource->get($configPath);
193+
if (!$value) {
194+
$configPath = $this->pathResolver
195+
->resolve($this->inputPath, $this->scope, strtolower($this->scopeCode));
196+
$value = $this->configSource->get($configPath);
197+
if (!$value) {
198+
$value = $this->configSource->get(strtolower($configPath));
199+
}
200+
}
201+
return $value;
202+
});
183203
});
184204

185205
$this->outputResult($output, $configValue, $this->inputPath);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Console\Command;
9+
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Framework\Phrase;
12+
use Magento\Framework\Phrase\RendererInterface;
13+
use Magento\Framework\TranslateInterface;
14+
15+
/**
16+
* Locale emulator for config set and show
17+
*/
18+
class LocaleEmulator implements LocaleEmulatorInterface
19+
{
20+
/**
21+
* @var bool
22+
*/
23+
private bool $isEmulating = false;
24+
25+
/**
26+
* @var TranslateInterface
27+
*/
28+
private TranslateInterface $translate;
29+
30+
/**
31+
* @var RendererInterface
32+
*/
33+
private RendererInterface $phraseRenderer;
34+
35+
/**
36+
* @var ResolverInterface
37+
*/
38+
private ResolverInterface $localeResolver;
39+
40+
/**
41+
* @var ResolverInterface
42+
*/
43+
private ResolverInterface $defaultLocaleResolver;
44+
45+
/**
46+
* @param TranslateInterface $translate
47+
* @param RendererInterface $phraseRenderer
48+
* @param ResolverInterface $localeResolver
49+
* @param ResolverInterface $defaultLocaleResolver
50+
*/
51+
public function __construct(
52+
TranslateInterface $translate,
53+
RendererInterface $phraseRenderer,
54+
ResolverInterface $localeResolver,
55+
ResolverInterface $defaultLocaleResolver,
56+
) {
57+
$this->translate = $translate;
58+
$this->phraseRenderer = $phraseRenderer;
59+
$this->localeResolver = $localeResolver;
60+
$this->defaultLocaleResolver = $defaultLocaleResolver;
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function emulate(callable $callback, ?string $locale = null): mixed
67+
{
68+
if ($this->isEmulating) {
69+
return $callback();
70+
}
71+
$this->isEmulating = true;
72+
$locale ??= $this->defaultLocaleResolver->getLocale();
73+
$initialLocale = $this->localeResolver->getLocale();
74+
$initialPhraseRenderer = Phrase::getRenderer();
75+
Phrase::setRenderer($this->phraseRenderer);
76+
$this->localeResolver->setLocale($locale);
77+
$this->translate->setLocale($locale);
78+
$this->translate->loadData();
79+
try {
80+
return $callback();
81+
} finally {
82+
Phrase::setRenderer($initialPhraseRenderer);
83+
$this->localeResolver->setLocale($initialLocale);
84+
$this->translate->setLocale($initialLocale);
85+
$this->translate->loadData();
86+
$this->isEmulating = false;
87+
}
88+
}
89+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Config\Console\Command;
9+
10+
/**
11+
* Locale emulator for config set and show
12+
*/
13+
interface LocaleEmulatorInterface
14+
{
15+
/**
16+
* Emulates given $locale during execution of $callback
17+
*
18+
* @param callable $callback
19+
* @param string|null $locale
20+
* @return mixed
21+
*/
22+
public function emulate(callable $callback, ?string $locale = null): mixed;
23+
}

0 commit comments

Comments
 (0)