Skip to content

alignwebs/saga-server-client-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP client for Laravel Saga Server

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";
}

About

PHP client for Laravel Saga Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages