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

[WIP] Allowing Multiple Factory Instantiation #194

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c523a17
Removed cache from DI
mmelograno Nov 17, 2022
e089f2b
linting fixes
mmelograno Nov 17, 2022
b08c536
updated Splitter test for TrafficAllocation
mmelograno Nov 17, 2022
49cd135
removed comments
mmelograno Nov 17, 2022
5c7e754
removed comments
mmelograno Nov 17, 2022
f7a8d13
updated di logger
mmelograno Dec 14, 2022
c5a8afb
feedback
mmelograno Dec 14, 2022
e923e71
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Dec 14, 2022
ebbbc6b
Updated License Year
github-actions[bot] Jan 1, 2023
1f403cc
updated Di component
mmelograno Jan 5, 2023
4daa3be
removed unnecesary private methods
mmelograno Jan 6, 2023
8154328
Merge pull request #196 from splitio/task/DiLogger
mmelograno Jan 6, 2023
5b46045
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Jan 6, 2023
47d9d1d
removed support for php 7
mmelograno Jan 6, 2023
54b7977
removed support for php 7
mmelograno Jan 6, 2023
b0eda71
Merge pull request #195 from splitio/update-license
mmelograno Jan 6, 2023
6cebe69
support for php 7.4
mmelograno Jan 6, 2023
a5f3d30
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Jan 6, 2023
eb1e875
added tracker component
mmelograno Jan 11, 2023
ca411b9
tracking instances
mmelograno Jan 11, 2023
7dcc25e
improved logging multiple factories
mmelograno Jan 16, 2023
d514aad
Merge pull request #197 from splitio/task/trackerComponent
mmelograno Jan 16, 2023
86cc2bc
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Jan 17, 2023
ad6c40c
updated log lines
mmelograno Jan 17, 2023
7d3a093
replaced Di in favor of Context
mmelograno Jan 17, 2023
092d94c
removed unused imports
mmelograno Jan 17, 2023
bc08632
Merge pull request #198 from splitio/task/context
mmelograno Jan 17, 2023
61ed071
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Jan 17, 2023
bffeba0
resetting context for integration tests
mmelograno Jan 17, 2023
9489dfc
replaced setMethods and doc
mmelograno Jan 18, 2023
cd81457
fixed factory for tests
mmelograno Jan 18, 2023
545a5de
Merge pull request #199 from splitio/maintenance/linting
mmelograno Jan 18, 2023
0170df4
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Jan 18, 2023
86b8f7f
added validation to exception message
mmelograno Jan 18, 2023
0869c91
merged with latest in master
mmelograno Feb 16, 2023
d3dd25c
updated with latest in master
mmelograno May 17, 2023
74cbd32
ci
mmelograno May 17, 2023
bae1a70
forwarding predis options directly without wrapping it
mmelograno Oct 24, 2023
5760067
updated php dependency
mmelograno Nov 8, 2023
841121c
updated ci
mmelograno Nov 8, 2023
333457d
more updates
mmelograno Jan 19, 2024
151b796
Merge pull request #210 from splitio/redisoptions
mmelograno Feb 1, 2024
29a6dce
Merge branch 'task/multipleFactory' of github.com:splitio/php-client …
mmelograno Feb 1, 2024
f158cf0
merged with latest release
mmelograno Feb 1, 2024
4b71e62
Merge pull request #222 from splitio/task/flagsetsintoMF
mmelograno Feb 1, 2024
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
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: ci
on:
pull_request:
branches:
- develop
- master
push:
branches:
- develop
- master
branches-ignore:
- none
pull_request:
branches-ignore:
- none

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand All @@ -26,13 +24,12 @@ jobs:
fail-fast: false
matrix:
version:
- '7.3'
- '8.0'
- '8.1'
- '8.2'
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -67,7 +64,6 @@ jobs:
projectBaseDir: .
args: >
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
-Dsonar.projectVersion=${{ env.VERSION }}

- name: SonarQube Scan (Pull Request)
if: matrix.version == '8.2' && github.event_name == 'pull_request'
Expand All @@ -79,7 +75,6 @@ jobs:
projectBaseDir: .
args: >
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
-Dsonar.projectVersion=${{ env.VERSION }}
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
2 changes: 1 addition & 1 deletion .github/workflows/update-license-year.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down
14 changes: 14 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
8.0.0 (Feb XX, 2023)
- BREAKING CHANGE: Removed support from versions older than PHP 7.4.
- BREAKING CHANGE: Added support for Multiple Factory Instantiation.

7.2.0 (Jan 24, 2024)
- Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation):
- Added new variations of the get treatment methods to support evaluating flags in given flag set/s.
- getTreatmentsByFlagSet and getTreatmentsByFlagSets
- getTreatmentWithConfigByFlagSets and getTreatmentsWithConfigByFlagSets
- Added `defaultTreatment` and `sets` properties to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager.

7.1.8 (Jul 24, 2023)
- Fixed input validation for empty keys.

7.1.7 (May 16, 2023)
- Updated terminology on the SDKs codebase to be more aligned with current standard without causing a breaking change. The core change is the term split for feature flag on things like logs and phpdoc comments.
- Fixed php 8.2 warnings in code.
Expand Down
27 changes: 2 additions & 25 deletions bin/splitio.dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
;NOTE: This file is read by default. If you would like customize it, please copy this file and replace the values.
;

;API-KEY for Split environment
api-key = 'YOUR_SPLITIO_APIKEY'
;SDK-KEY for Split environment
sdk-key = 'YOUR_SDK_KEY'

;---------------------
;LOG configuration
Expand Down Expand Up @@ -53,26 +53,3 @@ log-level = 'error'
cache-adapter = 'predis'
predis-parameters = '{"scheme":"tcp","host":"localhost","port":6379,"timeout":881}'
predis-options = '{"prefix":""}'


;---------------------
;PROCESS configuration
;---------------------

;SPLITS
;Set the rate to fetch the Splits definitions from server
features-refresh-rate = 30

;SEGMENTS
;Set the rate to fetch the Segments keys from server
segments-refresh-rate = 60

;IMPRESSIONS
;Set the rate to send the treatments impressions to server
impressions-refresh-rate = 60

;METRICS
;Set the rate to send the SDK metrics to server
metrics-refresh-rate = 60


7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
"bin": ["bin/splitio"],

"require": {
"php": ">=7.3",
"php": ">=8.0",
"psr/log": "1 - 3",
"predis/predis": "^2.0",
"symfony/yaml": "^5.3|^6.0"
},

"require-dev": {
"phpunit/phpunit": "^9.0.0",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "3.*",
"rogervila/php-sonarqube-scanner": "1.1.0"
"rogervila/php-sonarqube-scanner": "1.1.0",
"mockery/mockery": "^1.5"
},

"autoload": {
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
<testsuite name="component">
<directory suffix="Test.php">tests/Suite/Component/</directory>
</testsuite>
<testsuite name="dynamic_configurations">
<testsuite name="dynamic_configurations">
<directory suffix="Test.php">tests/Suite/DynamicConfigurations/</directory>
</testsuite>
<testsuite name="engine">
<directory suffix="Test.php">tests/Suite/Engine/</directory>
</testsuite>
<testsuite name="traffic_allocation">
<directory suffix="Test.php">tests/Suite/TrafficAllocation/</directory>
</testsuite>
<testsuite name="input_validation">
<directory suffix="Test.php">tests/Suite/InputValidation/</directory>
</testsuite>
Expand All @@ -59,6 +62,7 @@
<directory suffix="Test.php">tests/Suite/Component/</directory>
<directory suffix="Test.php">tests/Suite/DynamicConfigurations/</directory>
<directory suffix="Test.php">tests/Suite/Engine/</directory>
<directory suffix="Test.php">tests/Suite/TrafficAllocation/</directory>
<directory suffix="Test.php">tests/Suite/InputValidation/</directory>
<directory suffix="Test.php">tests/Suite/Matchers/</directory>
<directory suffix="Test.php">tests/Suite/Metrics/</directory>
Expand Down
22 changes: 18 additions & 4 deletions src/SplitIO/Component/Cache/EventsCache.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;
use SplitIO\Sdk\Events\EventQueueMessage;
use SplitIO\Component\Cache\Pool;

class EventsCache
{
const KEY_EVENTS_LIST = "SPLITIO.events";

public static function addEvent(EventQueueMessage $message)
/**
* @var \SplitIO\Component\Cache\Pool
*/
private $cache;

/**
* @param \SplitIO\Component\Cache\Pool $cache
*/
public function __construct(Pool $cache)
{
$this->cache = $cache;
}

public function addEvent(EventQueueMessage $message)
{
$queueJSONmessage = json_encode($message->toArray());

Di::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
return (Di::getCache()->rightPushInList(self::KEY_EVENTS_LIST, $queueJSONmessage) > 0);
Context::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
return ($this->cache->rightPushInList(self::KEY_EVENTS_LIST, $queueJSONmessage) > 0);
}
}
23 changes: 18 additions & 5 deletions src/SplitIO/Component/Cache/ImpressionCache.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;
use SplitIO\Component\Cache\KeyFactory;
use SplitIO\Component\Common\Context;
use SplitIO\Sdk\QueueMetadataMessage;
use SplitIO\Component\Cache\Pool;

class ImpressionCache
{
const IMPRESSIONS_QUEUE_KEY = "SPLITIO.impressions";
const IMPRESSION_KEY_DEFAULT_TTL = 3600;

/**
* @var \SplitIO\Component\Cache\Pool
*/
private $cache;

/**
* @param \SplitIO\Component\Cache\Pool $cache
*/
public function __construct(Pool $cache)
{
$this->cache = $cache;
}

public function logImpressions($impressions, QueueMetadataMessage $metadata)
{
$toStore = array_map(
Expand All @@ -30,10 +43,10 @@ function ($imp) use ($metadata) {
$impressions
);

Di::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
$count = Di::getCache()->rightPushInList(self::IMPRESSIONS_QUEUE_KEY, $toStore);
Context::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
$count = $this->cache->rightPushInList(self::IMPRESSIONS_QUEUE_KEY, $toStore);
if ($count == count($impressions)) {
Di::getCache()->expireKey(self::IMPRESSIONS_QUEUE_KEY, self::IMPRESSION_KEY_DEFAULT_TTL);
$this->cache->expireKey(self::IMPRESSIONS_QUEUE_KEY, self::IMPRESSION_KEY_DEFAULT_TTL);
}
return ($count >= count($impressions));
}
Expand Down
9 changes: 7 additions & 2 deletions src/SplitIO/Component/Cache/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use SplitIO\Component\Cache\Storage\Adapter\PRedis as PRedisAdapter;
use SplitIO\Component\Cache\Storage\Adapter\SafeRedisWrapper;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

class Pool extends CacheKeyTrait
{
Expand Down Expand Up @@ -39,7 +39,7 @@ public function __construct(array $options = array())
public function get($key)
{
$this->assertValidKey($key);
Di::getLogger()->debug("Fetching item ** $key ** from cache");
Context::getLogger()->debug("Fetching item ** $key ** from cache");
return $this->adapter->get($key);
}

Expand Down Expand Up @@ -83,4 +83,9 @@ public function expireKey($key, $ttl)
{
return $this->adapter->expireKey($key, $ttl);
}

public function sMembers($key)
{
return $this->adapter->sMembers($key);
}
}
19 changes: 15 additions & 4 deletions src/SplitIO/Component/Cache/SegmentCache.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;

class SegmentCache implements SegmentCacheInterface
{
const KEY_SEGMENT_DATA = 'SPLITIO.segment.{segmentName}';

const KEY_TILL_CACHED_ITEM = 'SPLITIO.segment.{segment_name}.till';

/**
* @var \SplitIO\Component\Cache\Pool
*/
private $cache;

/**
* @param \SplitIO\Component\Cache\Pool $cache
*/
public function __construct(Pool $cache)
{
$this->cache = $cache;
}

private static function getCacheKeyForSegmentData($segmentName)
{
return str_replace('{segmentName}', $segmentName, self::KEY_SEGMENT_DATA);
Expand All @@ -27,7 +38,7 @@ private static function getCacheKeyForSinceParameter($segmentName)
public function isInSegment($segmentName, $key)
{
$segmentDataKey = self::getCacheKeyForSegmentData($segmentName);
return Di::getCache()->isItemOnList($segmentDataKey, $key);
return $this->cache->isItemOnList($segmentDataKey, $key);
}

/**
Expand All @@ -36,7 +47,7 @@ public function isInSegment($segmentName, $key)
*/
public function getChangeNumber($segmentName)
{
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter($segmentName));
$since = $this->cache->get(self::getCacheKeyForSinceParameter($segmentName));
// empty check for nullable value
return (empty($since)) ? -1 : $since;
}
Expand Down
Loading