slava-basko/saga-php
最新稳定版本:1.0.1
Composer 安装命令:
composer require slava-basko/saga-php
包简介
Saga — transactions for distributed system
README 文档
README
Transactions for distributed system.
Read it if you are not familiar with Saga pattern [https://microservices.io/patterns/data/saga.html].
This library has no dependencies on any external libs and works on PHP 5.5+.
Install
composer require slava-basko/saga-php
Usage
Create a class that implements Basko\Saga\StageInterface and add it to the pipeline. Simple as that.
For example:
class OrderFlight implements StageInterface { /** * @param Booking $payload * @return Booking */ public function execute($payload) { // Logic related to flight order. // Call external API and then $payload->setFlightId($flightId); return $payload; } /** * @param Booking $payload * @return Booking */ public function rollback($payload) { // Logic related to flight cancellation // Call external API with $payload->getFlightId(); and then $payload->resetFlightId(); return $payload; } }
The pipeline:
try { $pipe = new Pipeline(); $pipe->addStage(new OrderFlight()); $pipe->addStage(new OrderCar()); $pipe->addStage(new OrderHotel()); $pipe->execute($booking); } catch (\Exception $e) { // Log }
All stages will be executed sequentially: OrderFlight::execute(), OrderCar::execute(), OrderHotel::execute().
Rollback also called sequentially but in reverse order: OrderHotel::rollback(), OrderCar::rollback(), OrderFlight::rollback().
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-11