Skip to content

Commit e8abd6b

Browse files
committed
[BUGFIX] Correctly expose user only config
ConfigurationManager::getLocalConfiguration must return user config only, but until now returned full config cleaned from default values, which mostly is the same thing, but not in all cases. Therefore API is introduced to really only return user config values instead. Fixes: #26
1 parent 739010e commit e8abd6b

File tree

7 files changed

+106
-23
lines changed

7 files changed

+106
-23
lines changed

.github/workflows/Test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,9 @@ jobs:
9797
run: |
9898
rm -rf var/cache/*
9999
vendor/bin/typo3cms site:list | grep my-fancy-host
100+
101+
- name: BE Config Test
102+
if: ${{ matrix.typo3 != '^9.5.0' }}
103+
run: |
104+
rm -rf var/cache/*
105+
vendor/bin/typo3cms configuration:showlocal BE/explicitADmode --json | grep explicitAllow

.php_cs.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ return PhpCsFixer\Config::create()
8383
PhpCsFixer\Finder::create()
8484
->in(__DIR__)
8585
->exclude('vendor')
86-
->exclude('.Build')
86+
->exclude('public')
8787
);

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ finder:
6565
- "*.php"
6666
exclude:
6767
- "vendor"
68+
- "public"

src/ConfigLoader.php

+33
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use Helhum\ConfigLoader\CachedConfigurationLoader;
2626
use Helhum\ConfigLoader\ConfigurationLoader;
27+
use Helhum\ConfigLoader\InvalidConfigurationFileException;
2728
use Helhum\ConfigLoader\Processor\PlaceholderValue;
2829
use Helhum\TYPO3\ConfigHandling\Processor\ExtensionSettingsSerializer;
2930
use Helhum\Typo3Console\Mvc\Cli\Symfony\Input\ArgvInput;
@@ -87,16 +88,48 @@ private function shouldCache(): bool
8788
return $shouldCache && preg_match($lowLevelNamespaces, $input->getFirstArgument() ?? 'list') === 0;
8889
}
8990

91+
/**
92+
* Complete config
93+
* Cached in production
94+
*
95+
* @throws InvalidConfigurationFileException
96+
* @return array
97+
*/
9098
public function load(): array
9199
{
92100
return $this->buildLoader()->load();
93101
}
94102

103+
/**
104+
* Complete config, but without overrides config
105+
*
106+
* @return array
107+
*/
95108
public function loadBase(): array
96109
{
97110
return (new Typo3Config($this->settingsFile))->readBaseConfig();
98111
}
99112

113+
/**
114+
* Config with overrides file, but without TYPO3 defaults
115+
*
116+
* @return array
117+
*/
118+
public function loadOwn(): array
119+
{
120+
return (new Typo3Config($this->settingsFile))->readOwnConfig();
121+
}
122+
123+
/**
124+
* Config from overrides file
125+
*
126+
* @return array
127+
*/
128+
public function loadOverrides(): array
129+
{
130+
return (new Typo3Config($this->settingsFile))->readOverridesConfig();
131+
}
132+
100133
public function flushCache(): void
101134
{
102135
if (!$this->isProduction) {

src/Typo3Config.php

+55
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Helhum\ConfigLoader\ConfigurationReaderFactory;
2727
use Helhum\ConfigLoader\Reader\CollectionReader;
2828
use Helhum\ConfigLoader\Reader\ConfigReaderInterface;
29+
use Helhum\TYPO3\ConfigHandling\ConfigReader\ArrayReader;
2930
use Helhum\TYPO3\ConfigHandling\ConfigReader\CustomProcessingReader;
3031
use Helhum\TYPO3\ConfigHandling\ConfigReader\Typo3BaseConfigReader;
3132
use Helhum\TYPO3\ConfigHandling\ConfigReader\Typo3DefaultConfigPresenceReader;
@@ -42,6 +43,16 @@ class Typo3Config implements ConfigReaderInterface
4243
*/
4344
private $reader;
4445

46+
/**
47+
* @var ConfigReaderInterface
48+
*/
49+
private $ownConfigReader;
50+
51+
/**
52+
* @var ConfigReaderInterface
53+
*/
54+
private $overridesReader;
55+
4556
public function __construct(string $configFile, ConfigurationReaderFactory $readerFactory = null)
4657
{
4758
$readerFactory = $readerFactory ?? new ConfigurationReaderFactory(dirname($configFile));
@@ -61,23 +72,67 @@ function (string $resource) {
6172
$readerFactory->createRootReader(SettingsFiles::getOverrideSettingsFile())
6273
)
6374
);
75+
$readerFactory->setReaderFactoryForType(
76+
'typo3',
77+
function () {
78+
return new ArrayReader([]);
79+
},
80+
false
81+
);
82+
$this->ownConfigReader = new CustomProcessingReader(
83+
new CollectionReader(
84+
$readerFactory->createRootReader($configFile),
85+
$readerFactory->createRootReader(SettingsFiles::getOverrideSettingsFile())
86+
)
87+
);
88+
$this->overridesReader = $readerFactory->createReader(SettingsFiles::getOverrideSettingsFile());
6489
}
6590

6691
public function hasConfig(): bool
6792
{
6893
return $this->reader->hasConfig();
6994
}
7095

96+
/**
97+
* Complete config
98+
*
99+
* @return array
100+
*/
71101
public function readConfig(): array
72102
{
73103
return $this->reader->readConfig();
74104
}
75105

106+
/**
107+
* Complete config, but without overrides config
108+
*
109+
* @return array
110+
*/
76111
public function readBaseConfig(): array
77112
{
78113
return $this->baseReader->readConfig();
79114
}
80115

116+
/**
117+
* Config with overrides file, but without TYPO3 defaults
118+
*
119+
* @return array
120+
*/
121+
public function readOwnConfig(): array
122+
{
123+
return $this->ownConfigReader->readConfig();
124+
}
125+
126+
/**
127+
* Config of overrides file only
128+
*
129+
* @return array
130+
*/
131+
public function readOverridesConfig(): array
132+
{
133+
return $this->overridesReader->hasConfig() ? $this->overridesReader->readConfig() : [];
134+
}
135+
81136
public function getValue(string $path)
82137
{
83138
return Config::getValue($this->readConfig(), $path);

src/Xclass/ConfigurationManager.php

+10-21
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737

3838
use Composer\InstalledVersions;
3939
use Helhum\ConfigLoader\Config;
40-
use Helhum\ConfigLoader\ConfigurationReaderFactory;
4140
use Helhum\ConfigLoader\PathDoesNotExistException;
4241
use Helhum\TYPO3\ConfigHandling\ConfigCleaner;
4342
use Helhum\TYPO3\ConfigHandling\ConfigDumper;
44-
use Helhum\TYPO3\ConfigHandling\ConfigExtractor;
4543
use Helhum\TYPO3\ConfigHandling\ConfigLoader;
4644
use Helhum\TYPO3\ConfigHandling\Processor\RemoveSettingsProcessor;
4745
use Helhum\TYPO3\ConfigHandling\SettingsFiles;
@@ -72,11 +70,6 @@ class ConfigurationManager
7270
*/
7371
private $configLoader;
7472

75-
/**
76-
* @var ConfigExtractor
77-
*/
78-
private $configExtractor;
79-
8073
/**
8174
* @var ConfigDumper
8275
*/
@@ -144,13 +137,11 @@ class ConfigurationManager
144137

145138
public function __construct(
146139
ConfigLoader $configLoader = null,
147-
ConfigExtractor $configExtractor = null,
148140
ConfigDumper $configDumper = null,
149141
ConfigCleaner $configCleaner = null
150142
) {
151143
$this->configLoader = $configLoader ?: new ConfigLoader(Environment::getContext()->isProduction());
152144
$this->configDumper = $configDumper ?: new ConfigDumper();
153-
$this->configExtractor = $configExtractor ?: new ConfigExtractor($this->configDumper);
154145
$this->configCleaner = $configCleaner ?: new ConfigCleaner();
155146
}
156147

@@ -163,8 +154,6 @@ public function getDefaultConfiguration()
163154
{
164155
if (!$this->defaultConfig) {
165156
$this->defaultConfig = require $this->getDefaultConfigurationFileLocation();
166-
// TYPO3 core expects this value to be set in LocalConfiguration.php (see SilentConfigurationUpgradeService::configureBackendLoginSecurity)
167-
unset($this->defaultConfig['BE']['loginSecurityLevel']);
168157
}
169158

170159
return $this->defaultConfig;
@@ -201,7 +190,7 @@ public function getDefaultConfigurationDescriptionFileLocation()
201190
*/
202191
public function getLocalConfiguration()
203192
{
204-
return $this->configCleaner->cleanConfig($this->getMergedLocalConfiguration(), $this->getDefaultConfiguration());
193+
return $this->configLoader->loadOwn();
205194
}
206195

207196
/**
@@ -294,17 +283,18 @@ public function updateLocalConfiguration(array $configurationToMerge): void
294283
$remainingPaths = array_diff($removedPaths, $addedPaths);
295284
$this->updateRemovalPaths($remainingPaths);
296285
}
297-
298-
if ($this->configExtractor->extractConfig($configurationToMerge, $this->getMergedLocalConfiguration(), $overrideSettingsFile)) {
299-
$this->configLoader->flushCache();
286+
$remainingConfigToWrite = $this->configCleaner->cleanConfig(
287+
$configurationToMerge,
288+
$this->getLocalConfiguration()
289+
);
290+
if (!empty($remainingConfigToWrite)) {
291+
$this->configDumper->dumpToFile(array_replace_recursive($this->configLoader->loadOverrides(), $remainingConfigToWrite), $overrideSettingsFile);
300292
}
301293
}
302294

303295
private function findRemovedPaths(): array
304296
{
305-
$overrideSettingsFile = SettingsFiles::getOverrideSettingsFile();
306-
$factory = new ConfigurationReaderFactory();
307-
$overrides = file_exists($overrideSettingsFile) ? $factory->createReader($overrideSettingsFile)->readConfig() : [];
297+
$overrides = $this->configLoader->loadOverrides();
308298
$removedPaths = [];
309299
if (isset($overrides['processors'])) {
310300
foreach ($overrides['processors'] as $index => $processorConfig) {
@@ -321,8 +311,7 @@ private function findRemovedPaths(): array
321311
private function updateRemovalPaths(array $pathsToRemove): void
322312
{
323313
$overrideSettingsFile = SettingsFiles::getOverrideSettingsFile();
324-
$factory = new ConfigurationReaderFactory();
325-
$overrides = file_exists($overrideSettingsFile) ? $factory->createReader($overrideSettingsFile)->readConfig() : [];
314+
$overrides = $this->configLoader->loadOverrides();
326315
$processorPosition = 0;
327316
if (isset($overrides['processors'])) {
328317
foreach ($overrides['processors'] as $index => $processorConfig) {
@@ -497,7 +486,7 @@ public function exportConfiguration()
497486
*/
498487
public function writeLocalConfiguration(array $configuration)
499488
{
500-
$configuration = $this->configCleaner->cleanConfig($configuration, $this->getMergedLocalConfiguration());
489+
$configuration = $this->configCleaner->cleanConfig($configuration, $this->getLocalConfiguration());
501490
$this->updateLocalConfiguration($configuration);
502491

503492
// Too many places require this file to exist, so we make sure to create it

tests/Unit/ConfigLoaderTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* This copyright notice MUST APPEAR in all copies of the script!
2323
***************************************************************/
2424

25-
use Composer\InstalledVersions;
2625
use Helhum\TYPO3\ConfigHandling\ConfigLoader;
2726
use org\bovigo\vfs\vfsStream;
2827
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)