treehouselabs / feature-toggle
功能开关库
1.0.3
2018-02-21 16:00 UTC
Requires
- php: >=7.0
- symfony/http-foundation: ^2.8|^3.0|^4.0
- symfony/options-resolver: ^2.8|^3.0|^4.0
Requires (Dev)
- behat/behat: ~3.0
- phpunit/phpunit: ^5.5
- psr/cache: ^1.0
- symfony/symfony: ^2.8|^3.0|^4.0
This package is not auto-updated.
Last update: 2024-09-14 19:31:27 UTC
README
简单的功能开关库
安装
composer require treehouselabs/feature-toggle
使用
$features = new FeatureToggleCollection(); $features->registerToggle( 'feature-x', new BooleanFeatureToggle(true) ); if ($features->isEnabled('feature-x')) { // perform stuff for feature-x }
Behat上下文
# behat.yml default: suites: default: contexts: - TreeHouse\FeatureToggle\Bridge\Behat\FeatureToggleContext: cacheItemPool: '@cache_item_pool' #PSR-6 cache item pool
<?php class Feature { private $features; public function __construct(FeatureToggleCollectionInterface $features) { $this->features = $features; } public function indexAction() { if ($this->features->isEnabled('feature-y')) { return 'Enabled!'; } return 'Disabled!'; } } $toggleCollection = new CacheFeatureToggleCollection(); $toggleCollection->setCacheItemPool($psr6CacheItemPool); // Overwrite the FeatureToggleCollection with the CacheFeatureToggleCollection in test env new Feature($toggleCollection);
# feature-y.feature Feature: Feature-Y Scenario: Feature-Y is enabled Given the feature toggle "feature-y" is enabled And I am on the homepage Then I should see "Enabled!" Scenario: Feature-Y is disabled # Given the feature toggle "feature-y" is disabled (default) Given I am on the homepage Then I should see "Disabled!"
测试
composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件发送至 dev@treehouse.nl 而不是使用问题跟踪器。
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。