定制 letflow/laravel-feature-toggle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

letflow/laravel-feature-toggle

Composer 安装命令:

composer require letflow/laravel-feature-toggle

包简介

Simple feature toggles for Laravel PHP and Javascript

README 文档

README

This package allows for easy and efficient feature flag managment in Laravel. Features include:

  • Definition of feature toggles per environment (e.g. local, dev, stage, production).
  • Managable way to keep flags in source control without becomming overwhelming.
  • Creation of a default setting per feature that will be used if the environment specific setting is not found.
  • Ability to easily request the status of a feature and automatically get the correct setting based on the current environment the application is running on.
  • Ability to tag features as eligable for Javascript export.
  • A helper method to easily export Javascript eligable feature flags and pass them along to your front-end framework.

Installation

Add the package to your project:

composer require letflow/laravel-feature-flag

If using Laravel lower than 5.5 add the following service provider:

// config/app.php

'providers' => [
    ...
    Kirschbaum\LaravelFeatureFlag\ServiceProvider::class,
    ...
];

This package also comes with a facade, making it easy to retrieve the correct flags for the environment you are in:

// config/app.php

'aliases' => [
    ...
    'FeatureFlag' => Kirschbaum\LaravelFeatureFlag\Facades\FeatureFlag::class,
    ...
]

Publish the config file using the arisan command:

php artisan vendor:publish --provider="Kirschbaum\LaravelFeatureFlag\ServiceProvider"

The configuration looks like this:

<?php

return [

    'feature-1' => [
        'value' => env('TOGGLE_FEATURE_1', false),
        'js_export'    => true,
    ],

    'feature-2' => [
        'cookie_override' => true,
        'js_export'      => true,
    ],

];

Usage

General PHP use:

if(FeatureFlag::isEnabled('feature-1'))
{
    // Only do stuff if feature is enabled.
}

If you need to pass your feature flags to a front-end JS framework like Angular or Vue.js, you can do so by using the getJavascriptFlags() method:

$js->put(
            [
                'pusher_public_key' => env('PUSHER_PUBLIC'),
                'feature_flags'     => FeatureFlag::getJavascriptFlags()
            ]
        );

Because not all feature flags should be passed to the front-end, only features with the setting 'js_export = true' will be included. The end result is a simple array of features with the correct flags for the environment:

array:2 [▼
  "feature-1" => true
  "feature-2" => false
]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固