jlis/judge 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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.

Build Status Scrutinizer Code Quality Code Coverage StyleCI SensioLabsInsight Total Downloads

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 jlis/judge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-09