PHPackages                             octarine/feature-flags - 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. octarine/feature-flags

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

octarine/feature-flags
======================

Lightweight, SOLID feature flag package for PHP

00PHP

Since Nov 17Pushed 6mo agoCompare

[ Source](https://github.com/alexwoollam/octarine)[ Packagist](https://packagist.org/packages/octarine/feature-flags)[ RSS](/packages/octarine-feature-flags/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

 [![Octarine logo](docs/logo.svg)](docs/logo.svg)

Octarine Feature Flags
======================

[](#octarine-feature-flags)

Lightweight, SOLID feature flag package for PHP 8.1+.

Octarine focuses on clean boundaries and extensibility:

- Contracts define small, focused responsibilities
- Strategies are pluggable and open for extension
- Evaluator composes repository and strategies via dependency inversion

Install
-------

[](#install)

Add to your Composer project (package name placeholder until published):

```
composer require octarine/feature-flags

```

Quick Start
-----------

[](#quick-start)

```
use Octarine\Evaluator\FlagEvaluator;
use Octarine\Model\Context;
use Octarine\Model\Flag;
use Octarine\Registry\StrategyRegistry;
use Octarine\Repository\InMemoryFlagRepository;
use Octarine\Strategy\AlwaysOnStrategy;
use Octarine\Strategy\PercentageStrategy;
use Octarine\Strategy\WhitelistStrategy;

$repo = new InMemoryFlagRepository([
    new Flag('new_ui', true), // simple on/off
    new Flag('gradual_rollout', true, 'percentage', ['percentage' => 25, 'attribute' => 'userId']),
    new Flag('beta_users', true, 'whitelist', ['attribute' => 'email', 'values' => ['a@example.com']]),
]);

$strategies = new StrategyRegistry([
    new AlwaysOnStrategy(),
    new PercentageStrategy(),
    new WhitelistStrategy(),
]);

$flags = new FlagEvaluator($repo, $strategies);

$ctx = new Context(['userId' => '123', 'email' => 'a@example.com']);

if ($flags->isEnabled('new_ui', $ctx)) {
    // show the new UI
}
```

Redis (Optional)
----------------

[](#redis-optional)

You can configure a Redis-backed repository for centralized flags.

Storage shape expected by the built-in Redis repository:

- Hash at `{prefix}:flag:{key}` with fields:
    - `enabled`: `"0"` or `"1"`
    - `strategyKey`: string or empty
    - `parameters`: JSON object string (optional)
- Optional Set at `{prefix}:flags` (or custom `keysSet`) listing all flag keys for enumeration.

Config object and factory usage:

```
use Octarine\Config\OctarineConfig;
use Octarine\Config\RedisConfig;
use Octarine\Factory\RepositoryFactory;
use Octarine\Evaluator\FlagEvaluator;
use Octarine\Registry\StrategyRegistry;
use Octarine\Strategy\AlwaysOnStrategy;
use Octarine\Strategy\PercentageStrategy;
use Octarine\Strategy\WhitelistStrategy;

$config = new OctarineConfig(
    new RedisConfig(
        host: '127.0.0.1',
        port: 6379,
        password: null,
        db: 0,
        prefix: 'octarine',
        keysSet: 'octarine:flags' // optional
    )
);

// Optionally pass an existing Redis/Predis client as 2nd argument
$repo = RepositoryFactory::fromConfig($config);

$strategies = new StrategyRegistry([
    new AlwaysOnStrategy(),
    new PercentageStrategy(),
    new WhitelistStrategy(),
]);

$flags = new FlagEvaluator($repo, $strategies);
```

Install one of the suggested Redis clients:

- `ext-redis` (php-redis)
- `predis/predis`

Concepts
--------

[](#concepts)

- Repository: supplies `Flag` definitions (in-memory provided; bring your own source)
- Strategy: evaluates flag rules (always on/off, percentage, whitelist included)
- Evaluator: orchestrates repository + strategy for a final boolean
- Context: immutable attribute bag used for targeting

Flags
-----

[](#flags)

`Flag` is a simple value object:

- `key`: unique flag key
- `enabled`: base toggle
- `strategyKey`: optional strategy id (e.g. `percentage`)
- `parameters`: strategy parameters (e.g. `percentage`, `attribute`, `values`)

Built-in Strategies
-------------------

[](#built-in-strategies)

- `always_on`: always returns true
- `always_off`: always returns false
- `percentage`: rollout N% for users bucketed by an attribute (default `userId`)
- `whitelist`: enable only for values in a list (e.g., specific emails)

Testing
-------

[](#testing)

This repo includes a basic `phpunit.xml.dist` and sample tests under `tests/`.

Run tests after installing dev dependencies:

```
composer install
vendor/bin/phpunit

```

Extending
---------

[](#extending)

Implement `Octarine\Contracts\StrategyInterface` and register your strategy with `StrategyRegistry`.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance47

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d416fe8f9619a7f92c9af9a9ec7c291257a4932175833f119aea9be9d0c951e5?d=identicon)[alexwoollam](/maintainers/alexwoollam)

---

Top Contributors

[![alexwoollam](https://avatars.githubusercontent.com/u/20298508?v=4)](https://github.com/alexwoollam "alexwoollam (1 commits)")

### Embed Badge

![Health badge](/badges/octarine-feature-flags/health.svg)

```
[![Health](https://phpackages.com/badges/octarine-feature-flags/health.svg)](https://phpackages.com/packages/octarine-feature-flags)
```

###  Alternatives

[nwilging/laravel-discord-bot

A robust Discord messaging integration for Laravel

576.0k](/packages/nwilging-laravel-discord-bot)[punkstar/ssl

PHP library for reading and understanding SSL certificates.

1824.3k](/packages/punkstar-ssl)[compwright/php-session

Standalone session implementation that does not rely on the PHP session module or the $\_SESSION global, ideal for ReactPHP applications

189.4k](/packages/compwright-php-session)

PHPackages © 2026

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