定制 octarine/feature-flags 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

octarine/feature-flags

Composer 安装命令:

composer require octarine/feature-flags

包简介

Lightweight, SOLID feature flag package for PHP

README 文档

README

Octarine logo

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

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

composer require octarine/feature-flags

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)

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

  • 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

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

  • 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

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

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

octarine/feature-flags 适用场景与选型建议

octarine/feature-flags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 octarine/feature-flags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 octarine/feature-flags 我们能提供哪些服务?
定制开发 / 二次开发

基于 octarine/feature-flags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-11-17