flipt-php is a small wrapper package for the Flipt REST API to be able to easily integrate Flipt into your PHP applications.
composer require fetzi/flipt-php
The Flipt
class uses HTTPlug a HTTP Client abstraction to make the API requests. You have to pass a base URL to the static create
function. Everything else (HttpClient
, RequestFactory
& StreamFactory
) is automatically determined.
$flipt = Flipt::create('http://localhost:8080');
By calling the evaluate
method you can check if a certain user (entity) should get a certain feature or not. To perform a evaluation you need to create a EvaluateRequest
that contains the data to evaluate.
$evaluateRequest = new EvaluateRequest('sample-flag', 'user-id', ['foo' => 'bar'])
$evaluateResponse = $flipt->evaluate($evaluateRequest);
if ($evaluateResponse->isMatch()) {
// awesome new feature
} else {
// old boring feature
}
To be able to determine which variant of a feature-flag should be displayed you need to use the getVariant()
method on the response.
The EvaluateResponse
also provides a variant that can be accessed via the getValue()
or getVariant()
method:
$evaluateRequest = new EvaluateRequest('sample-flag', 'user-id', ['foo' => 'bar'])
$evaluateResponse = $flipt->evaluate($evaluateRequest);
if ($evaluateResponse->isMatch()) {
switch ($evaluateResponse->getVariant()) {
case 'a':
// show A variant
break;
case 'b':
// show B variant
break;
}
}
flipt-php was created by Johannes Pichler under the MIT license.