Symfony bundle that registers the OpenFeature ConfigCat provider as a Symfony service.
ConfigCat in Symfony, one composer require away.
- PHP 8.2+
- Symfony 6.4, 7.4 or 8.x
- Guzzle ^7.0 (required by
configcat/configcat-clientfor HTTP requests)
composer require aubes/openfeature-configcat-bundleNote: Without a Symfony Flex recipe, register the bundle manually in
config/bundles.php:Aubes\OpenFeatureConfigCatBundle\OpenFeatureConfigCatBundle::class => ['all' => true],
# 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)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)) {
// ...
}
}
}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\Psr18FetchClientThis requires symfony/http-client and a PSR-17 implementation (e.g. nyholm/psr7).
MIT. See LICENSE.