Skip to content

Commit 055756d

Browse files
authored
Fixing the compiler pass (#161)
1 parent 9bcb22f commit 055756d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/CompilerPass/AddingTypesToAdjustmentClearerPass.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ public function process(ContainerBuilder $container): void
1717

1818
// Getting the new list of adjustment types to clear
1919
$listOfAdjustmentsToClear = $clearerDefinition->getArgument(0);
20-
if (1 === preg_match('/^%(.*)%$/', $listOfAdjustmentsToClear, $matches)) {
21-
$listOfAdjustmentsToClear = $container->getParameter($matches[1]);
20+
21+
// If the argument is a string then it's the name of the parameter where the services are configured
22+
// We then just need to modify the parameter.
23+
if (is_string($listOfAdjustmentsToClear)) {
24+
$this->addClearerToContainerParameter($container, $listOfAdjustmentsToClear);
25+
26+
return;
2227
}
28+
29+
// BC: For Symfony < 6 (modifing the service directly)
2330
$listOfAdjustmentsToClear[] = CustomerOptionRecalculator::CUSTOMER_OPTION_ADJUSTMENT;
2431

2532
// Setting the new list as the new definition
2633
$clearerDefinition->setArgument(0, $listOfAdjustmentsToClear);
2734
}
35+
36+
private function addClearerToContainerParameter(ContainerBuilder $container, string $parameterName): void
37+
{
38+
assert(1 === preg_match('/^%(.*)%$/', $parameterName, $matches));
39+
$parameterName = $matches[1];
40+
$listOfAdjustmentsToClear = $container->getParameter($parameterName);
41+
$listOfAdjustmentsToClear[] = CustomerOptionRecalculator::CUSTOMER_OPTION_ADJUSTMENT;
42+
43+
$container->setParameter($parameterName, $listOfAdjustmentsToClear);
44+
}
2845
}

0 commit comments

Comments
 (0)