worksome/feature-flags

用于管理应用程序中特性标志的包

资助包维护!
worksome

4.0.0 2024-06-19 20:53 UTC

README

PHPStan Run Tests

用于管理应用程序中特性标志的包。目前支持以下提供者

安装

您可以通过composer安装此包

composer require worksome/feature-flags

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="feature-flags-config"

这是发布配置文件的内容

declare(strict_types=1);

use Worksome\FeatureFlags\ModelFeatureFlagConvertor;

// config for Worksome/FeatureFlags
return [
    'default' => env('FEATURE_FLAGS_PROVIDER', 'launchdarkly'),

    'convertor' => ModelFeatureFlagConvertor::class,

    'providers' => [
        'launchdarkly' => [
            'key' => env('LAUNCHDARKLY_SDK_KEY'),
            'options' => [
                /**
                 * https://docs.launchdarkly.com/sdk/features/offline-mode
                 */
                'offline' => env('LAUNCHDARKLY_OFFLINE', false)
            ],
            /**
             * @link https://docs.launchdarkly.com/home/account-security/api-access-tokens
             */
            'access-token' => env('FEATURE_FLAGS_API_ACCESS_TOKEN', null),
        ]
    ],

    /**
     * List of available overriders.
     * Key is to be used to specify which overrider should be active.
     */
    'overriders' => [
        'config' => [
            /**
             * Overrides all feature flags directly without hitting the provider.
             * This is particularly useful for running things in the CI,
             * e.g. Cypress tests.
             *
             * Be careful in setting a default value as said value will be applied to all flags.
             * Use `null` value if needing the key to be present but act as if it was not
             */
            'override-all' => null,

            /**
             * Override flags. If a feature flag is set inside an override,
             * it will be used instead of the flag set in the provider.
             *
             * Usage: ['feature-flag-key' => true]
             *
             * Be careful in setting a default value as it will be applied.
             * Use `null` value if needing the key to be present but act as if it was not
             *
             */
            'overrides' => [
                // ...
            ],
        ],
        'in-memory' => [
            // ...
        ]
    ],
];

创建特性标志

特性标志应使用一个或多个包含特性标志的枚举进行注册。

所有特性标志枚举都必须实现Worksome\FeatureFlags\Contracts\FeatureFlagEnum接口。

例如,如果您有一个名为flag-one的特性标志,您可以使用以下方式创建枚举

namespace App\Enums;

enum FeatureFlag: string implements \Worksome\FeatureFlags\Contracts\FeatureFlagEnum
{
    case FlagOne = 'flag-one';
}

在Blade中的使用

@feature(\App\Enums\FeatureFlag::FlagOne)
    This is content under a feature flag.
@endfeature

变更日志

请参阅发布记录以获取有关最近更改的更多信息。

测试

我们自豪于我们的详尽的测试套件和严格的静态分析。您可以通过composer脚本来运行所有的检查

composer test

为了使贡献变得极其容易,我们还提供了一个docker-compose文件,它会启动一个包含所有必要依赖的容器。假设您已安装docker,只需运行

docker-compose run --rm composer install # Only needed the first time
docker-compose run --rm composer test # Run tests and static analysis 

Docker镜像中内置了对XDebug的支持,您只需配置XDEBUG_MODE环境变量即可

docker-compose run --rm -e XDEBUG_MODE=debug php

安全漏洞

请参阅我们的安全策略了解如何报告安全漏洞。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件