ghostwriter/result
最新稳定版本:2.0.0
Composer 安装命令:
composer require ghostwriter/result
包简介
Provides a Result type implementation for PHP
关键字:
README 文档
README
Provides a Result type implementation for PHP using ghostwriter/option
Installation
You can install the package via composer:
composer require ghostwriter/result
Usage
use Ghostwriter\Result\Failure; use Ghostwriter\Result\Success; // --- Success --- $success = Success::new('Hello world!'); $success->get(); // 'Hello world!' // --- Failure --- $failure = Failure::new(new ExampleException()); $failure->get(); // throws: ResultException $failure->getOr('Fallback'); // 'Fallback' $failure->getError(); // returns: instance of ExampleException // --- Example --- function divide(int $x, int $y): ResultInterface { if ($y === 0) { return Result::failure(new DivisionByZeroError); } return Result::success($x / $y); } divide(1, 0); // Error(DivisionByZeroError) divide(1, 1); // Success(1)
Credits
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
License
Please see LICENSE for more information on the license that applies to this project.
Security
Please see SECURITY.md for more information on security disclosure process.
统计信息
- 总下载量: 3.16M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04