-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Winzou State Machine config to the CompilerPass (#175)
- Loading branch information
Showing
5 changed files
with
83 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/DependencyInjection/CompilerPass/AddWinzouStateMachineConfigurationPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; | ||
|
||
final class AddWinzouStateMachineConfigurationPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
try { | ||
/** @var string $stateMachineDefaultAdapter */ | ||
$stateMachineDefaultAdapter = $container->resolveEnvPlaceholders( | ||
$container->getParameter('sylius_abstraction.state_machine.default_adapter'), | ||
true, | ||
); | ||
/** @var array<string, string> $stateMachineAdapterMapping */ | ||
$stateMachineAdapterMapping = $container->resolveEnvPlaceholders( | ||
$container->getParameter('sylius_abstraction.state_machine.graphs_to_adapters_mapping'), | ||
true, | ||
); | ||
} catch (ParameterNotFoundException) { | ||
return; | ||
} | ||
|
||
if ($this->hasWinzouStateMachineGraph('sylius_payment', $stateMachineDefaultAdapter, $stateMachineAdapterMapping)) { | ||
$container->prependExtensionConfig('winzou_state_machine', [ | ||
'sylius_payment' => [ | ||
'callbacks' => [ | ||
'before' => [ | ||
'tpay_refund_payment' => [ | ||
'on' => ['refund'], | ||
'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], | ||
'args' => ['object'], | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
} | ||
|
||
if ($this->hasWinzouStateMachineGraph('sylius_refund_refund_payment', $stateMachineDefaultAdapter, $stateMachineAdapterMapping)) { | ||
$container->prependExtensionConfig('winzou_state_machine', [ | ||
'sylius_refund_refund_payment' => [ | ||
'callbacks' => [ | ||
'before' => [ | ||
'tpay_refund_payment' => [ | ||
'on' => ['complete'], | ||
'do' => ['@commerce_weavers_sylius_tpay.refunding.dispatcher.refund', 'dispatch'], | ||
'args' => ['object'], | ||
], | ||
], | ||
], | ||
], | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* @param array<string, string> $stateMachineAdapterMapping | ||
*/ | ||
private function hasWinzouStateMachineGraph( | ||
string $graphName, | ||
string $stateMachineDefaultAdapter, | ||
array $stateMachineAdapterMapping, | ||
): bool { | ||
return ( | ||
isset($stateMachineAdapterMapping[$graphName]) && | ||
$stateMachineAdapterMapping[$graphName] === 'winzou_state_machine' | ||
) || | ||
( | ||
!isset($stateMachineAdapterMapping[$graphName]) && | ||
$stateMachineDefaultAdapter === 'winzou_state_machine' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters