jlis/judge
Composer 安装命令:
composer require jlis/judge
包简介
Judge handles feature and value toggles/flaggings for Laravel.
README 文档
README
The easy way to toggle/decide features and values.
- Installation.
- Feature configuration.
- Feature configuration examples.
- Value configuration.
- Value configuration examples.
- Voters.
- Adapters.
- Usage.
- TBD.
Installation
First, pull in the package through Composer.
composer require jlis/judge
And then include the service provider within app/config/app.php.
'providers' => [ Jlis\Judge\JudgeServiceProvider::class, ];
And, for convenience, add a facade alias to this same file at the bottom:
'aliases' => [ 'Feature' => Jlis\Judge\Feature::class, 'Value' => Jlis\Judge\Value::class, ];
Copy the package configs to your local config with the publish command:
php artisan vendor:publish
Feature configuration
The feature configuration is stored in:
app/config/features.php
A feature is defined as something which is either on or off and should be only used for that kind of toggles. Lets see:
'show_memory_usage' => [ [ 'value' => true, 'filters' => ['debug:true'], ], ],
The name of the feature is show_memory_usage and it should return true if the "debug" Voter returns true (it checks whether the debug mode is enabled or not, see DebugVoter.php)
Note that the default value of a feature, if not defined otherwise, is always false.
Feature configuration examples
A simple feature without any filters ( note that the value can also be a string like "true", "on" or "1", it will be converted into a boolean ):
'enable_captcha' => [ [ 'value' => true, ], ],
A feature with multiple filters chained in an AND condition:
'enable_captcha' => [ [ 'value' => true, 'filters' => ['env:production', 'expression_language:user==null'], ], ],
A feature with multiple filters chained in an OR condition:
'enable_captcha' => [ [ 'value' => true, 'filters' => ['expression_language:user==null'], ], [ 'value' => true, 'filters' => ['env:production'], ], ],
A feature with a negated filter:
'enable_debug_output' => [ [ 'value' => true, 'filters' => ['!env:production'], ], ],
Value configuration
The value configuration is stored in:
app/config/values.php
The value however is something which always returns a value (whoa) like a string or number for example:
'greeting' => [ [ 'value' => 'Hello my lady!', 'filters' => ['expression_language:user.getGender()=="female"'], ], [ 'value' => 'Hello sir.', ], ]
This name of the value is greeting. It should return "Hello my lady!" if the expression voter return true (assuming the given user is not NULL and it's gender is female). Otherwise it should return "Hello sir.".
(Sorry for the gender guessing)
(ExpressionVoter.php uses the Symfony Expression Language to check if the given expression is true)
Value configuration examples
A simple value without any filters :
'package_price' => [ [ 'value' => 10.00, ], ],
A value with one filter and a default value:
'package_price' => [ [ 'value' => 00.00, 'filters' => ['expression_language:user.hasPlan("premium")'], ], [ 'value' => 10.00, ], ],
A value with multiple filters chained in an AND condition and a default value:
'package_price' => [ [ 'value' => 5.00, 'filters' => ['expression_language:user.getRegisterDays() >= 365', 'made_at_least_one_purchase'], ], [ 'value' => 10.00, ], ],
Voters
The actual voters can be registered here:
app/config/judge.php
The voters contain the logic to decide whether the given filter should return true or false. This decides if either a feature is on or off or what a value should return regarding to it's config.
Adapters
By default, Judge uses the Laravel config to read the features/values. You can choose between the config, redis and cache adapter.
app/config/judge.php
If you want to add you own adapter, go for it. Just implement the AdapterInterface.
Usage
Within your controllers, you can use this for example...
$greeting = Value::decide('greeting', $this->getUser()); echo $greeting;
Or this:
if (Feature::decide('show_memory_usage', Auth::user())) { echo 'Memory usage: ' . memory_get_usage(); }
tbd
- Breakers
jlis/judge 适用场景与选型建议
jlis/judge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「feature」 「laravel」 「value」 「toggle」 「decision」 「featureflag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jlis/judge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jlis/judge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jlis/judge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
Runn Me! Value Objects Library
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.
Rinvex 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.
Provides Symfony param converters for mediagone/types-common package.
Rinvex 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.
统计信息
- 总下载量: 1.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-09