open-feature / flagd-provider
The Flagd provider package for open-feature
Requires
- php: ^8
- open-feature/sdk: ^2.0
- php-http/httplug: ^2.3.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.25
- friendsofphp/php-cs-fixer: ^3.13
- hamcrest/hamcrest-php: ^2.0
- mdwheele/zalgo: ^0.3.1
- mockery/mockery: ^1.5
- phan/phan: ^5.4
- php-parallel-lint/php-console-highlighter: ^1.0
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ~1.10.0
- phpstan/phpstan-mockery: ^1.0
- phpstan/phpstan-phpunit: ^1.1
- psalm/plugin-mockery: ^0.11.0
- psalm/plugin-phpunit: ^0.18.0
- ramsey/coding-standard: ^2.0.3
- ramsey/composer-repl: ^1.4
- ramsey/conventional-commits: ^1.3
- roave/security-advisories: dev-latest
- spatie/phpunit-snapshot-assertions: ^4.2
- vimeo/psalm: ~4.30.0
README
Overview
Flagd is a simple command line tool for fetching and presenting feature flags to services. It is designed to conform to OpenFeature schema for flag definitions. This repository and package provides the client side code for interacting with it via the OpenFeature PHP SDK.
This package also builds on various PSRs (PHP Standards Recommendations) such as the Logger interfaces (PSR-3) and the Basic and Extended Coding Standards (PSR-1 and PSR-12).
Installation
composer require open-feature/flagd-provider
Usage
The FlagdProvider
client constructor takes a single optional argument with 3 fields, their default values correspond to the default arguments supplied to the flagd server:
/** @var \Psr\Http\Client\ClientInterface $client */ $client; /** @var Psr\Http\Message\RequestFactoryInterface $requestFactory */ $requestFactory; /** @var Psr\Http\Message\StreamFactoryInterface $streamFactory */ $streamFactory; OpenFeatureAPI::setProvider(new FlagdProvider([ 'protocol' => 'http', 'host' => 'localhost', 'port' => 8013, 'secure' => true, 'http' => [ 'client' => $client, 'requestFactory' => $requestFactory, 'streamFactory' => $streamFactory, ], ]));
- protocol: "http" (defaults to http)
- host: string (defaults to "localhost")
- port: number (defaults to 8013)
- secure: true | false (defaults to false)
- http: An array or
HttpConfig
object, providing implementations for PSR interfaces- client: a
ClientInterface
implementation - requestFactory: a
RequestFactoryInterface
implementation - streamFactory: a
StreamFactoryInterface
implementation
- client: a
gRPC vs HTTP
The Flagd server is gRPC but offers gRPC Web endpoints that can be accessed over HTTP. The latter is used by the current implementation of the Flagd provider, with future development planned to implement a gRPC native provider option. There are certain flexibilities around HTTP with PHP available, whereas gRPC is an opinionated code-generation strategy, but they are both useful and gRPC native may provide better performance over certain sync/async scenarios. An additional goal will be to provide benchmarking of the Flagd provider's protocol for various scenarios so this decision can be made more easily by consumers of the provider.
Development
PHP Versioning
This library targets PHP version and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK.
This package also has a .tool-versions
file for use with PHP version managers like asdf
.
Installation and Dependencies
Install dependencies with composer install
. composer install
will update the composer.lock
with the most recent compatible versions.
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
Testing
Run tests with composer run test
.