Skip to content

Commit

Permalink
Merge pull request #6258 from systemfriend-tsuji/feature/fix_purchase…
Browse files Browse the repository at this point in the history
…_flow_priority

PurchaseFlowのPriorityが意図しないソート順になっている場合がある #6257 の修正
  • Loading branch information
dotani1111 authored Sep 11, 2024
2 parents f0adfec + 4a7d085 commit 4a80b63
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 4a80b63

Please sign in to comment.