open-feature / go-feature-flag-provider
The GO Feature Flag provider package for open-feature
Requires
- php: ^8
- guzzlehttp/guzzle: ^7.9
- open-feature/sdk: ^2.0
- psr/http-message: ^2.0
Requires (Dev)
- mockery/mockery: ^1.6
- 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
- phpunit/phpunit: ^9
- 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
GO Feature Flag - OpenFeature PHP provider
This repository contains the official PHP OpenFeature provider for accessing your feature flags with GO Feature Flag.
In conjunction with the OpenFeature SDK you will be able to evaluate your feature flags in your Ruby applications.
For documentation related to flags management in GO Feature Flag, refer to the GO Feature Flag documentation website.
Functionalities:
- Manage the integration of the OpenFeature PHP SDK and GO Feature Flag relay-proxy.
Dependency Setup
Composer
composer require open-feature/go-feature-flag-provider
Getting started
Initialize the provider
The GoFeatureFlagProvider
takes a config object as parameter to be initialized.
The constructor of the config object has the following options:
The only required option to create a GoFeatureFlagProvider
is the URL (endpoint
) to your GO Feature Flag relay-proxy instance.
use OpenFeature\Providers\GoFeatureFlag\config\Config; use OpenFeature\Providers\GoFeatureFlag\GoFeatureFlagProvider; use OpenFeature\implementation\flags\MutableEvaluationContext; use OpenFeature\implementation\flags\Attributes; use OpenFeature\OpenFeatureAPI; $config = new Config('http://gofeatureflag.org', 'my-api-key'); $provider = new GoFeatureFlagProvider($config); $api = OpenFeatureAPI::getInstance(); $api->setProvider($provider); $client = $api->getClient(); $evaluationContext = new MutableEvaluationContext( "214b796a-807b-4697-b3a3-42de0ec10a37", new Attributes(["email" => 'contact@gofeatureflag.org']) ); $value = $client->getBooleanDetails('integer_key', false, $evaluationContext); if ($value) { echo "The flag is enabled"; } else { echo "The flag is disabled"; }
The evaluation context is the way for the client to specify contextual data that GO Feature Flag uses to evaluate the feature flags, it allows to define rules on the flag.
The targeting_key
is mandatory for GO Feature Flag to evaluate the feature flag, it could be the id of a user, a session ID or anything you find relevant to use as identifier during the evaluation.
Evaluate a feature flag
The client is used to retrieve values for the current EvaluationContext
.
For example, retrieving a boolean value for the flag "my-flag":
$value = $client->getBooleanDetails('integer_key', false, $evaluationContext); if ($value) { echo "The flag is enabled"; } else { echo "The flag is disabled"; }
GO Feature Flag supports different all OpenFeature supported types of feature flags, it means that you can use all the accessor directly
// Bool $client->getBooleanDetails('my-flag-key', false, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); $client->getBooleanValue('my-flag-key', false, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); // String $client->getStringDetails('my-flag-key', "default", new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); $client->getStringValue('my-flag-key', "default", new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); // Integer $client->getIntegerDetails('my-flag-key', 1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); $client->getIntegerValue('my-flag-key', 1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); // Float $client->getFloatDetails('my-flag-key', 1.1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); $client->getFloatValue('my-flag-key', 1.1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); // Object $client->getObjectDetails('my-flag-key', ["default" => true], new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37")); $client->getObjectValue('my-flag-key', ["default" => true], new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
Features status
Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌
Contributing
This project welcomes contributions from the community. If you're interested in contributing, see the contributors' guide for some helpful tips.
PHP Versioning
This library targets PHP version 8.0 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
, it 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.