aubes / openfeature-flagd-bundle
Symfony bundle for the OpenFeature Flagd provider
Package info
github.com/aubes/openfeature-flagd-bundle
Type:symfony-bundle
pkg:composer/aubes/openfeature-flagd-bundle
Requires
- php: >=8.2
- open-feature/flagd-provider: ^1.1
- 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
- rector/rector: ^2.4
- symfony/framework-bundle: ^6.4|^7.4|^8.0
Suggests
- nyholm/psr7: Provides Psr\Http\Message\RequestFactoryInterface and StreamFactoryInterface implementations
- symfony/http-client: Provides a Psr\Http\Client\ClientInterface implementation
README
Symfony bundle that registers the OpenFeature Flagd provider as a Symfony service.
Flagd in Symfony, one composer require away.
Requirements
- PHP 8.2+
- Symfony 6.4, 7.4 or 8.x
- A PSR-18 HTTP client (e.g.
symfony/http-client,guzzlehttp/guzzle) and PSR-17 factories (e.g.nyholm/psr7) - A running flagd server
Installation
composer require aubes/openfeature-flagd-bundle symfony/http-client nyholm/psr7
Note: Without a Symfony Flex recipe, register the bundle manually in
config/bundles.php:Aubes\OpenFeatureFlagdBundle\OpenFeatureFlagdBundle::class => ['all' => true],
Configuration
# config/packages/open_feature_flagd.yaml open_feature_flagd: host: '%env(FLAGD_HOST)%' # default: localhost port: 8013 # default: 8013 protocol: http # default: http (http or grpc) secure: false # default: false # PSR-18 client service ID (default: Psr\Http\Client\ClientInterface). # Use this to wire a scoped or custom HTTP client (base URI, timeouts, retry, logging...). http_client: ~
Custom HTTP client
By default, the bundle references the autowired Psr\Http\Client\ClientInterface. To use a scoped Symfony HTTP client:
# config/packages/framework.yaml framework: http_client: scoped_clients: flagd.client: base_uri: '%env(FLAGD_URL)%' timeout: 2 max_duration: 5
# config/packages/open_feature_flagd.yaml open_feature_flagd: host: flagd http_client: flagd.client
Usage
Inject the provider directly
This bundle registers FlagdProvider as a Symfony service. You can inject it directly and use the OpenFeature API:
use OpenFeature\OpenFeatureAPI; use OpenFeature\Providers\Flagd\FlagdProvider; class MyService { public function __construct(private FlagdProvider $provider) { } public function doSomething(): void { $client = OpenFeatureAPI::getInstance() ->setProvider($this->provider) ->getClient(); if ($client->getBooleanValue('dark_mode', false)) { // ... } } }
Pair with aubes/openfeature-bundle (optional)
If you want framework-level sugar on top of the OpenFeature SDK (#[FeatureFlag] / #[FeatureGate] attributes, Twig helpers, request-scoped evaluation context, profiler integration), install aubes/openfeature-bundle alongside and point it at this provider:
# config/packages/open_feature.yaml open_feature: provider: OpenFeature\Providers\Flagd\FlagdProvider
It's entirely optional: this bundle works fine on its own with the plain OpenFeature SDK.
License
MIT. See LICENSE.