Skip to content

Commit 29a6dce

Browse files
committed
Merge branch 'task/multipleFactory' of github.com:splitio/php-client into task/multipleFactory
2 parents 74cbd32 + 151b796 commit 29a6dce

File tree

8 files changed

+49
-433
lines changed

8 files changed

+49
-433
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
name: ci
22
on:
3-
pull_request:
4-
branches:
5-
- develop
6-
- master
73
push:
8-
branches:
9-
- develop
10-
- master
4+
branches-ignore:
5+
- none
6+
pull_request:
7+
branches-ignore:
8+
- none
119

1210
concurrency:
1311
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
@@ -31,7 +29,7 @@ jobs:
3129
- '8.2'
3230
steps:
3331
- name: Checkout code
34-
uses: actions/checkout@v3
32+
uses: actions/checkout@v4
3533
with:
3634
fetch-depth: 0
3735

@@ -66,7 +64,6 @@ jobs:
6664
projectBaseDir: .
6765
args: >
6866
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
69-
-Dsonar.projectVersion=${{ env.VERSION }}
7067
7168
- name: SonarQube Scan (Pull Request)
7269
if: matrix.version == '8.2' && github.event_name == 'pull_request'
@@ -78,7 +75,6 @@ jobs:
7875
projectBaseDir: .
7976
args: >
8077
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
81-
-Dsonar.projectVersion=${{ env.VERSION }}
8278
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
8379
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }}
8480
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030

3131
"require-dev": {
32-
"phpunit/phpunit": "^9.0.0",
32+
"phpunit/phpunit": "^9.6",
3333
"squizlabs/php_codesniffer": "3.*",
3434
"rogervila/php-sonarqube-scanner": "1.1.0",
3535
"mockery/mockery": "^1.5"

src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php

Lines changed: 18 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
55
use SplitIO\Component\Utils as SplitIOUtils;
6-
use SplitIO\Component\Common\Context;
76

87
/**
98
* Class PRedis
@@ -15,6 +14,9 @@ class PRedis implements CacheStorageAdapterInterface
1514
/** @var \Predis\Client|null */
1615
private $client = null;
1716

17+
/** @var string */
18+
private $prefix = "";
19+
1820
/**
1921
* @param array $options
2022
* @throws AdapterException
@@ -26,7 +28,11 @@ public function __construct(array $options)
2628
}
2729
$_redisConfig = $this->getRedisConfiguration($options);
2830

29-
$this->client = new \Predis\Client($_redisConfig['redis'], $_redisConfig['options']);
31+
$this->client = new \Predis\Client($_redisConfig['parameters'], $_redisConfig['options']);
32+
33+
if (isset($_redisConfig['options']['prefix'])) {
34+
$this->prefix = $_redisConfig['options']['prefix'];
35+
}
3036
}
3137

3238
/**
@@ -48,24 +54,6 @@ private function isValidConfigArray($nodes, $type)
4854
return null;
4955
}
5056

51-
/**
52-
* @param array $sentinels
53-
* @param array $options
54-
* @return bool
55-
* @throws AdapterException
56-
*/
57-
private function isValidSentinelConfig($sentinels, $options)
58-
{
59-
$msg = $this->isValidConfigArray($sentinels, 'sentinel');
60-
if (!is_null($msg)) {
61-
throw new AdapterException($msg);
62-
}
63-
if (!isset($options['service'])) {
64-
throw new AdapterException('Master name is required in replication mode for sentinel.');
65-
}
66-
return true;
67-
}
68-
6957
private function validateKeyHashTag($keyHashTag)
7058
{
7159
if (!is_string($keyHashTag)) {
@@ -121,83 +109,32 @@ function ($value) {
121109
if (empty($filteredArray)) {
122110
throw new AdapterException('keyHashTags size is zero after filtering valid elements.');
123111
}
124-
return $selected = $filteredArray[array_rand($filteredArray, 1)];
112+
return $filteredArray[array_rand($filteredArray, 1)];
125113
}
126114

127115

128-
/**
129-
* @param array $clusters
130-
* @return bool
131-
* @throws AdapterException
132-
*/
133-
private function isValidClusterConfig($clusters)
134-
{
135-
$msg = $this->isValidConfigArray($clusters, 'clusterNode');
136-
if (!is_null($msg)) {
137-
throw new AdapterException($msg);
138-
}
139-
return true;
140-
}
141-
142116
/**
143117
* @param mixed $options
144118
* @return array
145-
* @throws AdapterException
146119
*/
147120
private function getRedisConfiguration($options)
148121
{
149122
$redisConfigutation = array(
150-
'redis' => null,
151-
'options' => null
123+
'parameters' => (isset($options['parameters'])) ? $options['parameters'] : null,
124+
'options' => null,
152125
);
153126

154-
$parameters = (isset($options['parameters'])) ? $options['parameters'] : null;
155-
$sentinels = (isset($options['sentinels'])) ? $options['sentinels'] : null;
156-
$clusters = (isset($options['clusterNodes'])) ? $options['clusterNodes'] : null;
157127
$_options = (isset($options['options'])) ? $options['options'] : null;
158-
159-
if (isset($_options['distributedStrategy']) && isset($parameters['tls'])) {
160-
throw new AdapterException("SSL/TLS cannot be used together with sentinel/cluster yet");
161-
}
162-
163128
if ($_options && isset($_options['prefix'])) {
164129
$_options['prefix'] = self::normalizePrefix($_options['prefix']);
165130
}
166131

167-
if (isset($parameters)) {
168-
$redisConfigutation['redis'] = $parameters;
169-
} else {
170-
// @TODO remove this statement when replication will be deprecated
171-
if (isset($_options['replication'])) {
172-
Context::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
173-
if (!isset($_options['distributedStrategy'])) {
174-
$_options['distributedStrategy'] = $_options['replication'];
175-
}
176-
}
177-
if (isset($_options['distributedStrategy'])) {
178-
switch ($_options['distributedStrategy']) {
179-
case 'cluster':
180-
if ($this->isValidClusterConfig($clusters)) {
181-
$keyHashTag = $this->selectKeyHashTag($_options);
182-
$_options['cluster'] = 'redis';
183-
$redisConfigutation['redis'] = $clusters;
184-
$prefix = isset($_options['prefix']) ? $_options['prefix'] : '';
185-
$_options['prefix'] = $keyHashTag . $prefix;
186-
}
187-
break;
188-
case 'sentinel':
189-
if ($this->isValidSentinelConfig($sentinels, $_options)) {
190-
$_options['replication'] = 'sentinel';
191-
$redisConfigutation['redis'] = $sentinels;
192-
}
193-
break;
194-
default:
195-
throw new AdapterException("Wrong configuration of redis 'distributedStrategy'.");
196-
}
197-
} else {
198-
throw new AdapterException("Wrong configuration of redis.");
199-
}
132+
if (isset($_options['cluster'])) {
133+
$keyHashTag = $this->selectKeyHashTag($_options);
134+
$prefix = isset($_options['prefix']) ? $_options['prefix'] : '';
135+
$_options['prefix'] = $keyHashTag . $prefix;
200136
}
137+
201138
$redisConfigutation['options'] = $_options;
202139
return $redisConfigutation;
203140
}
@@ -249,31 +186,8 @@ public function isOnList($key, $value)
249186

250187
public function getKeys($pattern = '*')
251188
{
252-
$prefix = null;
253-
if ($this->client->getOptions()->__isset("prefix")) {
254-
$prefix = $this->client->getOptions()->__get("prefix")->getPrefix();
255-
}
256-
257-
if ($this->client->getOptions()->__isset("distributedStrategy") &&
258-
$this->client->getOptions()->__get("distributedStrategy") == "cluster") {
259-
$keys = array();
260-
foreach ($this->client as $nodeClient) {
261-
$nodeClientKeys = $nodeClient->keys($pattern);
262-
$keys = array_merge($keys, $nodeClientKeys);
263-
}
264-
} else {
265-
$keys = $this->client->keys($pattern);
266-
}
267-
if ($prefix) {
268-
if (is_array($keys)) {
269-
foreach ($keys as $index => $key) {
270-
$keys[$index] = str_replace($prefix, '', $key);
271-
}
272-
} else {
273-
$keys = str_replace($prefix, '', $keys);
274-
}
275-
}
276-
return $keys;
189+
$keys = $this->client->keys($pattern);
190+
return str_replace($this->prefix, '', $keys);
277191
}
278192

279193
private static function normalizePrefix($prefix)

src/SplitIO/Sdk.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ private static function configureCache(array $options)
6767
} elseif ($cacheAdapter == 'predis') {
6868
$_options['options'] = isset($options['options']) ? $options['options'] : null;
6969
$_options['parameters'] = isset($options['parameters']) ? $options['parameters'] : null;
70-
$_options['sentinels'] = isset($options['sentinels']) ? $options['sentinels'] : null;
71-
$_options['clusterNodes'] = isset($options['clusterNodes']) ? $options['clusterNodes'] : null;
72-
$_options['distributedStrategy'] = isset($options['distributedStrategy'])
73-
? $options['distributedStrategy'] : null;
7470
} else {
7571
throw new Exception("A valid cache system is required. Given: $cacheAdapter");
7672
}

src/SplitIO/Sdk/ClientInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ public function isTreatment($key, $featureFlagName, $treatment);
168168
* @param $key
169169
* @param $trafficType
170170
* @param $eventType
171-
* @param null $value
171+
* @param $value
172+
* @param $properties
172173
* @return boolean
173174
*/
174-
public function track($key, $trafficType, $eventType, $value = null);
175+
public function track($key, $trafficType, $eventType, $value = null, $properties = null);
175176
}

src/SplitIO/Sdk/Factory/SplitFactory.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public function __construct($sdkKey, Pool $cache, array $options = array())
4545
$this->options = $options;
4646
$this->cache = $cache;
4747

48-
//Block until ready
49-
$this->doBUR();
50-
5148
$eventCache = new EventsCache($cache);
5249
$impressionCache = new ImpressionCache($cache);
5350
$segmentCache = new SegmentCache($cache);
@@ -63,21 +60,6 @@ public function __construct($sdkKey, Pool $cache, array $options = array())
6360
$this->manager = new SplitManager($splitCache);
6461
}
6562

66-
private function doBUR()
67-
{
68-
/*
69-
Deprecated
70-
$ready = (isset($this->options['ready']) && $this->options['ready'] > 0) ? $this->options['ready'] : null;
71-
72-
//Block Until Ready
73-
if ($ready) {
74-
if (!$this->blockUntilReady($ready)) {
75-
throw new TimeOutException("Cache data is not ready yet");
76-
}
77-
}
78-
*/
79-
}
80-
8163
/**
8264
* @return \SplitIO\Sdk\ClientInterface
8365
*/

src/SplitIO/Sdk/LocalhostClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function isTreatment($key, $featureFlagName, $treatment)
253253
/**
254254
* @inheritdoc
255255
*/
256-
public function track($key, $trafficType, $eventType, $value = null)
256+
public function track($key, $trafficType, $eventType, $value = null, $properties = null)
257257
{
258258
return true;
259259
}

0 commit comments

Comments
 (0)