Giter Club home page Giter Club logo

flipt-php's Introduction

GitHub Workflow Status (main) Total Downloads License


flipt-php is a small wrapper package for the Flipt REST API to be able to easily integrate Flipt into your PHP applications.

Installation

composer require fetzi/flipt-php

Usage

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
}

Variants

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.

flipt-php's People

Contributors

fetzi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.