alignwebs / saga-server-client-php
PHP client for Laravel Saga Server
Installs: 1 747
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-03-08 00:31:09 UTC
README
Install package:
composer require alignwebs/saga-server-client-php:dev-main
Sample Code:
<?php
include 'vendor/autoload.php';
use Alignwebs\SagaClient\SagaBuilder;
use Alignwebs\SagaClient\SagaClient;
use Alignwebs\SagaClient\SagaObject;
// make saga client object
$host = 'http://saga.hyperzod.test';
$sagaClient = new SagaClient($host);
$sagaName = "TestSaga";
$sagaBuilder = new SagaBuilder($sagaName, 11);
// Add Failed Callbacks
$failed = [
"url" => "http://saga.hyperzod.test/testing/0/delete",
"method" => "POST",
"payload" => ['id' => 111]
];
$sagaBuilder->addSagaFailedCallback($failed['url'], $failed['method'], $failed['payload']);
// SETTING SERVICE
$sagaObject = new SagaObject("setting");
$payload = array(
'tenant_id' => 1,
'business_name' => 'Meco Fresh',
'store_type' => 'single',
);
$sagaObject->payload($payload);
$sagaObject->successCase("http://saga.hyperzod.test/testing/1", "GET", "success:true");
$sagaObject->failureCase("http://saga.hyperzod.test/testing/1/rollback", "POST");
$sagaBuilder->addSagaEntry($sagaObject);
try {
$sagaId = ($sagaClient->createSaga($sagaBuilder));
echo "Saga ID: " . $sagaId . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}