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 34 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- 6379:6379
strategy:
matrix:
version: ['7.3', '8.0', '8.1']
version: ['7.4', '8.0', '8.2']
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
8.0.0 (Jan XX, 2023)
- BREAKING CHANGE: Removed support from versions older than PHP 7.4.
- BREAKING CHANGE: Added support for Multiple Factory Instantiation.

7.1.5 (Oct 28, 2022)
- Updated phpdocs for `ClientInterface`.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2022 Split Software, Inc.
Copyright © 2023 Split Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"bin": ["bin/splitio"],

"require": {
"php": ">=7.3",
"php": ">=7.4",
"psr/log": "1 - 3",
"predis/predis": "^2.0",
"symfony/yaml": "^5.3|^6.0"
Expand All @@ -31,7 +31,8 @@
"require-dev": {
"phpunit/phpunit": "^9.0.0",
"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 @@ -24,12 +24,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 @@ -55,6 +58,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
4 changes: 2 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
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
34 changes: 20 additions & 14 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;

class SplitCache implements SplitCacheInterface
{
const KEY_TILL_CACHED_ITEM = 'SPLITIO.splits.till';
Expand All @@ -11,6 +9,19 @@ class SplitCache implements SplitCacheInterface

const KEY_TRAFFIC_TYPE_CACHED = 'SPLITIO.trafficType.{trafficTypeName}';

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

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

private static function getCacheKeyForSinceParameter()
{
return self::KEY_TILL_CACHED_ITEM;
Expand All @@ -33,11 +44,11 @@ private static function getSplitNameFromCacheKey($key)
}

/**
* @return long
* @return int
*/
public function getChangeNumber()
{
$since = Di::getCache()->get(self::getCacheKeyForSinceParameter());
$since = $this->cache->get(self::getCacheKeyForSinceParameter());
// empty check for nullable value
return (empty($since)) ? -1 : $since;
}
Expand All @@ -48,18 +59,16 @@ public function getChangeNumber()
*/
public function getSplit($splitName)
{
$cache = Di::getCache();
return $cache->get(self::getCacheKeyForSplit($splitName));
return $this->cache->get(self::getCacheKeyForSplit($splitName));
}

/**
* @param array $splitNames
* @return string JSON representation
* @return array
*/
public function getSplits($splitNames)
{
$cache = Di::getCache();
$cacheItems = $cache->fetchMany(array_map('self::getCacheKeyForSplit', $splitNames));
$cacheItems = $this->cache->fetchMany(array_map('self::getCacheKeyForSplit', $splitNames));
$toReturn = array();
foreach ($cacheItems as $key => $value) {
$toReturn[self::getSplitNameFromCacheKey($key)] = $value;
Expand All @@ -72,8 +81,7 @@ public function getSplits($splitNames)
*/
public function getSplitNames()
{
$cache = Di::getCache();
$splitKeys = $cache->getKeys(self::getCacheKeySearchPattern());
$splitKeys = $this->cache->getKeys(self::getCacheKeySearchPattern());
return array_map('self::getSplitNameFromCacheKey', $splitKeys);
}

Expand All @@ -97,9 +105,7 @@ private static function getCacheKeyForTrafficType($trafficType)
*/
public function trafficTypeExists($trafficType)
{
$cache = Di::getCache();

$count = $cache->get(self::getCacheKeyForTrafficType($trafficType));
$count = $this->cache->get(self::getCacheKeyForTrafficType($trafficType));
// empty check for nullable value
return (empty($count) || $count < 1) ? false : true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SplitIO/Component/Cache/SplitCacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
interface SplitCacheInterface
{
/**
* @return long
* @return int
*/
public function getChangeNumber();

Expand Down
7 changes: 3 additions & 4 deletions src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
namespace SplitIO\Component\Cache\Storage\Adapter;

use SplitIO\Component\Cache\Storage\Exception\AdapterException;
use SplitIO\Component\Cache\Item;
use SplitIO\Component\Utils as SplitIOUtils;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

/**
* Class PRedis
Expand Down Expand Up @@ -109,7 +108,7 @@ private function selectKeyHashTag($options)
return $this->getDefaultKeyHashTag($options); // defaulting to keyHashTag or {SPLITIO}
}
$keyHashTags = $options['keyHashTags'];
$msg = $this->isValidConfigArray($keyHashTags, 'keyHashTags'); // check if is valid array
$msg = $this->isValidConfigArray($keyHashTags, 'keyHashTag'); // check if is valid array
if (!is_null($msg)) {
throw new AdapterException($msg);
}
Expand Down Expand Up @@ -170,7 +169,7 @@ private function getRedisConfiguration($options)
} else {
// @TODO remove this statement when replication will be deprecated
if (isset($_options['replication'])) {
Di::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
Context::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
if (!isset($_options['distributedStrategy'])) {
$_options['distributedStrategy'] = $_options['replication'];
}
Expand Down
Loading