ocus/laravel-launchdarkly 问题修复 & 功能扩展

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

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

ocus/laravel-launchdarkly

Composer 安装命令:

composer require ocus/laravel-launchdarkly

包简介

Wrap of the package launchdarkly/server-sdk for laravel.

README 文档

README

pipeline status coverage report

This package provides the LaunchDarkly PHP SDK in a Laravel ecosystem for an easy use with the framework. It in includes the facade to use it in your code. And in memory mock to help you in your tests.

Installation

You can install the package via composer:

composer require ocus/laravel-launchdarkly

You can publish the config file with:

php artisan vendor:publish --provider="Ocus\LaravelLaunchDarkly\LaravelLaunchDarklyServiceProvider" --tag="launchdarkly-config"

You can add in you .env file the LaunchDarkly SDK key

LAUNCH_DARKLY_SDK_KEY="sdk-<your-sdk-key>"

Usage

First to use it you have to implement the Ocus\LaravelLaunchDarkly\Contracts\IsLaunchDarklyUser interface in the model that you what tu use as a LaunchDarkly user.

/**
 * @return LDUser
 *
 * @see \LaunchDarkly\LDUserBuilder
 * @link https://docs.launchdarkly.com/sdk/features/user-config#php
 */
public function getLaunchDarklyUserAttribute(): \LaunchDarkly\LDUser
{
    return (new \LaunchDarkly\LDUserBuilder($this->getKey()))
        ->secondary(self::class)
        ->email($this->email)
        ->name($this->name)
        ->build();
}

In the code

use Ocus\LaravelLaunchDarkly\Facades\LaunchDarkly;

// Will return what you setup on your LaunchDarkly dashboard
LaunchDarkly::variation('your.flag.key', $user->launch_darkly_user);

In routes

You can use the launch-darkly middleware in your routes definition:

Route::middleware('launch-darkly:my-key,my-value')->get('/my-route', ...);

All value types are supported except json.

In the tests

use Ocus\LaravelLaunchDarkly\Facades\LaunchDarkly;

// Fake the LaunchDarkly feature requester with a in memory one
LaunchDarkly::fake();

// Add a value for a given flag key
LaunchDarkly::addFlagValue('your.flag.key', true);

// Will return true
LaunchDarkly::variation('your.flag.key', $user->launch_darkly_user);

Testing

composer test

License

The Apache License (Apache 2.0). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2021-12-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固