定制 beacon-hq/pennant-driver 二次开发

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

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

beacon-hq/pennant-driver

Composer 安装命令:

composer require beacon-hq/pennant-driver

包简介

The official Beacon driver for Laravel Pennant

README 文档

README

The official Beacon driver for Laravel Pennant, enabling seamless feature flag management through the Beacon platform.

Full Documentation

Installation

You can install the package via Composer:

composer require beacon-hq/pennant-driver

The package will automatically register its service provider through Laravel's package auto-discovery.

Configuration

Environment Variables

Add the following environment variables to your .env file:

BEACON_API_URL=https://your-beacon-instance.com
BEACON_API_TOKEN=your-api-token
BEACON_APP_NAME=YourAppName
BEACON_API_PATH_PREFIX=/api
BEACON_API_TIMEOUT=3000 # in milliseconds

Pennant Configuration

Update your config/pennant.php file to include the Beacon driver:

<?php

return [
    'default' => env('PENNANT_STORE', 'beacon'),

    'stores' => [
        'beacon' => [
            'driver' => 'beacon',
            'app_name' => env('BEACON_APP_NAME', env('APP_NAME', 'Laravel')),
            'environment' => env('BEACON_ENVIRONMENT', env('APP_ENV', 'local')),
            'url' => env('BEACON_API_URL', 'https://api.beaconhq.io/'),
            'path_prefix' => env('BEACON_API_PATH_PREFIX', '/api'),
            'cache_store' => env('BEACON_CACHE_STORE', config('cache.default', 'array')),
            'cache_ttl' => env('BEACON_CACHE_TTL', 1800),
            'api_key' => env('BEACON_ACCESS_TOKEN'),
            'api_timeout' => env('BEACON_API_TIMEOUT', 3000),
        ],
    ],
];

Configuration Options

  • app_name: The name of your application as registered in Beacon
  • environment: The environment name (e.g., production, staging, local)
  • url: The base URL of your Beacon API instance
  • path_prefix: The API path prefix (default: /api)
  • cache_store: The cache store to use (default: Laravel's default cache store)
  • cache_ttl: Cache time-to-live in seconds (default: 1800 seconds / 30 minutes)
  • api_key: Your Beacon API authentication token
  • api_timeout: Beacon API request timeout, (recommended: no less than 100ms no greater than 3000ms)

Usage

Once configured, you can use Laravel Pennant's standard API to interact with feature flags:

Basic Feature Checking

use Laravel\Pennant\Feature;

// Check if a feature is active
if (Feature::active('new-dashboard')) {
    // Show new dashboard
}

// Check if a feature is inactive
if (Feature::inactive('legacy-feature')) {
    // Hide legacy feature
}

Scoped Features

use Laravel\Pennant\Feature;

// Check feature for a specific user
$user = auth()->user();
if (Feature::for($user)->active('premium-features')) {
    // Show premium features
}

// Check feature for a team
$team = $user->team;
if (Feature::for($team)->active('team-collaboration')) {
    // Enable team collaboration features
}

Retrieving Feature Values

use Laravel\Pennant\Feature;

// Get feature value (boolean, string, array, etc.)
$config = Feature::value('feature-config');

Conditional Execution

use Laravel\Pennant\Feature;

// Execute code when feature is active
Feature::when('new-feature', function () {
    // Code to run when feature is active
}, function () {
    // Code to run when feature is inactive (optional)
});

Context Information

The Beacon driver automatically sends contextual information with each request:

  • Scope Type: The class name of the scoped object (e.g., User, Team)
  • Scope: The actual scope object or identifier
  • App Name: Your application name
  • Environment: Current Laravel environment
  • Session ID: Current session identifier (if available)
  • IP Address: Client IP address
  • User Agent: Client user agent string
  • Referrer: HTTP referrer header
  • URL: Current request URL
  • Method: HTTP request method

This context helps Beacon make intelligent feature flag decisions based on your application's state.

Caching

The driver includes built-in caching to improve performance:

  • Feature responses are cached for the configured TTL (default: 30 minutes)
  • Cache keys are generated based on feature names and scope serialization
  • You can flush the cache using the driver's flushCache() method

Testing

Run the test suite:

composer test

Run code style checks:

composer lint

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0 or higher
  • Laravel Pennant 1.14 or higher

License

This package is open-sourced software licensed under the MIT license.

Credits

Support

For support, please contact Beacon HQ or open an issue on GitHub.

beacon-hq/pennant-driver 适用场景与选型建议

beacon-hq/pennant-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 946 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 beacon-hq/pennant-driver 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-04