PHPackages                             airship/flagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. airship/flagger

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

airship/flagger
===============

Flagger PHP SDK

1.0.0(7y ago)119.4k1MITPHPPHP &gt;=7.1

Since Oct 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/airshiphq/flagger-php)[ Packagist](https://packagist.org/packages/airship/flagger)[ Docs](https://github.com/airshiphq/flagger-php)[ RSS](/packages/airship-flagger/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

 [ ![Airship](https://avatars3.githubusercontent.com/u/29476417?s=200&v=4) ](https://airshiphq.com/)

Flagger PHP
===========

[](#flagger-php)

Requirement
-----------

[](#requirement)

PHP 7.1 or higher

Prerequisite
------------

[](#prerequisite)

This SDK works with the [Airship Microservice](https://github.com/airshiphq/airship-microservice). Please refer to its documentation before proceeding.

### Content

[](#content)

- [01 Installation](#01-installation)
- [02 Key Concepts](#02-key-concepts)
- [03 Configuring Flags](#03-configuring-flags)
- [04 Usage](#04-usage)

01 Installation
---------------

[](#01-installation)

`php composer.phar require airship/flagger`

02 Key Concepts
---------------

[](#02-key-concepts)

In Flagger, feature **flags** control traffic to generic objects (called **entities**). The most common type for entities is `User`, but they can also be other things (i.e. `Page`, `Group`, `Team`, `App`, etc.). By default, all entities have the type `User`.

Entities can be represented by dicitionaries or by using the `Entity` class.

03 Configuring Flags
--------------------

[](#03-configuring-flags)

To configure Flagger, we would need to pass a new Client instance.

```
require 'vendor/autoload.php';

// Create an instance with an env key
$flagger = new Flagger\Flagger(new Flagger\Client\GuzzleClient(''));
```

04 Usage
--------

[](#04-usage)

```
if ($flagger->flag('bitcoin-pay')->isEnabled(['id' => 5])) {
  // ...
}

// Define your entity
$entity = [
  'type' => 'User', // 'type' starts with a capital letter '[U]ser', '[H]ome', '[C]ar'. If omittied, it will default to 'User'
  'id' => '1234', // 'id' must be a string or integer
  'displayName' => 'ironman@stark.com', // must be a string. If omitted, the SDK will use the same value as 'id' (converted to a string)
];
// or
$entity = new Entity(1234, 'User', 'ironman@stark.com');

// The most compact form can be:
$entity = [
  'id' => 1234
];
// or
$entity = new Entity(1234);

// as this will translate into:
$entity = [
  'type' => 'User',
  'id' => '1234',
  'displayName' => '1234',
];

$flagger->flag('bitcoin-pay')->isEnabled($entity); // Does the entity have the feature 'bitcoin-pay'?
$flagger->flag('bitcoin-pay')->getTreatment($entity); // Get the treatment associated with the flag
$flagger->flag('bitcoin-pay')->isEligible($entity);
// Returns true if the entity can potentially receive the feature via sampling
// or is already receiving the feature.

// Note: It may take up to a minute for entities gated to show up on our web app.
```

Attributes (for complex targeting)
----------------------------------

[](#attributes-for-complex-targeting)

```
// Define your entity with an attributes dictionary of key-value pairs.
// Values must be a string, a number, or a boolean. nil values are not accepted.
// For date or datetime string value, use iso8601 format.
$entity = [
  'type' => 'User',
  'id' => '1234',
  'displayName' => 'ironman@stark.com',
  'attributes' => [
    't_shirt_size' => 'M',
    'date_created' => '2018-02-18',
    'time_converted' => '2018-02-20T21:54:00.630815+00:00',
    'owns_property' => true,
    'age' => 39,
  ],
];
// or
$entity = new Entity(
  1234,
  'User',
  'ironman@stark.com',
  [
    't_shirt_size' => 'M',
    'date_created' => '2018-02-18',
    'time_converted' => '2018-02-20T21:54:00.630815+00:00',
    'owns_property' => true,
    'age' => 39,
  ]
);

// Now in app.airshiphq.com, you can target this particular user using its
// attributes
```

Group (for membership-like cascading behavior)
----------------------------------------------

[](#group-for-membership-like-cascading-behavior)

```
// An entity can be a member of a group.
// The structure of a group entity is just like that of the base entity.
$entity = [
  'type' => 'User',
  'id' => '1234',
  'displayName' => 'ironman@stark.com',
  'attributes' => [
    't_shirt_size' => 'M',
    'date_created' => '2018-02-18',
    'time_converted' => '2018-02-20T21:54:00.630815+00:00',
    'owns_property' => true,
    'age' => 39,
  ],
  'group' => [
    'type' => 'Club',
    'id' => '5678',
    'displayName' => 'SF Homeowners Club',
    'attributes' => [
      'founded' => '2016-01-01',
      'active' => true,
    ],
  ],
];
// or
$group = new Entity(
  5678,
  'Club',
  'SF Homeowners Club',
  [
    'founded' => '2016-01-01',
    'active' => true,
  ]
);
$user = new Entity(
  1234,
  'User',
  'ironman@stark.com',
  [
    't_shirt_size' => 'M',
    'date_created' => '2018-02-18',
    'time_converted' => '2018-02-20T21:54:00.630815+00:00',
    'owns_property' => true,
    'age' => 39,
  ],
  $group
);

// Inheritance of values `isEnabled`, `getTreatment`, `getPayload`, and `isEligible` works as follows:
// 1. If the group is enabled, but the base entity is not,
//    then the base entity will inherit the values `isEnabled`, `getTreatment`, `getPayload`, and `isEligible` of the group entity.
// 2. If the base entity is explicitly blacklisted, then it will not inherit.
// 3. If the base entity is not given a variation in rule-based variation assignment,
//    but the group is and both are enabled, then the base entity will inherit
//    the variation of the group's.

// You can ask questions about the group directly (use the `is_group` flag):
$entity = [
  'isGroup' => true,
  'type' => 'Club',
  'id' => '5678',
  'displayName' => 'SF Homeowners Club',
  'attributes' => [
    'founded' => '2016-01-01',
    'active' => true,
  ],
];

$flagger->flag('bitcoin-pay')->isEnabled($entity);
```

Contributing
------------

[](#contributing)

Dependencies are managed using [Composer](https://getcomposer.org/) and the following documentation assumes that `composer` is installed on the your executable path.

### Code Style

[](#code-style)

PSR-2 code style is enforced. Check the code style with `composer check-style` and fix it with `composer fix-style`.

### Running Tests

[](#running-tests)

Tests are run through PhpUnit

```
composer test

```

---

License
=======

[](#license)

[MIT](/LICENSE)

[![StackShare](https://camo.githubusercontent.com/d27f0da116be85ad69709cd154931c443ba4d7a3d36c920f503409815aeabda3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f746563682d737461636b2d3036393066612e7376673f7374796c653d666c6174)](https://stackshare.io/airship/airship)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2821d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2756574?v=4)[airship](/maintainers/airship)[@Airship](https://github.com/Airship)

---

Tags

featureflag

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/airship-flagger/health.svg)

```
[![Health](https://phpackages.com/badges/airship-flagger/health.svg)](https://phpackages.com/packages/airship-flagger)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k34](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[opensoft/rollout

Feature switches or flags for PHP

2571.9M5](/packages/opensoft-rollout)[francescomalatesta/laravel-feature

A simple package to manage feature flagging in a Laravel project.

210206.7k](/packages/francescomalatesta-laravel-feature)[zumba/swivel

Strategy driven feature toggles

208138.1k5](/packages/zumba-swivel)[novaway/feature-flag-bundle

Very KISS bundle to manage features flag

25291.0k](/packages/novaway-feature-flag-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
