承接 phputil/flags 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

phputil/flags

Composer 安装命令:

composer require phputil/flags

包简介

A lightweight, extensible feature flags framework for PHP

README 文档

README

Version Build License PHP

🚩 A lightweight, customizable feature flags framework for PHP

You can customize:

  • 🧠 How flags are evaluated, through Strategies.
  • 💾 How flags are stored, through Storages.
  • 📢 Who is notified about flag changes or removal, through Listeners.

Installation

PHP 7.4 or later. No external dependencies.

composer require phputil/flags

👉 You may also like to install some of the official extensions.

Extensions

Official extensions:

Third-party extensions:

  • Create yours and open an Issue to be evaluated. It may appear here.

Usage

Basic flag checking:

require_once 'vendor/autoload.php';
use phputil\flags\FlagManager;

// By default, it uses a storage-based strategy with an in-memory storage
$flag = new FlagManager();

if ( $flag->isEnabled( 'my-cool-feature' ) ) {
    echo 'Cool feature available!', PHP_EOL;
} else {
    echo 'Not-so-cool feature here', PHP_EOL;
}

Customizing a certain verification:

// ...
use phputil\flags\FlagVerificationStrategy;

$flag = new FlagManager();

$myLuckBasedStrategy = new class implements FlagVerificationStrategy {
    function isEnabled( string $flag ): bool {
        return rand( 1, 100 ) >= 50; // 50% chance
    }
};

if ( $flag->isEnabled( 'my-cool-feature', [ $myLuckBasedStrategy ] ) ) {
    echo 'Cool feature available!', PHP_EOL;
} else {
    echo 'Not-so-cool feature here', PHP_EOL;
}

Customizing all the verifications:

$flag = new FlagManager( null, [ $myLuckBasedStrategy ] );

if ( $flag->isEnabled( 'my-cool-feature' ) ) {
    ...

Setting a flag:

$flag->enable( 'my-cool-feature' );
$flag->disable( 'my-cool-feature' );
$flag->setEnable( 'my-cool-feature', true /* or false */ );

Removing a flag:

$flag->remove( 'my-cool-feature' );

Retrieving flag data:

$flagData = $flag->getStorage()->get( 'my-cool-feature' ); // null if not found

Adding a listener:

// ...
use phputil\flags\FlagListener;
use phputil\flags\FlagData;

$myListener = new class implements FlagListener {
  public function notify( string $event, FlagData $flagData ): void {
    if ( $event === 'change' ) {
        echo 'Flag ', $flagData->key, ' is now ', $flagData->enabled ? 'enabled': 'disabled', PHP_EOL;
    } else if ( $event === 'removal' ) {
        echo 'Flag ', $flagData->key, ' was removed.', PHP_EOL;
    }
  }
};

$flag->addListener( $myListener ); // v0.5.0+
// or $flag->getListeners()->add( $myListener );

$flag->enable( 'my-cool-feature' ); // Notify the listener

Customization

Storages

Use a different flag storage by:

How to configure it:

$storage = /* Create your storage here, e.g. new InMemoryStorage() */;
$flag = new FlagManager( $storage );

Storages available in the framework:

Strategies

Use a flag verification strategy by:

How to configure it globally:

$strategies = [ /* pass your strategies here   */ ];
$flag = new FlagManager( null, $strategies );

Strategies available in the framework:

👉 A flag is considered enabled when all the strategies considered it enabled.

Listeners

Define a listener by:

How to configure it:

$flag->addListener( $myListener ); // v0.5.0+
// or $flag->getListeners()->add( $myListener );

Roadmap

  • Extensible library
  • Official extensions:
    • PDO-based storage
    • Firebase-based storage
    • Webhook-like listener
  • REST API (external repository)
  • Web-based control panel (external repository)

License

MIT © Thiago Delgado Pinto

phputil/flags 适用场景与选型建议

phputil/flags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 60 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「php」 「library」 「flag」 「feature」 「toggle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-10