dzunke/feature-flags-bundle
最新稳定版本:v6.1.1
Composer 安装命令:
composer require dzunke/feature-flags-bundle
包简介
Symfony Bundle to implement Feature Flags to your Application
README 文档
README
The Bundle will allow you to implement Feature Flags to your Application. Please Note that there is no Interface available, so the Flags must be configured directly in Symfony-Configs.
- Use Versions ^2.0 if Symfony 3.0 Support is wanted!
- Use Versions ^4.0 if Symfony 4.2 Support is wanted!
- Use Versions ^5.0 if Symfony 4.3 or 5.x Support is wanted!
- Use Versions ^6.0 if Symfony 6.0 Support is wanted!
- Use Versions ^6.1 if Symfony >6.1 Support is wanted!
Documentation
Setup
You can add the Bundle by running Composer on your shell or adding it directly to your composer.json
php composer.phar require dzunke/feature-flags-bundle:"^6.1"
"require" : { "dzunke/feature-flags-bundle": "^6.1" }
The Namespace will be registered by autoloading with Composer but to use the integrated features for symfony you have to register the Bundle.
# app/AppKernel.php public function registerBundles() { $bundles = [ // [..] new DZunke\FeatureFlagsBundle\DZunkeFeatureFlagsBundle(), ]; }
Without any Configuration all Features will be enabled! But at this point you can start developing.
Usage
Service-Container
The simplest way to use the Bundle is to get the Container and request the state of a Feature. Note: Features that are not configured are enabled by default.
# src/AcmeBundle/Controller/IndexController.php <?php namespace AcmeBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { if ($this->get('dz.feature_flags.toggle')->isActive('FooFeature')) { // [...] } // [...] } }
Twig
# src/AcmeBundle/Resources/views/Index/index.html.twig {% if has_feature('FooFeature') %} <p>Lorem Ipsum Dolor ...</p> {% endif %}
Argument-Usage
On every check you can give arguments to the check if you want to specify the check. The Arguments for a Flag can be definied by an array on the validation method. The Keys must be named like the condition itself. Please Note that if the Condition does not support the Arguments they would be ignored.
# src/AcmeBundle/Resources/views/Index/index.html.twig {% if has_feature('FooBarFeature', {'device': 'tablet'}) %} <p>Lorem Ipsum Dolor ...</p> {% endif %}
Creating a Condition
At first the Condition must be created. The Condition must implement the ConditionInterface. There is a general context available.
<?php # src/AcmeBundle/FeatureFlags/Condition/Foo.php namespace AcmeBundle\FeatureFlags\Condition; use DZunke\FeatureFlagsBundle\Toggle\Conditions\AbstractCondition; use DZunke\FeatureFlagsBundle\Toggle\Conditions\ConditionInterface; class Foo extends AbstractCondition implements ConditionInterface { public function validate($config, $argument = null) { // [..] Implement your Methods to Validate the Feature return true; } public function __toString() { return 'Foo'; } }
After the Class was created it must be defined as a Tagged-Service. With this Tag and the Alias the Condition would be loaded. At this point there is many space to extend the Condition by adding calls or arguments.
# src/AcmeBundle/Resources/config/services.yml services: acme.feature_flags.condition.fo: class: DZunke\FeatureFlagsBundle\Toggle\Conditions\Foo calls: - [setContext, [@dz.feature_flags.context]] tags: - { name: dz.feature_flags.toggle.condition, alias: foo }
Configuration
Example
d_zunke_feature_flags: flags: FooFeature: # feature will always be disabled default: false BarFeature: # feature will only be enabled for a list of special ClientIps conditions_config: ip_address: [192.168.0.1] BazFeature: # the feature will be enabled for the half of the users conditions_config: percentage: percentage: 50 cookie: ExampleCookieForFeature lifetime: 3600 FooBarFeature: conditions_config: device: tablet: "/ipad|playbook|android|kindle|opera mobi|arm|(^.*android(?:(?!mobile).)*$)/i" mobile: "/iphone|ipod|bb10|meego|blackberry|windows\\sce|palm|windows phone|((android.*mobile))|mobile/i"
Available Conditions
hostname: [example.local, www.example.local]
ip_address: [192.168.0.1, 192.168.0.2]
percentage: cookie: NameThisCookieForTheUser # Default: 84a0b3f187a1d3bfefbb51d4b93074b1e5d9102a percentage: 29 # Default: 100 lifetime: 3600 # Default: 86400 - 1 day
device: name: regex # give regex for each valid device
# See php.net/datetime date: start_date: "2016-09-01" # Start date, accepts DateTime constructor values. Defaults to "now". end_date: "2016-09-03" # End date, accepts DateTime constructor values. Defaults to "now".
Reference
d_zunke_feature_flags: # the default state to return for non-existent features default: true # feature flags for the built system flags: # Prototype feature: # general active state for the flag - if conditions used it would be irrelevant default: false # list of configured conditions which must be true to set this flag active conditions_config: []
Resources
License
FeatureFlagsBundle is licensed under the MIT license.
dzunke/feature-flags-bundle 适用场景与选型建议
dzunke/feature-flags-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 203.82k 次下载、GitHub Stars 达 67, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「feature flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dzunke/feature-flags-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dzunke/feature-flags-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dzunke/feature-flags-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
统计信息
- 总下载量: 203.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 67
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知