landingi/toggle-bundle

包含核心功能,帮助检查给定账户的功能

安装: 8,899

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 1

类型:symfony-bundle

v1.0.0 2021-04-01 12:00 UTC

This package is auto-updated.

Last update: 2024-09-12 10:26:14 UTC


README

Build Status

Toggle bundle

功能标志

检查账户是否启用了功能标志的系统。

FeatureFlagsSource

实现

  • Landingi\ToggleBundle\FeatureFlagsSource\DbSource - 应使用 Landingi 只读 DB 实例通过账户的 UUID 从 accounts_features 表中获取功能,通过账户的包从 packages_features 表中获取。

  • Landingi\ToggleBundle\FeatureFlagsSource\RedisSource - 通过账户的 UUID 作为键从缓存于 Redis 中的功能标志列表中获取。

  • Landingi\ToggleBundle\FeatureFlagsSource\CachingSource - 这个类是账户功能标志列表缓存的抽象。

配置

该包提供了一种配置,允许您轻松控制数据访问层。配置文件应创建在路径:config/packages/landingi_toggle.yaml

landingi_toggle:
    dbal:
        connection_name: mysql # DBAL connection name (this should be a read only connection, for a better performance)
    cache:
        enabled: true # If enabled then CachingSource is used, otherwise DbSource is used to fetch the feature flags
        redis_connection:
            schema: 'tcp'
            host: '%env(REDIS_HOST)%'
            port: 6379
        ttl: 60 # Time to live for cached feature flags entries for a selected account_uuid

用法

要检查选定账户_uuid 的功能标志访问,请按照以下代码片段操作

use Landingi\ToggleBundle\AccessVoter;

class ExampleService
{
    private AccessVoter $accessVoter;
 
    public function __construct(AccessVoter $accessVoter)
    {
        $this->accessVoter = $accessVoter;
    }
    
    public function exampleMethod(string $accountUuid)
    {
        /** ... some logic  */
        
        if ($this->accessVoter->vote($accountUuid, 'EXAMPLE_FEATURE_FLAG')) {
            // Access granted
        }
    }
}

AccessVoter 已在 symfony 依赖注入容器中定义,因此我们可以轻松地在整个项目的每个服务类中使用它作为依赖项。