Skip to content

Commit 79f76c0

Browse files
committed
!!! Configured processors now need a key for identifcation
Instead of being an array, processors must now be defined as a map, so that every processor can be identified with a key. This allows easier overriding of already defined processors and makes the code for removing options with a processor much simpler. Closes #34
1 parent d05ca12 commit 79f76c0

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ There are some prerequisites to follow if you want to use this feature:
127127

128128
```yaml
129129
processors:
130-
- class: Helhum\TYPO3\ConfigHandling\Processor\DecryptSettingsProcessor
130+
decrypt:
131+
class: Helhum\TYPO3\ConfigHandling\Processor\DecryptSettingsProcessor
131132
```
132133

133134
As you can see, the decryption is solely based on a processor, which handles the

src/Xclass/ConfigurationManager.php

+11-29
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function updateLocalConfiguration(array $configurationToMerge): void
269269
1346323822
270270
);
271271
}
272-
$removedPaths = $this->findRemovedPaths();
272+
$removedPaths = $this->getRemovedPaths();
273273
foreach ($removedPaths as $removedPath) {
274274
try {
275275
Config::getValue($configurationToMerge, $removedPath);
@@ -292,44 +292,26 @@ public function updateLocalConfiguration(array $configurationToMerge): void
292292
}
293293
}
294294

295-
private function findRemovedPaths(): array
296-
{
297-
$overrides = $this->configLoader->loadOverrides();
298-
$removedPaths = [];
299-
if (isset($overrides['processors'])) {
300-
foreach ($overrides['processors'] as $index => $processorConfig) {
301-
if (($processorConfig['internal'] ?? false) && $processorConfig['class'] === RemoveSettingsProcessor::class) {
302-
$removedPaths = $processorConfig['paths'];
303-
break;
304-
}
305-
}
306-
}
295+
private const REMOVE_PROCESSOR_KEY = '_stale_options';
307296

308-
return $removedPaths;
297+
private function getRemovedPaths(): array
298+
{
299+
return $this->configLoader->loadOverrides()['processors'][self::REMOVE_PROCESSOR_KEY]['paths'] ?? [];
309300
}
310301

311302
private function updateRemovalPaths(array $pathsToRemove): void
312303
{
313304
$overrideSettingsFile = SettingsFiles::getOverrideSettingsFile();
314305
$overrides = $this->configLoader->loadOverrides();
315-
$processorPosition = 0;
316-
if (isset($overrides['processors'])) {
317-
foreach ($overrides['processors'] as $index => $processorConfig) {
318-
if (($processorConfig['internal'] ?? false) && $processorConfig['class'] === RemoveSettingsProcessor::class) {
319-
$processorPosition = $index;
320-
break;
321-
}
322-
}
323-
}
306+
$overrides['processors'][self::REMOVE_PROCESSOR_KEY] = [
307+
'class' => RemoveSettingsProcessor::class,
308+
'paths' => $pathsToRemove,
309+
];
324310
if (empty($pathsToRemove)) {
325-
unset($overrides['processors'][$processorPosition]);
311+
unset($overrides['processors'][self::REMOVE_PROCESSOR_KEY]);
326312
if (empty($overrides['processors'])) {
327313
unset($overrides['processors']);
328314
}
329-
} else {
330-
$overrides['processors'][$processorPosition]['class'] = RemoveSettingsProcessor::class;
331-
$overrides['processors'][$processorPosition]['paths'] = $pathsToRemove;
332-
$overrides['processors'][$processorPosition]['internal'] = true;
333315
}
334316
$this->configDumper->dumpToFile($overrides, $overrideSettingsFile);
335317
}
@@ -422,7 +404,7 @@ public function removeLocalConfigurationKeysByPath(array $keys): bool
422404
}
423405
}
424406
if (!empty($removedPaths)) {
425-
$alreadyRemovedPaths = $this->findRemovedPaths();
407+
$alreadyRemovedPaths = $this->getRemovedPaths();
426408
$removedPaths = array_unique(array_merge($alreadyRemovedPaths, $removedPaths));
427409
$this->updateRemovalPaths($removedPaths);
428410
}

0 commit comments

Comments
 (0)