use Illuminate\Database\Eloquent\Model;
use LenderSpender\StateTransitionWorkflow\Transition;
use LenderSpender\StateTransitionWorkflow\Workflow;
class TransactionSuccessfullWorkflow extends Workflow
{
public function __construct(FakeMailer $mailer)
{
$this->mailer = $mailer;
}
/**
* @param \App\Models\Transaction $model
*/
public function execute(Model $transaction, Transition $transition): void
{
$this->mailer->mail($transaction->email, 'Payment was sucessfull');
}
}
use Illuminate\Database\Eloquent\Model;
use LenderSpender\StateTransitionWorkflow\HasStateTransitions;
/**
* @property \App\Enums\TransactionState $state
*/
class Transaction extends Model
{
use HasStateTransitions;
protected function registerStateTransitions(): void
{
$this->addState('status');
}
}
class Transaction extends Model
{
use HasStateTransitions;
protected function registerStateTransitions(): void
{
$this->addState('status')
->allowTransitions(State::FROM(), State::TO());
}
}
use Illuminate\Database\Eloquent\Model;
use LenderSpender\StateTransitionWorkflow\HasStateTransitions;
class Transaction extends Model
{
use HasStateTransitions;
protected function registerStateTransitions(): void
{
$this->addState('status')
->allowTransitions(State::CREATED(), [State::FAILED(), State::SUCCESS());
}
}
use LenderSpender\StateTransitionWorkflow\HasStateTransitions;
class Transaction extends Model
{
use HasStateTransitions;
protected function registerStateTransitions(): void
{
$this->addState('status')
->allowTransitions([State::CREATED(), State::UPDATED()], [State::FAILED(), State::SUCCESS()]);
}
}
use Illuminate\Database\Eloquent\Model;
use LenderSpender\StateTransitionWorkflow\Transition;
use LenderSpender\StateTransitionWorkflow\Workflow;
class PaidWorkflow extends Workflow
{
/**
* @param \App\Model\Transaction $model
*/
public function execute(Model $transaction, Transition $transition): void
{
dump('This is executed before the transition');
}
}
use Illuminate\Database\Eloquent\Model;
use LenderSpender\StateTransitionWorkflow\Transition;
use LenderSpender\StateTransitionWorkflow\Workflow;
class PaidWorkflow extends Workflow
{
/**
* @param \App\Model\Transaction $model
*/
public function execute(Model $transaction, Transition $transition): void
{
dump('This is executed before the transition');
$transition->execute();
dump('This is executed after the transition');
}
}
use Illuminate\Contracts\Queue\ShouldQueue;
use LenderSpender\StateTransitionWorkflow\Workflow;
class PaidWorkflow extends Workflow implements ShouldQueue
{
}
use LenderSpender\StateTransitionWorkflow\Workflow;
class PaidWorkflow extends Workflow
{
public function isAllowed(Transition $transition): bool
{
return false;
}
}
class Transaction extends Model
{
use HasStateTransitions;
protected function registerStateTransitions(): void
{
$this->addState('status')
->allowTransitions(State::CREATED(), State::SUCCESS(), PaidWorkflow::class);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.