定制 clearlyip/laravel-flipt 二次开发

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

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

clearlyip/laravel-flipt

Composer 安装命令:

composer require clearlyip/laravel-flipt

包简介

A Flipt client for Laravel

README 文档

README

Laravel-flipt was created by, and is maintained by Andrew Nagy, the package is designed to allow Laravel to work with Flipt

Total Downloads Latest Stable Version License

Features

  • Registers as a driver for Laravel Pennant
  • Registers a Flipt client class to access the API directly
  • Utilizes Laravel's cache system to store flags in cache for quick access with configurable TTL
  • Supports boolean and variant flag evaluation
  • Supports batch evaluation via the clientevaluation API
  • Provides access to Flipt's Environments, Flags, Evaluate, OpenFeature, and Internal APIs
  • Ships with Artisan commands to clear flag caches globally or per user

Installation & Usage

Requires PHP 8.4+

Require Laravel-flipt using Composer:

composer require clearlyip/laravel-flipt

Laravel Version Compatibility

Laravel Laravel Flipt
12.x 1.x
12.x, 13.x 2.x

Usage

Configuration Files

Publish the Laravel Flipt configuration file using the vendor:publish Artisan command. The flipt configuration file will be placed in your config directory (use --force to overwrite an existing config file):

php artisan vendor:publish --tag="flipt" [--force]

All options are fully documented in the published configuration file.

Key environment variables:

Variable Default Description
FLIPT_HOST null The Flipt API host URL
FLIPT_NAMESPACE null The Flipt namespace
FLIPT_ENVIRONMENT local The Flipt environment

Pennant

Register the driver for Laravel Pennant in the pennant.php configuration file:

'default' => env('PENNANT_STORE', 'flipt'),
'stores' => [
    'array' => [
        'driver' => 'array',
    ],

    'flipt' => [
        'driver' => 'flipt',
    ],
],

User Identity

Use the hasFeatures trait on your User model.

Configure what parameters to use for entityId and context in the flipt configuration file. Dot notation is supported for nested model attributes:

'identity' => [
    'identifier' => 'id',
    'context' => [
        'email' => 'email',
        'my-value' => 'dot.notation.is.supported',
    ],
],

Accessing the Flipt Client

The Flipt class can be resolved through Laravel's service container:

use Clearlyip\LaravelFlipt\Flipt;

$flipt = App::make(Flipt::class);

The client exposes the following API modules as magic properties:

Property Class Description
$flipt->evaluate Flipt\Evaluate Boolean and variant flag evaluation
$flipt->clientevaluation Flipt\ClientEvaluation Batch/client-side evaluation
$flipt->openfeature Flipt\OpenFeature OpenFeature-compatible evaluation
$flipt->environments Flipt\Environments Manage Flipt environments
$flipt->flags Flipt\Flags List and retrieve flag definitions
$flipt->internal Flipt\Internal Internal Flipt API access

Disabling the Cache

To skip the cache for a single call chain, use withSkipCache():

$flipt->withSkipCache()->evaluate->boolean($request);

Artisan Commands

Command Description
php artisan flipt:cache:clear Clear all cached Flipt flag responses
php artisan flipt:cache:user:clear {userId} Clear cached flags for a specific user

Caching

The package uses Laravel's cache system to cache Flipt API responses. Configure the cache behavior in config/flipt.php:

'cache' => [
    'store'  => env('FLIPT_CACHE_STORE', 'default'),
    'prefix' => env('FLIPT_CACHE_PREFIX', 'flipt'),
    'ttl'    => env('FLIPT_CACHE_TTL', 60),
    'tags'   => ['flipt'],
],

The cache store must support tagging (e.g., Redis, Memcached) for the cache-clearing commands to work correctly.

Contributing

Contributions are welcome. Please open an issue or pull request on GitHub.

License

Laravel-flipt is open-sourced software licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-10-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固