Skip to content

Commit 4ba0033

Browse files
authoredSep 3, 2024··
feat: new GO Feature Flag PHP provider (#106)
* Exclude jetbrains IDE folder from GIT Signed-off-by: Thomas Poignant <[email protected]> * Goff PHP Provider initial commit Signed-off-by: Thomas Poignant <[email protected]> * fix linter issue Signed-off-by: Thomas Poignant <[email protected]> * fix linter issue Signed-off-by: Thomas Poignant <[email protected]> * removing phpcs cache file Signed-off-by: Thomas Poignant <[email protected]> * Adding phpcs file to gitignore Signed-off-by: Thomas Poignant <[email protected]> * Fix typo Signed-off-by: Thomas Poignant <[email protected]> --------- Signed-off-by: Thomas Poignant <[email protected]> Signed-off-by: Thomas Poignant <[email protected]>

31 files changed

+2206
-1
lines changed
 

Diff for: ‎.github/workflows/php-ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- hooks/Validators
2020
- providers/Flagd
2121
- providers/Split
22+
- providers/GoFeatureFlag
2223
# - providers/CloudBees
2324
fail-fast: false
2425

Diff for: ‎.github/workflows/split_monorepo.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,17 @@ jobs:
8787
targetRepo: split-provider
8888
targetBranch: refs/tags/${{ github.event.release.tag_name }}
8989
filterArguments: '--subdirectory-filter providers/Split/ --force'
90+
91+
split-provider-go-feature-flag:
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: checkout
95+
run: git clone "$GITHUB_SERVER_URL"/"$GITHUB_REPOSITORY" "$GITHUB_WORKSPACE" && cd "$GITHUB_WORKSPACE" && git checkout "$GITHUB_SHA"
96+
- name: push-provider-split
97+
uses: tcarrio/git-filter-repo-docker-action@v1
98+
with:
99+
privateKey: ${{ secrets.SSH_PRIVATE_KEY }}
100+
targetOrg: open-feature-php
101+
targetRepo: go-feature-flag-provider
102+
targetBranch: refs/tags/${{ github.event.release.tag_name }}
103+
filterArguments: '--subdirectory-filter providers/GoFeatureFlag/ --force'

Diff for: ‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ composer.lock
88

99
/proto/
1010

11-
/.devenv*
11+
/.devenv*
12+
13+
.idea/

Diff for: ‎providers/GoFeatureFlag/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/composer.lock
2+
/vendor
3+
/build
4+
5+
.php-cs-fixer.cache

Diff for: ‎providers/GoFeatureFlag/README.md

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<p align="center">
2+
<img width="400" src="https://raw.githubusercontent.com/thomaspoignant/go-feature-flag/main/gofeatureflag.svg" alt="go-feature-flag logo" />
3+
4+
</p>
5+
6+
# GO Feature Flag - OpenFeature PHP provider
7+
<p align="center">
8+
<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>
9+
<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>
10+
<img alt="Packagist Version" src="https://img.shields.io/packagist/v/open-feature/go-feature-flag-provider?logo=php&color=blue">
11+
<a href="https://gofeatureflag.org/"><img src="https://img.shields.io/badge/%F0%9F%93%92-Website-blue" alt="Documentation"></a>
12+
<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>
13+
<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>
14+
</p>
15+
16+
This repository contains the official PHP OpenFeature provider for accessing your feature flags with [GO Feature Flag](https://gofeatureflag.org).
17+
18+
In conjunction with the [OpenFeature SDK](https://openfeature.dev/docs/reference/concepts/provider) you will be able
19+
to evaluate your feature flags in your Ruby applications.
20+
21+
For documentation related to flags management in GO Feature Flag,
22+
refer to the [GO Feature Flag documentation website](https://gofeatureflag.org/docs).
23+
24+
### Functionalities:
25+
- Manage the integration of the OpenFeature PHP SDK and GO Feature Flag relay-proxy.
26+
27+
## Dependency Setup
28+
29+
### Composer
30+
31+
```shell
32+
composer require open-feature/go-feature-flag-provider
33+
```
34+
## Getting started
35+
36+
### Initialize the provider
37+
38+
The `GoFeatureFlagProvider` takes a config object as parameter to be initialized.
39+
40+
The constructor of the config object has the following options:
41+
42+
| **Option** | **Description** |
43+
|-----------------|------------------------------------------------------------------------------------------------------------------|
44+
| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.<br />*(example: `https://relay.proxy.gofeatureflag.org/`)* |
45+
| `apiKey` | The token used to call the relay proxy. |
46+
| `customHeaders` | Any headers you want to add to call the relay-proxy. |
47+
| `httpclient` | The HTTP Client to use (if you want to use a custom one). _It has to be a `PSR-7` compliant implementation._ |
48+
49+
The only required option to create a `GoFeatureFlagProvider` is the URL _(`endpoint`)_ to your GO Feature Flag relay-proxy instance.
50+
51+
```php
52+
use OpenFeature\Providers\GoFeatureFlag\config\Config;
53+
use OpenFeature\Providers\GoFeatureFlag\GoFeatureFlagProvider;
54+
use OpenFeature\implementation\flags\MutableEvaluationContext;
55+
use OpenFeature\implementation\flags\Attributes;
56+
use OpenFeature\OpenFeatureAPI;
57+
58+
$config = new Config('http://gofeatureflag.org', 'my-api-key');
59+
$provider = new GoFeatureFlagProvider($config);
60+
61+
$api = OpenFeatureAPI::getInstance();
62+
$api->setProvider($provider);
63+
$client = $api->getClient();
64+
$evaluationContext = new MutableEvaluationContext(
65+
"214b796a-807b-4697-b3a3-42de0ec10a37",
66+
new Attributes(["email" => 'contact@gofeatureflag.org'])
67+
);
68+
69+
$value = $client->getBooleanDetails('integer_key', false, $evaluationContext);
70+
if ($value) {
71+
echo "The flag is enabled";
72+
} else {
73+
echo "The flag is disabled";
74+
}
75+
```
76+
77+
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.
78+
79+
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.
80+
81+
82+
### Evaluate a feature flag
83+
The client is used to retrieve values for the current `EvaluationContext`.
84+
For example, retrieving a boolean value for the flag **"my-flag"**:
85+
86+
```php
87+
$value = $client->getBooleanDetails('integer_key', false, $evaluationContext);
88+
if ($value) {
89+
echo "The flag is enabled";
90+
} else {
91+
echo "The flag is disabled";
92+
}
93+
```
94+
95+
GO Feature Flag supports different all OpenFeature supported types of feature flags, it means that you can use all the accessor directly
96+
```php
97+
// Bool
98+
$client->getBooleanDetails('my-flag-key', false, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
99+
$client->getBooleanValue('my-flag-key', false, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
100+
101+
// String
102+
$client->getStringDetails('my-flag-key', "default", new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
103+
$client->getStringValue('my-flag-key', "default", new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
104+
105+
// Integer
106+
$client->getIntegerDetails('my-flag-key', 1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
107+
$client->getIntegerValue('my-flag-key', 1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
108+
109+
// Float
110+
$client->getFloatDetails('my-flag-key', 1.1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
111+
$client->getFloatValue('my-flag-key', 1.1, new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
112+
113+
// Object
114+
$client->getObjectDetails('my-flag-key', ["default" => true], new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
115+
$client->getObjectValue('my-flag-key', ["default" => true], new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37"));
116+
```
117+
118+
## Features status
119+
120+
| Status | Feature | Description |
121+
|-------|-----------------|----------------------------------------------------------------------------|
122+
|| Flag evaluation | It is possible to evaluate all the type of flags |
123+
|| Caching | Mechanism is in place to refresh the cache in case of configuration change |
124+
|| Event Streaming | Not supported by the SDK |
125+
|| Logging | Not supported by the SDK |
126+
|| Flag Metadata | Not supported by the SDK |
127+
128+
129+
<sub>**Implemented**: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub>
130+
131+
## Contributing
132+
This project welcomes contributions from the community.
133+
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.
134+
135+
### PHP Versioning
136+
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.
137+
138+
This package also has a .tool-versions file for use with PHP version managers like asdf.
139+
140+
### Installation and Dependencies
141+
Install dependencies with `composer install`, it will update the `composer.lock` with the most recent compatible versions.
142+
143+
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
144+

Diff for: ‎providers/GoFeatureFlag/composer.json

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"name": "open-feature/go-feature-flag-provider",
3+
"description": "The GO Feature Flag provider package for open-feature",
4+
"license": "Apache-2.0",
5+
"type": "library",
6+
"keywords": [
7+
"featureflags",
8+
"featureflagging",
9+
"openfeature",
10+
"gofeatureflag",
11+
"provider"
12+
],
13+
"authors": [
14+
{
15+
"name": "Thomas Poignant",
16+
"homepage": "https://github.com/thomaspoignant/go-feature-flag"
17+
}
18+
],
19+
"require": {
20+
"php": "^8",
21+
"guzzlehttp/guzzle": "^7.9",
22+
"open-feature/sdk": "^2.0",
23+
"psr/http-message": "^2.0"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^9",
27+
"mockery/mockery": "^1.6",
28+
"spatie/phpunit-snapshot-assertions": "^4.2",
29+
"phan/phan": "^5.4",
30+
"php-parallel-lint/php-console-highlighter": "^1.0",
31+
"php-parallel-lint/php-parallel-lint": "^1.3",
32+
"phpstan/extension-installer": "^1.1",
33+
"phpstan/phpstan": "~1.10.0",
34+
"phpstan/phpstan-mockery": "^1.0",
35+
"phpstan/phpstan-phpunit": "^1.1",
36+
"psalm/plugin-mockery": "^0.11.0",
37+
"psalm/plugin-phpunit": "^0.18.0",
38+
"ramsey/coding-standard": "^2.0.3",
39+
"ramsey/composer-repl": "^1.4",
40+
"ramsey/conventional-commits": "^1.3",
41+
"roave/security-advisories": "dev-latest",
42+
"spatie/phpunit-snapshot-assertions": "^4.2",
43+
"vimeo/psalm": "~4.30.0"
44+
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true,
47+
"autoload": {
48+
"psr-4": {
49+
"OpenFeature\\Providers\\GoFeatureFlag\\": "src/"
50+
}
51+
},
52+
"autoload-dev": {
53+
"psr-4": {
54+
"OpenFeature\\Providers\\GoFeatureFlag\\Test\\": "tests/"
55+
}
56+
},
57+
"config": {
58+
"allow-plugins": {
59+
"phpstan/extension-installer": true,
60+
"dealerdirect/phpcodesniffer-composer-installer": true,
61+
"ergebnis/composer-normalize": true,
62+
"captainhook/plugin-composer": true,
63+
"ramsey/composer-repl": true
64+
},
65+
"sort-packages": true
66+
},
67+
"scripts": {
68+
"dev:analyze": [
69+
"@dev:analyze:phpstan",
70+
"@dev:analyze:psalm"
71+
],
72+
"dev:analyze:phpstan": "phpstan --ansi --debug --memory-limit=512M",
73+
"dev:analyze:psalm": "psalm",
74+
"dev:build:clean": "git clean -fX build/",
75+
"dev:lint": [
76+
"@dev:lint:syntax",
77+
"@dev:lint:style"
78+
],
79+
"dev:lint:fix": "phpcbf",
80+
"dev:lint:style": "phpcs --colors",
81+
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
82+
"dev:test": [
83+
"@dev:lint",
84+
"@dev:analyze",
85+
"@dev:test:unit",
86+
"@dev:test:integration"
87+
],
88+
"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",
89+
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
90+
"dev:test:unit": [
91+
"@dev:test:unit:setup",
92+
"phpunit --colors=always --testdox --testsuite=unit",
93+
"@dev:test:unit:teardown"
94+
],
95+
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
96+
"dev:test:unit:setup": "echo 'Setup for unit tests...'",
97+
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'",
98+
"dev:test:integration": [
99+
"@dev:test:integration:setup",
100+
"phpunit --colors=always --testdox --testsuite=integration",
101+
"@dev:test:integration:teardown"
102+
],
103+
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
104+
"dev:test:integration:setup": "echo 'Setup for integration tests...'",
105+
"dev:test:integration:teardown": "echo 'Tore down integration tests...'",
106+
"test": "@dev:test"
107+
},
108+
"scripts-descriptions": {
109+
"dev:analyze": "Runs all static analysis checks.",
110+
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
111+
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
112+
"dev:build:clean": "Cleans the build/ directory.",
113+
"dev:lint": "Runs all linting checks.",
114+
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
115+
"dev:lint:style": "Checks for coding standards issues.",
116+
"dev:lint:syntax": "Checks for syntax errors.",
117+
"dev:test": "Runs linting, static analysis, and unit tests.",
118+
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.",
119+
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.",
120+
"dev:test:unit": "Runs unit tests.",
121+
"test": "Runs linting, static analysis, and unit tests."
122+
}
123+
}

Diff for: ‎providers/GoFeatureFlag/phpcs.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
4+
<arg name="extensions" value="php"/>
5+
<arg name="colors"/>
6+
<arg value="sp"/>
7+
8+
<file>./src</file>
9+
<file>./tests</file>
10+
11+
<exclude-pattern>*/tests/fixtures/*</exclude-pattern>
12+
<exclude-pattern>*/tests/*/fixtures/*</exclude-pattern>
13+
14+
<rule ref="Ramsey">
15+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
16+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
17+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
18+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
19+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
20+
21+
<exclude name="Generic.Files.LineLength.TooLong"/>
22+
<exclude name="Generic.Commenting.Todo.TaskFound"/>
23+
</rule>
24+
25+
</ruleset>

Diff for: ‎providers/GoFeatureFlag/phpstan.neon.dist

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
tmpDir: ./build/cache/phpstan
3+
level: max
4+
paths:
5+
- ./src
6+
excludePaths:
7+
- */tests/fixtures/*
8+
- */tests/*/fixtures/*

Diff for: ‎providers/GoFeatureFlag/phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="./vendor/autoload.php"
5+
cacheResultFile="./build/cache/phpunit.result.cache"
6+
colors="true"
7+
verbose="true">
8+
9+
<testsuites>
10+
<testsuite name="unit">
11+
<directory>./tests/unit</directory>
12+
</testsuite>
13+
</testsuites>
14+
15+
<coverage processUncoveredFiles="true">
16+
<include>
17+
<directory suffix=".php">./src</directory>
18+
</include>
19+
</coverage>
20+
21+
<php>
22+
<ini name="date.timezone" value="UTC"/>
23+
</php>
24+
25+
</phpunit>

Diff for: ‎providers/GoFeatureFlag/psalm-baseline.xml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="3.9.5@0cfe565d0afbcd31eadcc281b9017b5692911661"/>

Diff for: ‎providers/GoFeatureFlag/psalm.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<psalm xmlns="https://getpsalm.org/schema/config"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
5+
errorLevel="1"
6+
cacheDirectory="./build/cache/psalm"
7+
errorBaseline="./psalm-baseline.xml">
8+
9+
<projectFiles>
10+
<directory name="./src"/>
11+
<ignoreFiles>
12+
<directory name="./tests"/>
13+
<directory name="./vendor"/>
14+
</ignoreFiles>
15+
</projectFiles>
16+
17+
</psalm>

0 commit comments

Comments
 (0)
Please sign in to comment.