承接 jkbennemann/laravel-features 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jkbennemann/laravel-features

Composer 安装命令:

composer require jkbennemann/laravel-features

包简介

The package provides a convenient way to introduce new functionalities into your application by simply switching them on or off or granting access only to specific groups of users.

README 文档

README

This packages provides a simple to use possibility to introduce functionality (features) to specific users or groups of users (parties).

This concept is also known as FeatureFlags or FeatureToggles.

Installation

You can install the package via composer:

composer require jkbennemann/laravel-features

After you have installed the package run the following command start the installation routine

#Interactive installation
php artisan feature:install

#Command if you are using uuids for your model
php artisan feature:install --uuid

#Command if you are using unsigned big integer (id)
php artisan feature:install --id

Last steps

Migrate database files

php artisan migrate

Adding HasFeatures trait to your User model

//..
use Jkbennemann\Features\Models\Traits\HasFeatures;

class User extends Model
{
    use HasFeatures;
    //..
}

After these steps you're good to go.

Common Use-Cases

1. A/B testing

  1. Add you features which should be tested
  2. Create two parties and add users to them
  3. Assign features to the parties or single users

2. A group of Beta-Testers

  1. Add you features which should be beta-tested
  2. Create a new party fpr you beta-testers
  3. Assign the users to that party

3. Preparation for an upcoming feature

  1. Add a new feature which should be INACTIVE for now
  2. Complete development and optionally create a special group for users e.g.
    developers that should still be able to access that new feature
  3. Extend that feature to beta-testers or remove feature-switch

4. Functionality for specific users like administrators

  1. Create a new party for administrators
  2. Assign all features which should be explicitly available for them to that party
  3. Add all relevant users to that party.

Usage

use \Jkbennemann\Features\Models\Enums\FeatureStatus;
use \Jkbennemann\Features\Models\Feature;

$feature = Features::create([
    'name' => 'Functionality A',
    'description' => 'This is a new feature', //optional
    'status' => FeatureStatus::ACTIVE //optional, defaults to INACTIVE
]);

$party = Party::create([
    'name' => 'Beta Testers',
    'description' => 'This is a new party', //optional
    'status' => FeatureStatus::ACTIVE //optional, defaults to INACTIVE
]);

$feature->activate();       //activates a feature
$feature->deactivate();     //deactivates a feature

$party->addFeature($feature);       //assigns a feature to a party
$party->removeFeature($feature);    //removes a feature from a party

$active = $user->hasFeature($feature);        //user has the feature which is active
$active = $user->hasFeature('feature-slug');  //you may provide the slug of a feature
$active = $user->hasFeature('feature-slug', false); //provide false ignore the check for active features
$active = $user->hasFeatureThroughParty('feature-slug');    //checks if a feature is granted through a party

$features = $user->allFeatures();   //returns all features
$features = $user->allFeatures(false);   //returns all features without checking the status

$user->giveFeature('feature-slug');     //add specific feature to a user
$user->removeFeature('feature-slug');   //remove specific feature

$user->joinParty('party-slug');     //add a user to a party
$user->addToParty('party-slug');    //add a user to a party
$user->leaveParty('party-slug');    //remove a user from a party

$user->belongsToParty('party-slug');    //checks if the user belongs to the party
$user->inParty('party-slug');           //checks if the user belongs to the party

Commands

# Create a new feature/party
php artisan feature:add {name} {description?} {--status}
php artisan party:add {name} {description?} {--status}

# List features/parties
php artisan feature:list
php artisan party:list

# Activate a feature/party
php artisan feature:activate {id|slug}
php artisan party:activate {id|slug}

# Deactivate a feature/party
php artisan feature:deactivate {id|slug}
php artisan party:deactivate {id|slug}

Gates

# Check feature
$user->can('feature-slug');   //allows to check using laravel gates
$user->can('feature-slug', true);    //validates if feature is ACTIVE
$user->can('feature-slug', false);    //ignores status of feature

Ideas

  • Blade directives for @feature, @party
  • Command to update feature status
  • Gate support
  • Support for UUIDs for User model
  • Support can() method to use accept a Feature model
  • Middleware to secure requests for features/parties
  • Feature expiration to tackle carying costs
  • Management for Parties/Features using Livewire

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Feel free to make suggestions of features or contribute by creating a Pull Request.
Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

jkbennemann/laravel-features 适用场景与选型建议

jkbennemann/laravel-features 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「feature-toggles」 「jkbennemann」 「laravel-features」 「feature-switch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jkbennemann/laravel-features 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jkbennemann/laravel-features 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-06