Coder Social home page Coder Social logo

splitio / php-client Goto Github PK

View Code? Open in Web Editor NEW
16.0 24.0 12.0 13.68 MB

PHP SDK client for Split Software

Home Page: https://split.io

License: Other

PHP 100.00%
feature-toggles feature-toggle feature-flags split splitsoftware control-rollout sdk ab-testing php

php-client's Introduction

Split SDK for PHP

build status Latest stable Documentation

Overview

This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via feature flags to manage your complete customer experience.

Compatibility

This SDK is compatible with PHP 7.3 and above.

Getting started

Below is a simple example that describes the instantiation and most basic usage of our SDK. Keep in mind that since PHP does not have the ability to share memory between processes the use of the split-synchronizer is mandatory for this SDK.

<?php

$sdkConfig = ['cache' => ['adapter' => 'predis']];
$splitFactory = \SplitIO\Sdk::factory('YOUR_SDK_KEY', $sdkConfig);

$splitClient = $splitFactory->client();
$treatment = $splitClient->getTreatment('CUSTOMER_ID','FEATURE_FLAG_NAME');
if ($treatment === 'on') {
    // Feature is enabled for this user!
} elseif ($treatment === 'off') {
    // Feature is disabled for this user!
} else {
    // Unable to perform evaluation.
}

Please refer to our official docs to learn about all the functionality provided by our SDK and the configuration options available for tailoring it to your current application setup.

Submitting issues

The Split team monitors all issues submitted to this issue tracker. We encourage you to use this issue tracker to submit any bug reports, feedback, and feature enhancements. We'll do our best to respond in a timely manner.

Contributing

Please see Contributors Guide to find all you need to submit a Pull Request (PR).

License

Licensed under the Apache License, Version 2.0. See: Apache License.

About Split

Split is the leading Feature Delivery Platform for engineering teams that want to confidently deploy features as fast as they can develop them. Split’s fine-grained management, real-time monitoring, and data-driven experimentation ensure that new features will improve the customer experience without breaking or degrading performance. Companies like Twilio, Salesforce, GoDaddy and WePay trust Split to power their feature delivery.

To learn more about Split, contact [email protected], or get started with feature flags for free at https://www.split.io/signup.

Split has built and maintains SDKs for:

For a comprehensive list of open source projects visit our Github page.

Learn more about Split:

Visit split.io/product for an overview of Split, or visit our documentation at help.split.io for more detailed information.

php-client's People

Contributors

frazjp65 avatar github-actions[bot] avatar goldensun8891 avatar hjewkes avatar israphel avatar jbreton avatar jmrieger avatar mmelograno avatar mredolatti avatar nicozelaya avatar patricioe avatar sanzmauro avatar sarrubia avatar senhorcastor avatar splitadricejas avatar wag-somohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-client's Issues

Use phpredis extension

Hello,

I'd like to know if it is possible (and if yes, how) to use the phpredis extension with this SDK?

Thanks

Control treatment not returned if cache adapter is unavailable

I'm testing out a failure scenario where our redis cache is down. It looks like when I call

$splitClient->getTreatment('CUSTOMER_ID','SPLIT_NAME');

it catches the error correctly when reading the treatment from cache. However when it tries to write the impression to cache for the control treatment I'm getting a failure before the return statement:

        $this->logImpression(
            $matchingKey,
            $featureName,
            TreatmentEnum::CONTROL,
            $impressionLabel,
            $bucketingKey
        );
        return TreatmentEnum::CONTROL;

Should the call to logImpression() in SplitIO\Sdk\Client::getTreatment() be wrapped in a try/catch so that it can at least return the control treatment?

json_decode doesn't work in SharedMemory

The cached string in SharedMemory will not be able to be decoded using json_decode unless the size matches exactly. Since the size it set for all cached items globally and not for each key, this will rarely work.

Expected Behavior

  • Configure the shared memory to have a size of 1000 (or anything that doesn't match the size of your cache item).
  • Try to read a small split from the cache twice in a row.
  • The second read is pulled from shared memory.

Actual Behavior

  • Configure the shared memory to have a size of 1000 (or anything that doesn't match the size of your cache item).
  • Try to read a small split from the cache twice in a row.
  • The second read is not pulled from shared memory.

Feature Request: Allow SDK initialization with existing Predis Connection

Our application(s) already use a Redis client for caching session data. It would be a nice feature to be able to reuse that existing Redis instance AND connection, instead of having to build two separate connections, one for Split, and one for our application.

Ideally, the SDK class would have an option to pass an existing Predis (or Rredis) connection object, in addition to the parameters to build a new client.

Error while extracting composer package in 7.2.0 | duplicate class in two different files

When installing the composer package in version 7.2.0 the following error occurs on macOS:

  - Installing splitsoftware/split-sdk-php (7.2.0): Extracting archive
    Failed to extract splitsoftware/split-sdk-php: (1) '/usr/bin/unzip' -qq '/Users/.../vendor/composer/tmp-3adceb1e2ad196f58b2ac42cebdedab9.zip' -d '/Users/.../vendor/composer/6e494f8f'

replace /Users/.../vendor/composer/6e494f8f/splitio-php-client-4d0aef5/src/SplitIO/Sdk/Validator/flagSetsValidator.php? [y]es, [n]o, [A]ll, [N]one, [r]ename:  NULL
(EOF or read error, treating as "[N]one" ...)

    The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
    Unzip with unzip command failed, falling back to ZipArchive class
    Skipped installation of bin bin/splitio for package splitsoftware/split-sdk-php: name conflicts with an existing file

It seems that the same class exists in two files in https://github.com/splitio/php-client/tree/master/src/SplitIO/Sdk/Validator, one with an upper case first char and another with a lower case first char:

I guess that https://github.com/splitio/php-client/blob/master/src/SplitIO/Sdk/Validator/flagSetsValidator.php could simply be deleted, as the content of the two files is identical.

PHP 7.1 Compatibility

We're excited to use Split.io. Unfortunately, it doesn't appear PHP 7.1 compatible:

Compile Error: Cannot use SplitIO\Component\Log\Handler\Void as Void because 'Void' is a special class name
at n/a
    in /app/vendor/splitsoftware/split-sdk-php/src/SplitIO/Component/Initialization/LoggerTrait.php line 10

at Symfony\Component\Debug\DebugClassLoader->loadClass()
    in /app/vendor/splitsoftware/split-sdk-php/src/SplitIO/Sdk.php line 55

at spl_autoload_call()
    in /app/vendor/splitsoftware/split-sdk-php/src/SplitIO/Sdk.php line 55

at SplitIO\Sdk::registerLogger()
    in /app/vendor/splitsoftware/split-sdk-php/src/SplitIO/Sdk.php line 35

Return a singleton instead of null when trying to create multiple factories

The current code returns null when a factory was already instantiated. I can see some major problems with this approach:

  1. It is not intuitive for the developer
  2. This violates the method contract as specified in the @return docblock annotation tag. The annotation specifies that the return type is an instance of SplitFactoryInterface

My suggestion would be: Instead of tracking the instantiation of the factories by using a flag (KEY_FACTORY_TRACKER) we would keep a reference to the instantiated object in the container, so that whenever an user of the SDK tries to create multiple factories, we simply return the last created factory

Another approach would be to create a new static method called singleton to make this behavior more explicit.

Magento 2 Integration

I am looking for a documentation that explains how to integrate with Magento 2 and split.io. Any help is appreciated

Error when loading SplitIO\Component\Cache\Storage\Adapter\Filesystem

Fatal error: Class SplitIO\Component\Cache\Storage\Adapter\Filesystem contains 10 abstract methods and must therefore be declared abstract or implement the remaining methods (SplitIO\Component\Cache\Storage\Adapter\CacheStorageAdapterInterface::getKeys, SplitIO\Component\Cache\Storage\Adapter\CacheStorageAdapterInterface::getItems, SplitIO\Component\Cache\Storage\Adapter\CacheStorageAdapterInterface::addItemList, ...) in /opt/project/vendor/splitsoftware/split-sdk-php/src/SplitIO/Component/Cache/Storage/Adapter/Filesystem.php on line 12

This is on 7.1.0 using php 7.4

PHP 8.0 Compatibility

We're trying to upgrade from PHP 7.4 to 8.0 and right now the only library holding us back is Split.io SDK. When executing from PHP 8.0 environment, we're getting this error in Di.php line 75:

The magic method SplitIO\Component\Common\Di::__wakeup() must have public visibility

SplitManager fatals when cache isn't present

in SplitIO\Component\Common\Di:

/**
* @return null|\SplitIO\Component\Cache\Pool
*/
public static function getCache()

however in SplitIO\Sdk\Manager\SplitManager

public function getSplitNames()
{
    $cache = Di::getCache();     <---- this can return null according to function signature
    $splitKeys = $cache->getKeys(self::getCacheKeySearchPattern());     <--- this will then result in null reference exception

Easy to reproduce:

$manager = new SplitManager();
$manager->getSplitNames(); <-- fatal exception

Server-side SDK always getting control treatments.

When I call getTreatment($key, $featureName, array $attributes = null) I am always getting control treatments.

Also when I debug $bucketingKey = $inputValidation['bucketingKey']; is null not sure where to pass the 'bucketingKey'

Support for predis 2.x

ATM the constraint for predis/predis in composer.json is "^1.1.9". Therefore it isn't possible to upgrade predis to v2 (released since 2022-06-08 13:14 UTC) in projects which uses slitio/php-client.

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.