{"id":14966471,"url":"https://github.com/xepozz/feature-flag","last_synced_at":"2026-02-07T21:32:40.025Z","repository":{"id":151856967,"uuid":"624962374","full_name":"xepozz/feature-flag","owner":"xepozz","description":"This is a simple library to enable/disable features based on a set of rules.","archived":false,"fork":false,"pushed_at":"2023-07-28T21:26:14.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-10T22:23:47.571Z","etag":null,"topics":["feature-flag","feature-flagging","feature-flags","ff","management","yii","yii3"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xepozz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-07T17:44:21.000Z","updated_at":"2024-05-13T07:08:03.000Z","dependencies_parsed_at":"2024-09-14T02:54:23.286Z","dependency_job_id":null,"html_url":"https://github.com/xepozz/feature-flag","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"2eb86918027d385de8a086d4b217f1c68543f758"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xepozz/feature-flag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Ffeature-flag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Ffeature-flag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Ffeature-flag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Ffeature-flag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xepozz","download_url":"https://codeload.github.com/xepozz/feature-flag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Ffeature-flag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29208712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T20:33:12.493Z","status":"ssl_error","status_checked_at":"2026-02-07T20:30:47.381Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feature-flag","feature-flagging","feature-flags","ff","management","yii","yii3"],"created_at":"2024-09-24T13:36:25.936Z","updated_at":"2026-02-07T21:32:40.011Z","avatar_url":"https://github.com/xepozz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Feature Flag\n\nThis is a simple library to enable/disable features based on a set of rules.\n\n[![Latest Stable Version](https://poser.pugx.org/xepozz/feature-flag/v/stable.svg)](https://packagist.org/packages/xepozz/feature-flag)\n[![Total Downloads](https://poser.pugx.org/xepozz/feature-flag/downloads.svg)](https://packagist.org/packages/xepozz/feature-flag)\n[![phpunit](https://github.com/xepozz/feature-flag/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/feature-flag/actions)\n[![codecov](https://codecov.io/gh/xepozz/feature-flag/branch/master/graph/badge.svg?token=UREXAOUHTJ)](https://codecov.io/gh/xepozz/feature-flag)\n[![type-coverage](https://shepherd.dev/github/xepozz/feature-flag/coverage.svg)](https://shepherd.dev/github/xepozz/feature-flag)\n\n## Installation\n\n```shell\ncomposer require xepozz/feature-flag\n```\n\n## Configuration\n\nChoose the driver you want to use. Currently, the library supports the following drivers:\n- [InMemory](src/Driver/InMemoryDriver.php) - stores data in memory. This driver is used by default.\n- [Redis](src/Driver/RedisDriver.php) - stores data in Redis. Uses [phpredis extension](https://github.com/phpredis/phpredis#installation)\n\n### InMemory\n\nConfigure the driver in the dependency injection container configuration file:\n\n`di.php`\n```php\n\\Xepozz\\FeatureFlag\\Driver\\InMemoryDriver::class =\u003e [\n    '__construct()' =\u003e [\n        'flags' =\u003e [\n            155 =\u003e false,\n            'feature_name' =\u003e true,\n            FeaturesEnum::FEATURE_NAME =\u003e true,\n        ],\n    ],\n],\n```\n\nOr with `params.php`:\n\n```php\n'xepozz/feature-flag' =\u003e [\n    'flags' =\u003e [\n        155 =\u003e false,\n        'feature_name' =\u003e true,\n        FeaturesEnum::FEATURE_NAME =\u003e true,\n    ],\n],\n```\n\n\u003e Configuring the driver with `params.php` is only available for the `InMemoryDriver`.\n\n### Redis\n\nConfigure the driver in the dependency injection container configuration file:\n\n`di.php`\n```php\n\\Xepozz\\FeatureFlag\\Driver\\RedisDriver::class =\u003e function () {\n    $redis = new Redis();\n    $redis-\u003epconnect(\n        host: '127.0.0.1',\n        port: 6379,\n        timeout: 2.5,\n    );\n\n    return new \\Xepozz\\FeatureFlag\\Driver\\RedisDriver(redis: $redis, hashTableKey: 'ab');\n},\n```\n\nThe driver uses a hash table functions to store and retrieve data.\nRead more about the hash table functions [here](https://redis.io/commands/?group=hash).\n\n### Choose a driver\n\nAfter you have chosen a driver, you need to configure the dependency injection container:\n\n`di.php`\n\n```php\nuse Xepozz\\FeatureFlag\\FlagStorageInterface;\nuse \\Xepozz\\FeatureFlag\\Driver\\RedisDriver;\n\nreturn [\n    // ...\n    FlagStorageInterface::class =\u003e RedisDriver::class,\n    // ...\n]\n````\n\n## Usage\n\nPull `\\Xepozz\\FeatureFlag\\FlagStorageInterface` from the dependency injection container and use it:\n\n### `isActive(string|int|BackedEnum $flag): bool`\n\n```php\nuse Xepozz\\FeatureFlag\\FlagStorageInterface;\n\nclass Controller\n{\n    public function index(FlagStorageInterface $flagStorage)\n    {\n        if ($flagStorage-\u003eisActive('feature_name')) {\n            // feature is enabled\n        } else {\n            // feature is disabled\n        }\n    }\n}\n```\n\n### `setFlag(string|int|BackedEnum $flag, bool $active): void`\n\n\u003e Be careful, in case of using not the `InMemoryDriver`, the flag will be stored permanently.\n\n\u003e In case of using the `InMemoryDriver`, the flag will be stored only for the current request. \n\u003e So you can switch the flag depending on the conditions in your code. \n\u003e For instance, you can enable the feature only for trusted IP addresses.\n\n```php\nuse Xepozz\\FeatureFlag\\FlagStorageInterface;\n\nclass Controller\n{\n    public function index(FlagStorageInterface $flagStorage)\n    {\n        if ($condition) {\n            $flagStorage-\u003esetFlag('feature_name', true);\n        }\n    }\n}\n```\n\n### `getAll(): array`\n\nReturns all flags as an associative array `array\u003cstring, bool\u003e`. \n\nThe only `InMemoryDriver` supports returning `BackendEnum` as a key, because it does not need to serialize the key.\n\nThe key is the flag name, the value is the flag state.\n\n```php\nuse Xepozz\\FeatureFlag\\FlagStorageInterface;\n\nclass Controller\n{\n    public function index(FlagStorageInterface $flagStorage)\n    {\n        $flags = $flagStorage-\u003egetAll();\n        // ...\n    }\n}\n```\n\n## Testing\n\n#### Redis\n\nRedis driver requires [phpredis extension](https://github.com/phpredis/phpredis) and a running Redis server. \n\nYou can use the following command to start a Redis server in a Docker container:\n\n```shell\ndocker run --rm -p 6379:6379 redis\n```\n\nOr use docker-compose:\n\n```shell\ndocker-compose up -d\n```\n\n### Run tests:\n\n```shell\ncomposer test\n```\nOr\n```shell\n./vendor/bin/phpunit\n```\n\n## Looking for more modules?\n\n- [Unique ID](https://github.com/xepozz/unique-id) - Allows you to track the unique user in the application.\n- [Request ID](https://github.com/xepozz/request-id) - A simple library to generate both unique request and response IDs for tracing purposes.\n- [AB](https://github.com/xepozz/ab) - A simple library to enable A/B testing based on a set of rules.\n- [Shortcut](https://github.com/xepozz/shortcut) - Sets of helper functions for rapid development of Yii 3 applications.\n\n \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxepozz%2Ffeature-flag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxepozz%2Ffeature-flag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxepozz%2Ffeature-flag/lists"}