heldtogether / venice-php
v1.1.0
2015-12-10 20:20 UTC
Requires
- league/flysystem: ^1.0
- nesbot/carbon: ^1.20
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-14 18:31:34 UTC
README
功能切换是持续集成的主要原则之一。Venice 允许您通过在运行时提供配置来轻松开启和关闭应用程序的某些部分。
配置
您可以将配置存储在任何您选择的地方,通过创建一个实现 ConfigInterface
的类。一个从 JSON 文件加载配置的类已经提供。
使用方法
在应用程序初始化时,将 Venice 管理器和 Bucketer 绑定为单例,并将会话接口绑定到您选择的具体会话类。
$container->singleton('Venice\Manager', function(){ $factory = new Venice\Factory(); $config = new Venice\Configs\JSONFileConfig($factory); $config->setFilename('/path/to/config/file.json'); $manager = new Venice\Manager(); $manager->addConfig($config); return $manager; }); $container->singleton('Venice\Bucketer', function(){ $session = new Venice\Sessions\CookieSession(); $return new Venice\Bucketer($session); }); $container->bind( 'Venice\Interfaces\SessionInterface', 'Venice\Sessions\CookieSession' );
在任何您希望使用功能管理器的类中,注入功能管理器
/** * Basic Controller */ class Controller { /** * @var Venice\Manager */ protected $features; /** * Construct * * @param Venice\Manager $features * @return void */ public function __construct(Venice\Manager $features) { $this->features = $features; } /** * Handle the index route. */ public function index() { if ($this->features->get('feature-name')->active()) { // Do something } } }
布尔功能
布尔功能显然是开启或关闭的。
{ 'feature-name': true }
方法
/** * Check if the Feature is active * * @return bool */ public function active(); /** * Set the active state of the feature * * @param bool $active * @return void */ public function setActive($active)
定时功能
定时功能被配置为根据计划开启和关闭。在配置中可以可选地提供开始时间和/或结束时间。
{ 'feature-name': { 'type': 'timed', 'start_time': '2015-10-06 12:30:20', 'end_time': '2015-10-10 12:30:20' } }
方法
/** * Check if the Feature is active * * @return bool */ public function active(); /** * Get the start time of the Feature * * @return Carbon\Carbon */ public function startTime(); /** * Set the time the Feature should be active * * @param string $start_time * @return void */ public function setStartTime($start_time); /** * Get the end time of the Feature * * @return Carbon\Carbon */ public function endTime(); /** * Set the time the Feature should become inactive * * @param string $end_time * @return void */ public function setEndTime($end_time);
变体功能
变体功能被配置为将每个会话分桶到特定的变体中,并在会话之间持久化该信息。
{ 'feature-name': { 'type': 'variant', 'variants': [ 'control', 'variant-1', 'variant-2' ] } }
方法
/** * Check if the Feature is active * * @return bool */ public function active(); /** * Get the variant for the current session * * @return string */ public function variant();
待办事项
- 布尔功能
- 定时功能
- 变体功能(用于 A/B 测试等)
- JSON 文件配置
- 数据库配置