maxiviper117/result-flow
最新稳定版本:v1.3.0
Composer 安装命令:
composer require maxiviper117/result-flow
包简介
A minimal Result type with branch-aware chaining for PHP
README 文档
README
Minimal, type-safe Result monad for explicit success/failure handling in PHP.
Primary class:
Maxiviper117\ResultFlow\Result(seesrc/Result.php)
Why
- Keep success and failure paths explicit
- Chain actions fluently with metadata propagation
- Convert exceptions to failures automatically
- Small surface area with PHPStan-friendly templates
Installation
composer require maxiviper117/result-flow
Import and use:
use Maxiviper117\ResultFlow\Result;
Laravel config publish (optional)
The package is framework-agnostic, but if you're using Laravel the service provider is auto-discovered. Publish the config to override debug sanitization settings (redaction token, sensitive keys, max string length):
php artisan vendor:publish --tag=result-flow-config
Edit config/result-flow.php to match your policies. Keys include enabled, redaction, sensitive_keys, max_string_length, and truncate_strings. Result::toDebugArray() will pick up these values via the config() helper when present.
Quick Start
$result = Result::ok($payload) ->then(new ValidateOrder) // runs on success ->then(fn($data, $meta) => save($data)) ->otherwise(fn($error, $meta) => cacheFallback($error, $meta)); // Handle both branches return $result->match( onSuccess: fn($value) => response()->json($value), onFailure: fn($error) => response()->json(['error' => $error], 400), );
Documentation
The full guide, API reference, patterns, and testing notes are available at https://maxiviper117.github.io/result-flow/result/.
Contributing
See CONTRIBUTING.md for setup, checks, and PR expectations.
Testing
composer test
License
The MIT License (MIT). Please see LICENSE.md for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09