Skip to content

Commit

Permalink
PurchaseFlowのPriorityが意図しないソート順になっている場合がある #6257 を修正
Browse files Browse the repository at this point in the history
purchaseFlowで呼び出すメソッドがflowTypeごとにソートされていなかったため、flowTypeごとにソートされるように調整
  • Loading branch information
systemfriend-tsuji committed Jul 29, 2024
1 parent c972044 commit 4a7d085
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/Eccube/DependencyInjection/Compiler/PurchaseFlowPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,32 @@ public function process(ContainerBuilder $container)
*/
foreach ($this->getProcessorTags() as $tag => $methodName) {
/** @var Reference $id */
$allMethod = [];
$i = 0;
// findAndSortTaggedServicesでは、flow_typeごとのソートができないため
// その並びをもとに配列に入れ直す
foreach ($this->findAndSortTaggedServices($tag, $container) as $id) {
$def = $container->findDefinition($id);
foreach ($def->getTag($tag) as $attributes) {
if (isset($attributes['flow_type'])) {
/**
* @var string $flowType
* @var Definition $purchaseFlowDef
*/
foreach ($flowTypes as $flowType => $purchaseFlowDef) {
if ($flowType === $attributes['flow_type']) {
$purchaseFlowDef->addMethodCall($methodName, [$id]);
}
}
$attributes['id'] = $id;
$attributes['index'] = ++$i;
$attributes['priority'] = isset($attributes['priority']) ? $attributes['priority'] : 0;
$allMethod[$attributes['flow_type']][] = $attributes;
}
}
}
/**
* @var string $flowType
* @var Definition $purchaseFlowDef
*/
foreach ($allMethod as $flowType => $flowMethod) {
$purchaseFlowDef = isset($flowTypes[$flowType]) ? $flowTypes[$flowType] : null; ;
if (!is_null($purchaseFlowDef) && count($flowMethod) > 0) {
// flow_typeごとにソートをしてセットする
uasort($flowMethod, static fn ($a, $b) => $b['priority'] <=> $a['priority'] ? : $a['index'] <=> $b['index']);
foreach ($flowMethod as $attributes) {
$purchaseFlowDef->addMethodCall($methodName, [$attributes['id']]);
}
}
}
Expand Down

0 comments on commit 4a7d085

Please sign in to comment.