Giter Club home page Giter Club logo

flagsmith / flagsmith-php-client Goto Github PK

View Code? Open in Web Editor NEW
17.0 9.0 10.0 162 KB

PHP Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/

Home Page: https://www.flagsmith.com/

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%
feature-flags feature-flag feature-flagging feature-flaggers feature-toggles feature-toggle ci cd continous-deployment continuous-integration

flagsmith-php-client's Issues

Cache getting incorrectly accessed/read

I am accessing flagsmith in a docker container via a PHP CMS and everytime after restarting I have to manually clear the cache folder (removing the cache folder via the entrypoint doesnt work aswell) due to an error that the cachedCall is null.

https://sentry.internal.jrbit.de/share/issue/4bf1cd4ca04b4cbcaca8541a37709f9e/

The cache folder is empty and after deleting it it works.

https://github.com/JRB-IT/crispcms/blob/68e313aedf9c30aa996ae10fead621acab24fe5b/cms/jrbit/class/crisp/api/Flagsmith.php#L53

Any clue on what the issue is an how to hotfix it? Running on Tag 2.1.1

Possibility to implement PSRs? (Through Community submitted PR)

Hello!

Would you be willing to accept a PR that introduces PSR-18 and PSR-17, for example Guzzle and PSR-16 for example Symfony Cache to this library? This is how the unleashed client works (https://github.com/Unleash/unleash-client-php) and allows for more flexibility in the library. Additionally in terms of PSR-16 if one does not want to implement a cache they can just set the null driver so this library can actually work the same way as before it would just allow more flexibility than relying directly on CURL commands (like being able to async in PHP)

Regex segment local evaluation with getype cast expression as int

Hello,

We encountered a bug after defining a regex segment with the following regex ^\d*[13579]$, after a lot of investigation we found that the code cast the expression as an int, making the regex useless and hazardous. We added dumps to the code in order to help you understand the bug.

class SegmentConditionModel
{
    public function matchesTraitValue($traitValue): bool
    {
        $condition = false;
        $castedValue = $this->value;
        $traitValueType = gettype($traitValue);

        dump($castedValue); // "^\d*[13579]$"
        dump($traitValueType); // "integer"
        dump($this->operator); "REGEX"
        if ($traitValueType == 'boolean') {
            $castedValue = filter_var($castedValue, FILTER_VALIDATE_BOOLEAN);
        } elseif ($this->operator === SegmentConditions::MODULO) {
            return $this->matchesModuloTraitValue($traitValue);
        } else {
            settype($castedValue, $traitValueType);
        }
        dump($castedValue); // 0
    }
}

Identity overrides in local evaluation mode

  1. Extend the Environment model with the identity_overrides: List[IdentityModel] field.
  2. On environment update in local evaluation mode, store overrides so they're efficiently accessed by identifier.
  3. For getIdentityFlagsFromDocument interface, use the storage above to retrieve the identity overrides. Fall back to a new IdentityModel instance if not found. If found, update traits with user-provided traits.

Refer to the following existing implementations:

Flagsmith/flagsmith-python-client#72
Flagsmith/flagsmith-java-client#142
Flagsmith/flagsmith-nodejs-client#143

Create a release

Can you create a release please?

That would enable users of this package to use the version in composer.json, instead of dev-master.

Identity Traits not being assigned

I've noticed weird behaviour on the identity traits (them not working at all),

when using withTraits, the traits object is set to NULL, not assigning any trait

$LoggedInID = new Identity($GLOBALS['user']['sub']);


$LoggedInID->withTraits([
	(new IdentityTrait('session_id'))->withValue($GLOBALS['guid']),
    (new IdentityTrait('email'))->withValue($GLOBALS['email']),
    (new IdentityTrait('preferred_username'))->withValue($GLOBALS['preferred_username']),
    (new IdentityTrait('route'))->withValue($GLOBALS['route']->Page),
    (new IdentityTrait('locale'))->withValue($Locale)
]);

$GLOBALS['flagsmith_identity'] = $LoggedInID;
object(Flagsmith\Models\Identity)#115 (3) { ["id":"Flagsmith\Models\Identity":private]=> string(36) "28e0577f-37eb-471a-8bb0-0c3309ed50ce" ["traits":"Flagsmith\Models\Identity":private]=> NULL ["flags":"Flagsmith\Models\Identity":private]=> NULL } 

however using withTrait, the object is set to an empty array, not containing any trait

            $AnonymousID->withTrait((new IdentityTrait('session_id'))->withValue($GLOBALS['guid']));
            $AnonymousID->withTrait((new IdentityTrait('route'))->withValue($GLOBALS['route']->Page));
            $AnonymousID->withTrait((new IdentityTrait('locale'))->withValue($Locale));
object(Flagsmith\Models\Identity)#206 (3) { ["id":"Flagsmith\Models\Identity":private]=> string(36) "b1e2a203-f4e1-93db-95c5-2dd10e5e7944" ["traits":"Flagsmith\Models\Identity":private]=> array(0) { } ["flags":"Flagsmith\Models\Identity":private]=> NULL } 

Running on the latest tag (2.0.1)

Resolve `jsonSerialize` deprecation warnings

The following warning was presented for the jsonSerialize() methods on the MultivariateFeatureStateValueModelList and CollectionTrait and classes. We have temporarily resolved this in this PR by indicating that the return type will change in the next major version.

Deprecated: Return type of Flagsmith\Utils\Collections\FlagModelsList::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Initital value not nullable.

There currently is an issue with the $initialValue variable not being nullable, thus throwing the following exception if no default value is set in a flag

message' => 'Flagsmith\\Models\\Feature::withInitialValue(): Argument #1 ($initialValue) must be of type string, null given, called in /********/vendor/flagsmith/flagsmith-php-client/src/Flagsmith.php on line 584

Fix can be done in the Models/Feature.php by making the parameter in withInitialValue optional as well as the private variable $initialValue

public function withInitialValue(string $initialValue): self

private string $initialValue;

PR is upcoming

Mocking routes directly from file

I saw that in ClientFixtures.php file the routes are create using the "withResponse" method.

->withResponse(new Response(200, [], self::loadFileContents('flags.json')))

FYI you can also use the "withFileResponse" method like the following

->withFileResponse(self::DATA_DIR . 'flags.json')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.