承接 byjg/featureflag 相关项目开发

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

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

byjg/featureflag

最新稳定版本:6.0.0

Composer 安装命令:

composer require byjg/featureflag

包简介

Allows you to enable or disable features in your application and dispatch the proper code based on the flags.

README 文档

README

sidebar_key featureflag
tags
php

FeatureFlag Dispatcher

A simple feature flag dispatcher that allows conditional code execution based on enabled feature flags.

Sponsor Build Status Opensource ByJG GitHub source GitHub license GitHub release

Feature flags are a powerful technique for managing features in your application, enabling you to toggle functionality on/off without deploying new code. This library provides a clean, interface-based approach to dispatch handlers based on feature flag states.

Basic Usage

use ByJG\FeatureFlag\FeatureFlags;
use ByJG\FeatureFlag\FeatureFlagDispatcher;
use ByJG\FeatureFlag\FeatureFlagSelector;
use ByJG\FeatureFlag\FeatureFlagHandlerInterface;

// Initialize the enabled features
FeatureFlags::addFlag('flag1', 'value1');
FeatureFlags::addFlag('flag2', 'value2');
FeatureFlags::addFlag('flag3');

// Create handler implementations
class MyHandler implements FeatureFlagHandlerInterface
{
    public function execute(mixed ...$args): mixed
    {
        echo "Handler executed!\n";
        return null;
    }
}

// Create a Dispatcher
$dispatcher = new FeatureFlagDispatcher();

// Add feature flag handlers
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value1', new MyHandler()));
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value2', new MyHandler()));

// Dispatch the request
$dispatcher->dispatch();

// Since there is a feature flag 'flag2' with value 'value2', the corresponding handler will be executed

:::note If one or more feature flags match the condition, all matching handlers will be executed in the order they were added. :::

Handler Types

  • Handler Interface - Create custom handlers implementing FeatureFlagHandlerInterface
  • Attributes - Use PHP 8 attributes to mark methods as handlers

Selector Types

Advanced Usage

Install

composer require "byjg/featureflag"

Requirements

  • PHP 8.3 to 8.5
  • PSR-11 Container (optional, for container integration)

Unit tests

composer test

Dependencies

flowchart TD
    byjg/featureflag --> php8.3-8.5
    byjg/featureflag --> psr/container
Loading

Open source ByJG

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-11-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固