aaronmacaron/reaction
Composer 安装命令:
composer require aaronmacaron/reaction
包简介
Library for dealing with reactions of actions
README 文档
README
This library makes it easy to handle reactions of actions, methods and functions. If you are dealing with methods that can either be successful or fail and want more information about the result of the method, you can use a reaction.
Installation
You can install reaction using Composer:
$ composer require aaronmacaron/reaction
To install and use the reaction library you need PHP version 7.1 or newer.
Example
You can use this library as follows:
<?php use Aaronmacaron\Reaction\Reaction; include __DIR__ . "/vendor/autoload.php"; function validatePassword(string $password): Reaction { if (empty($password)) { return Reaction::failure("The password must not be empty!"); } if (strlen($password) >= 8) { return Reaction::success(); } return Reaction::failure("The password must be at least eight chars long."); } validatePassword("secret") ->succeed(function () { echo "Password is valid" . PHP_EOL; })->fail(function (Reaction $reaction) { echo "The password is not valid: " . $reaction->getMessage() . PHP_EOL; }); // Output: The password is not valid: The password must be at least eight chars long.
统计信息
- 总下载量: 77
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-04-15