aubes / openfeature-configcat-bundle
Symfony bundle for the OpenFeature ConfigCat provider
Package info
github.com/aubes/openfeature-configcat-bundle
Type:symfony-bundle
pkg:composer/aubes/openfeature-configcat-bundle
Requires
- php: >=8.2
- configcat/openfeature-provider: ^1.0
- symfony/config: ^6.4|^7.4|^8.0
- symfony/dependency-injection: ^6.4|^7.4|^8.0
- symfony/http-kernel: ^6.4|^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
- rector/rector: ^2.4
- symfony/framework-bundle: ^6.4|^7.4|^8.0
Suggests
- guzzlehttp/guzzle: Required by configcat/configcat-client for HTTP requests when fetch_client is not configured (^7.0)
- nyholm/psr7: PSR-17 implementation needed when using Psr18FetchClient
- symfony/http-client: Use with Psr18FetchClient to replace Guzzle
README
Symfony bundle that registers the OpenFeature ConfigCat provider as a Symfony service.
ConfigCat in Symfony, one composer require away.
Requirements
- PHP 8.2+
- Symfony 6.4, 7.4 or 8.x
- Guzzle ^7.0 (required by
configcat/configcat-clientfor HTTP requests)
Installation
composer require aubes/openfeature-configcat-bundle
Note: Without a Symfony Flex recipe, register the bundle manually in
config/bundles.php:Aubes\OpenFeatureConfigCatBundle\OpenFeatureConfigCatBundle::class => ['all' => true],
Configuration
# config/packages/open_feature_configcat.yaml open_feature_config_cat: sdk_key: '%env(CONFIGCAT_SDK_KEY)%' # Optional settings base_url: ~ # custom ConfigCat CDN URL cache_refresh_interval: ~ # polling interval in seconds data_governance: ~ # "global" or "eu_only" offline: ~ # start in offline mode # Optional service references (Symfony service IDs) logger: ~ # PSR-3 LoggerInterface cache: ~ # ConfigCat\ConfigCache implementation (mutually exclusive with cache_pool) cache_pool: ~ # PSR-6 CacheItemPoolInterface, e.g. "cache.app" (mutually exclusive with cache) fetch_client: ~ # ConfigCat\Http\FetchClientInterface implementation # Flag overrides (optional, pick one type) flag_overrides: type: file # "file", "array", or "service" behaviour: local_only # "local_only", "local_over_remote", or "remote_over_local" path: ~ # JSON file path (type: file) # values: ~ # inline key/value map (type: array) # id: ~ # service ID of OverrideDataSource (type: service)
Usage
This bundle registers ConfigCatProvider as a lazy Symfony service. You can inject it directly:
use ConfigCat\OpenFeature\ConfigCatProvider; use OpenFeature\API; class MyService { public function __construct(private ConfigCatProvider $provider) { } public function doSomething(): void { $client = API::getInstance() ->withProvider($this->provider) ->getClient(); if ($client->getBooleanValue('dark_mode', false)) { // ... } } }
Using without Guzzle
By default, ConfigCat uses Guzzle for HTTP requests. If you prefer symfony/http-client (or any PSR-18 client), this bundle ships a Psr18FetchClient adapter:
# config/services.yaml services: Aubes\OpenFeatureConfigCatBundle\Http\Psr18FetchClient: arguments: $client: '@psr18.http_client' $requestFactory: '@Psr\Http\Message\RequestFactoryInterface' # config/packages/open_feature_configcat.yaml open_feature_config_cat: sdk_key: '%env(CONFIGCAT_SDK_KEY)%' fetch_client: Aubes\OpenFeatureConfigCatBundle\Http\Psr18FetchClient
This requires symfony/http-client and a PSR-17 implementation (e.g. nyholm/psr7).
License
MIT. See LICENSE.