-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
261 additions
and
133 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 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 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 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 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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine; | ||
|
||
use Sylius\Abstraction\StateMachine\StateMachineInterface as SyliusAbstractionStateMachineInterface; | ||
|
||
final class CompositeStateMachine implements StateMachineInterface | ||
{ | ||
private SyliusAbstractionStateMachineInterface $stateMachine; | ||
|
||
public function __construct(SyliusAbstractionStateMachineInterface $stateMachine) | ||
{ | ||
$this->stateMachine = $stateMachine; | ||
} | ||
|
||
public function getTransitionToState(object $subject, string $graphName, string $toState): ?string | ||
{ | ||
return $this->stateMachine->getTransitionToState($subject, $graphName, $toState); | ||
} | ||
|
||
public function apply(object $subject, string $graphName, string $transition, array $context = []): void { | ||
$this->stateMachine->apply($subject, $graphName, $transition, $context); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine; | ||
|
||
interface StateMachineInterface | ||
{ | ||
public function getTransitionToState(object $subject, string $graphName, string $toState): ?string; | ||
|
||
public function apply(object $subject, string $graphName, string $transition, array $context = []): void; | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine; | ||
|
||
use SM\Factory\FactoryInterface; | ||
use Sylius\Resource\StateMachine\StateMachineInterface as SyliusStateMachineInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class WinzouStateMachine implements StateMachineInterface | ||
{ | ||
private FactoryInterface $factory; | ||
|
||
public function __construct(FactoryInterface $factory) | ||
{ | ||
$this->factory = $factory; | ||
} | ||
|
||
public function getTransitionToState(object $subject, string $graphName, string $toState): ?string | ||
{ | ||
$stateMachine = $this->factory->get($subject, $graphName); | ||
Assert::isInstanceOf($stateMachine, SyliusStateMachineInterface::class); | ||
|
||
return $stateMachine->getTransitionToState($toState); | ||
} | ||
|
||
public function apply(object $subject, string $graphName, string $transition, array $context = []): void | ||
{ | ||
$stateMachine = $this->factory->get($subject, $graphName); | ||
|
||
$stateMachine->apply($transition); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/DependencyInjection/Compiler/WinzouStateMachineCallbacksModifier.php
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
35 changes: 35 additions & 0 deletions
35
src/EventListener/Workflow/PaymentCompletedStateListener.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FluxSE\SyliusPayumStripePlugin\EventListener\Workflow; | ||
|
||
use FluxSE\SyliusPayumStripePlugin\StateMachine\PaymentStateProcessorInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Symfony\Component\Workflow\Event\CompletedEvent; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class PaymentCompletedStateListener | ||
{ | ||
private PaymentStateProcessorInterface $paymentStateProcessor; | ||
|
||
public function __construct(PaymentStateProcessorInterface $paymentStateProcessor) | ||
{ | ||
$this->paymentStateProcessor = $paymentStateProcessor; | ||
} | ||
|
||
public function __invoke(CompletedEvent $event): void | ||
{ | ||
/** @var PaymentInterface $payment */ | ||
$payment = $event->getSubject(); | ||
Assert::isInstanceOf($payment, PaymentInterface::class); | ||
|
||
$transition = $event->getTransition(); | ||
Assert::notNull($transition); | ||
// state machine transition from list always contains 1 element | ||
$fromState = $transition->getFroms()[0]; | ||
Assert::notNull($fromState); | ||
|
||
$this->paymentStateProcessor->__invoke($payment, $fromState); | ||
} | ||
} |
Oops, something went wrong.