Skip to content

feat: FlagsmithProvider #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4098a0b
Initial Flagsmith provider.
ChrisLightfootWild Mar 18, 2025
9615e1e
Added split config for Flagsmith.
ChrisLightfootWild Mar 18, 2025
9d23a4e
Flagsmith: added .gitattributes
ChrisLightfootWild Mar 19, 2025
6793ad3
Flagsmith: handle enabled/disabled state of flags.
ChrisLightfootWild Mar 19, 2025
9f09785
(ci) add Flagsmith to test matrix
ChrisLightfootWild Mar 23, 2025
0485e53
(feat) Flagsmith resolveObjectValue should expect flag value to be en…
ChrisLightfootWild Mar 23, 2025
e754566
(feat) Flagsmith resolveObjectValue should not call json_decode on de…
ChrisLightfootWild Mar 30, 2025
4bce148
(style) FlagsmithProvider linting
ChrisLightfootWild Mar 30, 2025
be6f4e2
(chore) remove unused Flagsmith dependencies
ChrisLightfootWild Mar 30, 2025
25eaa2a
(chore) fix FlagsmithProvider complaints
ChrisLightfootWild Mar 30, 2025
9d2c70e
(chore) fix FlagsmithProviderTest
ChrisLightfootWild Mar 30, 2025
2a8e686
(chore) bunp Flagsmith minimum PHP version to 8.1
ChrisLightfootWild Mar 31, 2025
1d9187e
(style) fix Flagsmith TestOfflineHandler
ChrisLightfootWild Mar 31, 2025
e0bf3b6
(test) added resolveBooleanValue tests to FlagsmithProvider
ChrisLightfootWild Mar 31, 2025
381b541
(test) added resolveStringValue tests to FlagsmithProvider
ChrisLightfootWild Mar 31, 2025
945fb94
(style) fix FlagsmithProviderTest trailing comma
ChrisLightfootWild Mar 31, 2025
a33f93c
(test) added resolveIntegerValue tests to FlagsmithProvider
ChrisLightfootWild Mar 31, 2025
9b8b892
(test) added resolveFloatValue tests to FlagsmithProvider
ChrisLightfootWild Mar 31, 2025
f10470c
(test) added resolveObjectValue tests to FlagsmithProvider
ChrisLightfootWild Mar 31, 2025
2c931b3
Update providers/Flagsmith/src/FlagsmithProvider.php
ChrisLightfootWild Apr 22, 2025
69de543
chore(deps) updated flagsmith/flagsmith-php-client for FlagsmithProvider
ChrisLightfootWild Apr 22, 2025
3f6fdca
fix: use correct PHP runtime in composer scripts
ChrisLightfootWild Apr 22, 2025
a89fa79
fix: update FlagsmithProvider supported PHP versions in README
ChrisLightfootWild Apr 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/php-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ jobs:
operating-system: [ubuntu-latest]
php-version: ['8.0', '8.1', '8.2']
project-dir:
- hooks/OpenTelemetry
- hooks/DDTrace
- hooks/OpenTelemetry
- hooks/Validators
# - providers/CloudBees
- providers/Flagd
- providers/Split
- providers/Flagsmith
- providers/GoFeatureFlag
# - providers/CloudBees
- providers/Split
fail-fast: false

# todo exclude some matrix combinations based on php version requirements
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/split_monorepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- [hook, validators, Validators]
- [provider, cloudbees, CloudBees]
- [provider, flagd, Flagd]
- [provider, flagsmith, Flagsmith]
- [provider, split, Split]
- [provider, go-feature-flag, GoFeatureFlag]
steps:
Expand Down
15 changes: 15 additions & 0 deletions providers/Flagsmith/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/build/ export-ignore
/CHANGELOG.md export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/psalm-baseline.xml export-ignore
/psalm.xml export-ignore
/tests/ export-ignore

* text=auto
3 changes: 3 additions & 0 deletions providers/Flagsmith/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
/composer.lock
/vendor
1 change: 1 addition & 0 deletions providers/Flagsmith/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
47 changes: 47 additions & 0 deletions providers/Flagsmith/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# OpenFeature Flagsmith Provider for PHP

[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
[![Latest Stable Version](http://poser.pugx.org/open-feature/flagsmith-provider/v)](https://packagist.org/packages/open-feature/flagsmith-provider)
[![Total Downloads](http://poser.pugx.org/open-feature/flagsmith-provider/downloads)](https://packagist.org/packages/open-feature/flagsmith-provider)
![PHP 8.0+](https://img.shields.io/badge/php->=8.0-blue.svg)
[![License](http://poser.pugx.org/open-feature/flagsmith-provider/license)](https://packagist.org/packages/open-feature/flagsmith-provider)

## Overview

Flagsmith provides an all-in-one platform for developing, implementing, and managing your feature flags. 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

```sh
composer require open-feature/flagsmith-provider
```

## Usage

The `FlagsmithProvider` constructor takes a configured Flagsmith client as its only argument:

```php
$flagsmith = new Flagsmith\Flagsmith('YOUR_FLAGSMITH_API_KEY');

OpenFeatureAPI::setProvider(new FlagsmithProvider($flagsmith));
```

## Development

### PHP Versioning

This library targets PHP 8.1 and above. As long as you have a 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`.

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`.
133 changes: 133 additions & 0 deletions providers/Flagsmith/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"name": "open-feature/flagsmith-provider",
"description": "The Flagsmith provider package for open-feature",
"license": "Apache-2.0",
"type": "library",
"keywords": [
"featureflags",
"featureflagging",
"openfeature",
"flagsmith",
"provider"
],
"authors": [
{
"name": "OpenFeature PHP Maintainers",
"homepage": "https://github.com/orgs/open-feature/teams/php-maintainer"
},
{
"name": "open-feature/php-sdk-contrib Contributors",
"homepage": "https://github.com/open-feature/php-sdk-contrib/graphs/contributors"
}
],
"require": {
"php": "^8.1",
"flagsmith/flagsmith-php-client": "^4.5.1",
"open-feature/sdk": "^2.0"
},
"require-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"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OpenFeature\\Providers\\Flagsmith\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"OpenFeature\\Providers\\Flagsmith\\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,
"php-http/discovery": false
},
"lock": false,
"sort-packages": true
},
"extra": {
"captainhook": {
"force-install": false
}
},
"scripts": {
"dev:analyze": [
"@dev:analyze:phpstan",
"@dev:analyze:psalm"
],
"dev:analyze:phpstan": "@php vendor/bin/phpstan analyse --ansi --debug --memory-limit=512M",
"dev:analyze:psalm": "@php vendor/bin/psalm",
"dev:build:clean": "git clean -fX build/",
"dev:grpc": [
"@dev:grpc:init",
"@dev:grpc:generate",
"@dev:grpc:stage"
],
"dev:grpc:generate": "export GOPATH=\"$(pwd)/schemas/vendor\" && pushd schemas && make gen-php && popd",
"dev:grpc:init": "git submodule update --recursive",
"dev:grpc:stage": "git add --force ./proto",
"dev:lint": [
"@dev:lint:syntax",
"@dev:lint:style"
],
"dev:lint:fix": "@php vendor/bin/phpcbf",
"dev:lint:style": "@php vendor/bin/phpcs --colors",
"dev:lint:syntax": "@php vendor/bin/parallel-lint --colors src/ tests/",
"dev:test": [
"@dev:lint",
"@dev:analyze",
"@dev:test:unit",
"@dev:test:integration"
],
"dev:test:coverage:ci": "@php vendor/bin/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": "@php vendor/bin/phpunit --colors=always --coverage-html build/coverage/coverage-html/",
"dev:test:unit": "@php vendor/bin/phpunit --colors=always --testdox",
"dev:test:unit:debug": "@php vendor/bin/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 unit tests...'",
"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."
}
}
25 changes: 25 additions & 0 deletions providers/Flagsmith/phpcs.xml.dist
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>
9 changes: 9 additions & 0 deletions providers/Flagsmith/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
tmpDir: ./build/cache/phpstan
level: max
paths:
- ./src
- ./tests
excludePaths:
- */tests/fixtures/*
- */tests/*/fixtures/*
25 changes: 25 additions & 0 deletions providers/Flagsmith/phpunit.xml.dist
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>
2 changes: 2 additions & 0 deletions providers/Flagsmith/psalm-baseline.xml
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"/>
17 changes: 17 additions & 0 deletions providers/Flagsmith/psalm.xml
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>
Loading