decodelabs/fluidity
最新稳定版本:v0.3.7
Composer 安装命令:
composer require decodelabs/fluidity
包简介
Tools for creating fluent interfaces
README 文档
README
Tools for creating fluent interfaces.
Fluidity provides a set of middleware interfaces that aid in the development of libraries that themselves aim to provide fluid interfaces.
Installation
This package requires PHP 8.4 or higher.
Install via Composer:
composer require decodelabs/fluidity
Usage
Method chaining
namespace DecodeLabs\Fluidity; interface Then { public function then(callable $callback): Then; public function thenEach(iterable $values, callable $callback): Then; public function thenIf(?bool $truth, callable $yes, callable $no=null): Then; public function thenUnless(?bool $truth, callable $no, callable $yes=null): Then; }
Create fluent object interfaces with basic generic logic structure support.
use DecodeLabs\Fluidity\Then; use DecodeLabs\Fluidity\ThenTrait; $test = new class() implements Then { use ThenTrait; public function doThing(int $value=null) {} }; $truth = true; $test ->then(function($test) { $test->doThing(); }) ->thenEach([1, 2, 3], function($test, $value) { // Called three times $test->doThing($value); }) ->thenIf($truth, function($test) { // This gets called if($truth) }, function($test) { // This get called otherwise }) ->thenUnless($truth, function($test) { // This gets called if(!$truth) }, function($test) { // This get called otherwise });
Licensing
Fluidity is licensed under the MIT License. See LICENSE for the full license text.
统计信息
- 总下载量: 37.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-06