Skip to content
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

feat: FlagsmithProvider #126

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ChrisLightfootWild
Copy link

@ChrisLightfootWild ChrisLightfootWild commented Mar 31, 2025

This PR

  • adds new package, open-feature/flagsmith-provider
    • implements OpenFeature\interfaces\provider\Provider interface for Flagsmith
    • depends on flagsmith/flagsmith-php-client

Notes

image

Follow-up Tasks

How to test

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

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

Run the tests with:

composer run dev:test

You should (hopefully) see the below output:
image

Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
Signed-off-by: Chris Lightfoot-Wild <[email protected]>
@ChrisLightfootWild ChrisLightfootWild changed the title (feat): FlagsmithProvider feat: FlagsmithProvider Mar 31, 2025
@ChrisLightfootWild ChrisLightfootWild marked this pull request as ready for review March 31, 2025 23:55
@ChrisLightfootWild ChrisLightfootWild requested a review from a team as a code owner March 31, 2025 23:55

class FlagsmithProvider extends AbstractProvider implements Provider
{
protected static string $NAME = 'FlagsmithProvider';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected static string $NAME = 'FlagsmithProvider';
protected static string $NAME = 'Flagsmith';

This is up to you but I feel like Provider is implicit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to detect if a flag isn't found?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the Flagsmith client throws a generic FlagsmithClientError in this situation, but I don't see any reason not to use this opportunity to improve the Flagsmith SDK too and extend that exception for a specific FlagsmithFlagNotFound error, similar to how we do it in the python client here.


### 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 library targets PHP version X and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK.

"require": {
"php": "^8.1",
"ext-json": "*",
"flagsmith/flagsmith-php-client": "^4.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine since we're using the ^ to specify that any version since 4.1 can be used, but the latest version is 4.5.1 and includes some important changes. Would it be better to specify ^4.5.1 here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the Flagsmith client throws a generic FlagsmithClientError in this situation, but I don't see any reason not to use this opportunity to improve the Flagsmith SDK too and extend that exception for a specific FlagsmithFlagNotFound error, similar to how we do it in the python client here.

Comment on lines +112 to +117
if ($flag->getEnabled()) {
/** @var array<array-key, mixed>|bool|DateTime|float|int|string|null $value */
$value = $flag->getValue();

$builder->withValue($value);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other providers (e.g. this logic in the python client) we only check this value before returning the value based on a configuration argument passed to the initialisation of the provider.

I'm not against handling this differently here, but just though I'd highlight it.

Comment on lines +55 to +68
public function resolveStringValue(string $flagKey, string $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->resolve($flagKey, $defaultValue, $context);
}

public function resolveIntegerValue(string $flagKey, int $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->resolve($flagKey, $defaultValue, $context);
}

public function resolveFloatValue(string $flagKey, float $defaultValue, ?EvaluationContext $context = null): ResolutionDetails
{
return $this->resolve($flagKey, $defaultValue, $context);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the value from the flagsmith SDK can have different types, shouldn't we do some string casting here (or in the resolve method perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants