Skip to content

Repository files navigation

Fluidity

PHP from PackagistLatest VersionTotal DownloadsGitHub Workflow StatusPHPStanLicense

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

namespaceDecodeLabs\Fluidity;
interface Then
{
publicfunctionthen(callable$callback): Then;
publicfunctionthenEach(iterable$values, callable$callback): Then;
publicfunctionthenIf(?bool$truth, callable$yes, callable$no=null): Then;
publicfunctionthenUnless(?bool$truth, callable$no, callable$yes=null): Then;
}

Create fluent object interfaces with basic generic logic structure support.

useDecodeLabs\Fluidity\Then;
useDecodeLabs\Fluidity\ThenTrait;
$test = newclass() implements Then {
use ThenTrait;
publicfunctiondoThing(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.

About

Tools for creating fluent interfaces in PHP

Topics

Resources

Stars

4 stars

Watchers

3 watching

Forks

Releases

Contributors

Languages