-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Thomas Poignant <[email protected]>
- Loading branch information
1 parent
77d389d
commit aaa2577
Showing
28 changed files
with
2,065 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/composer.lock | ||
/vendor | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<p align="center"> | ||
<img width="400" src="https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/gofeatureflag.svg" alt="go-feature-flag logo" /> | ||
|
||
</p> | ||
|
||
# GO Feature Flag - OpenFeature PHP provider | ||
<p align="center"> | ||
<a href="https://packagist.org/packages/open-feature/go-feature-flag"><img src="https://img.shields.io/packagist/v/open-feature/go-feature-flag-provider?color=blue&logo=php" /></a> | ||
<a href="https://packagist.org/packages/open-feature/go-feature-flag"><img src="https://img.shields.io/packagist/dt/open-feature/go-feature-flag-provider?logo=php" /></a> | ||
<img alt="Packagist Version" src="https://img.shields.io/packagist/v/open-feature/go-feature-flag-provider?logo=php&color=blue"> | ||
<a href="https://gofeatureflag.org/"><img src="https://img.shields.io/badge/%F0%9F%93%92-Website-blue" alt="Documentation"></a> | ||
<a href="https://github.com/thomaspoignant/go-feature-flag/issues"><img src="https://img.shields.io/badge/%E2%9C%8F%EF%B8%8F-issues-red" alt="Issues"></a> | ||
<a href="https://gofeatureflag.org/slack"><img src="https://img.shields.io/badge/join-us%20on%20slack-gray.svg?longCache=true&logo=slack&colorB=green" alt="Join us on slack"></a> | ||
</p> | ||
|
||
This repository contains the official PHP OpenFeature provider for accessing your feature flags with [GO Feature Flag](https://gofeatureflag.org). | ||
|
||
In conjunction with the [OpenFeature SDK](https://openfeature.dev/docs/reference/concepts/provider) 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](https://gofeatureflag.org/docs). | ||
|
||
### Functionalities: | ||
- Manage the integration of the OpenFeature PHP SDK and GO Feature Flag relay-proxy. | ||
|
||
## Dependency Setup | ||
|
||
### Composer | ||
|
||
```shell | ||
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: | ||
|
||
| **Option** | **Description** | | ||
|-----------------|------------------------------------------------------------------------------------------------------------------| | ||
| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.<br />*(example: `https://relay.proxy.gofeatureflag.org/`)* | | ||
| `apiKey` | The token used to call the relay proxy. | | ||
| `customHeaders` | Any headers you want to add to call the relay-proxy. | | ||
|
||
The only required option to create a `GoFeatureFlagProvider` is the URL _(`endpoint`)_ to your GO Feature Flag relay-proxy instance. | ||
|
||
```php | ||
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" => "[email protected]"]) | ||
); | ||
|
||
$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"**: | ||
|
||
```php | ||
$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 | ||
```php | ||
// 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 | ||
|
||
| Status | Feature | Description | | ||
|-------|-----------------|----------------------------------------------------------------------------| | ||
| ✅ | Flag evaluation | It is possible to evaluate all the type of flags | | ||
| ❌ | Caching | Mechanism is in place to refresh the cache in case of configuration change | | ||
| ❌ | Event Streaming | Not supported by the SDK | | ||
| ❌ | Logging | Not supported by the SDK | | ||
| ❌ | Flag Metadata | Not supported by the SDK | | ||
|
||
|
||
<sub>**Implemented**: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub> | ||
|
||
## Contributing | ||
This project welcomes contributions from the community. | ||
If you're interested in contributing, see the [contributors' guide](https://github.com/thomaspoignant/go-feature-flag/blob/main/CONTRIBUTING.md) 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"name": "open-feature/go-feature-flag-provider", | ||
"description": "The GO Feature Flag provider package for open-feature", | ||
"license": "Apache-2.0", | ||
"type": "library", | ||
"keywords": [ | ||
"featureflags", | ||
"featureflagging", | ||
"openfeature", | ||
"gofeatureflag", | ||
"provider" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Thomas Poignant", | ||
"homepage": "https://github.com/thomaspoignant/go-feature-flag" | ||
} | ||
], | ||
"require": { | ||
"php": "^8", | ||
"open-feature/sdk": "^2.0", | ||
"guzzlehttp/guzzle": "^7.9" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9", | ||
"mockery/mockery": "^1.6", | ||
"spatie/phpunit-snapshot-assertions": "^4.2" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"psr-4": { | ||
"OpenFeature\\Providers\\GoFeatureFlag\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"OpenFeature\\Providers\\GoFeatureFlag\\Test\\": "tests/" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"phpstan/extension-installer": true, | ||
"dealerdirect/phpcodesniffer-composer-installer": true, | ||
"ergebnis/composer-normalize": true, | ||
"captainhook/plugin-composer": true, | ||
"ramsey/composer-repl": true | ||
}, | ||
"sort-packages": true | ||
}, | ||
"scripts": { | ||
"dev:analyze": [ | ||
"@dev:analyze:phpstan", | ||
"@dev:analyze:psalm" | ||
], | ||
"dev:analyze:phpstan": "phpstan analyse --ansi --debug --memory-limit=512M", | ||
"dev:analyze:psalm": "psalm", | ||
"dev:build:clean": "git clean -fX build/", | ||
"dev:lint": [ | ||
"@dev:lint:syntax", | ||
"@dev:lint:style" | ||
], | ||
"dev:lint:fix": "phpcbf", | ||
"dev:lint:style": "phpcs --colors", | ||
"dev:lint:syntax": "parallel-lint --colors src/ tests/", | ||
"dev:test": [ | ||
"@dev:lint", | ||
"@dev:analyze", | ||
"@dev:test:unit", | ||
"@dev:test:integration" | ||
], | ||
"dev:test:coverage:ci": "phpunit --colors=always --coverage-text --coverage-clover build/coverage/clover.xml --coverage-cobertura build/coverage/cobertura.xml --coverage-crap4j build/coverage/crap4j.xml --coverage-xml build/coverage/coverage-xml --log-junit build/junit.xml", | ||
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/", | ||
"dev:test:unit": [ | ||
"@dev:test:unit:setup", | ||
"phpunit --colors=always --testdox --testsuite=unit", | ||
"@dev:test:unit:teardown" | ||
], | ||
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on", | ||
"dev:test:unit:setup": "echo 'Setup for unit tests...'", | ||
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'", | ||
"dev:test:integration": [ | ||
"@dev:test:integration:setup", | ||
"phpunit --colors=always --testdox --testsuite=integration", | ||
"@dev:test:integration:teardown" | ||
], | ||
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on", | ||
"dev:test:integration:setup": "echo 'Setup for integration tests...'", | ||
"dev:test:integration:teardown": "echo 'Tore down integration tests...'", | ||
"test": "@dev:test" | ||
}, | ||
"scripts-descriptions": { | ||
"dev:analyze": "Runs all static analysis checks.", | ||
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.", | ||
"dev:analyze:psalm": "Runs the Psalm static analyzer.", | ||
"dev:build:clean": "Cleans the build/ directory.", | ||
"dev:lint": "Runs all linting checks.", | ||
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.", | ||
"dev:lint:style": "Checks for coding standards issues.", | ||
"dev:lint:syntax": "Checks for syntax errors.", | ||
"dev:test": "Runs linting, static analysis, and unit tests.", | ||
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.", | ||
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.", | ||
"dev:test:unit": "Runs unit tests.", | ||
"test": "Runs linting, static analysis, and unit tests." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
|
||
<arg name="extensions" value="php"/> | ||
<arg name="colors"/> | ||
<arg value="sp"/> | ||
|
||
<file>./src</file> | ||
<file>./tests</file> | ||
|
||
<exclude-pattern>*/tests/fixtures/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*/fixtures/*</exclude-pattern> | ||
|
||
<rule ref="Ramsey"> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/> | ||
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/> | ||
|
||
<exclude name="Generic.Files.LineLength.TooLong"/> | ||
<exclude name="Generic.Commenting.Todo.TaskFound"/> | ||
</rule> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
parameters: | ||
tmpDir: ./build/cache/phpstan | ||
level: max | ||
paths: | ||
- ./src | ||
- ./tests | ||
excludePaths: | ||
- */tests/fixtures/* | ||
- */tests/*/fixtures/* | ||
# TODO: Implement gRPC Completely | ||
- ./src/grpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="./vendor/autoload.php" | ||
cacheResultFile="./build/cache/phpunit.result.cache" | ||
colors="true" | ||
verbose="true"> | ||
|
||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>./tests/unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
|
||
<php> | ||
<ini name="date.timezone" value="UTC"/> | ||
</php> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="3.9.5@0cfe565d0afbcd31eadcc281b9017b5692911661"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<psalm xmlns="https://getpsalm.org/schema/config" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
errorLevel="1" | ||
cacheDirectory="./build/cache/psalm" | ||
errorBaseline="./psalm-baseline.xml"> | ||
|
||
<projectFiles> | ||
<directory name="./src"/> | ||
<ignoreFiles> | ||
<directory name="./tests"/> | ||
<directory name="./vendor"/> | ||
</ignoreFiles> | ||
</projectFiles> | ||
|
||
</psalm> |
Oops, something went wrong.