Skip to content

Commit fb250a1

Browse files
authored
Merge branch 'master' into develop
2 parents f21448e + 99c931c commit fb250a1

File tree

12 files changed

+86
-13
lines changed

12 files changed

+86
-13
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
7.1.6 (Feb 14, 2023)
2+
- Fixed logging on array conversion.
3+
4+
7.1.5 (Oct 28, 2022)
5+
- Updated phpdocs for `ClientInterface`.
6+
17
7.1.4 (Sep 6, 2022)
28
- Updated dependencies to allow `psr/log` 2 and 3.
39
- Removed `phpdocumentor/phpdocumentor` dependency.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Split SDK for PHP
22

3-
[![Build Status](https://api.travis-ci.com/splitio/php-client.svg?branch=master)](https://api.travis-ci.com/splitio/php-client)
3+
[![build status](https://github.com/splitio/php-client/actions/workflows/ci.yml/badge.svg)](https://github.com/splitio/php-client/actions)
4+
[![Latest stable](https://img.shields.io/packagist/v/splitsoftware/split-sdk-php)](https://packagist.org/packages/splitsoftware/split-sdk-php)
5+
[![Documentation](https://img.shields.io/badge/php_client-documentation-informational)](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
46

57
This SDK is designed to work with Split, the platform for controlled rollouts, serving features to your users via the Split feature flag to manage your complete customer experience.
68

src/SplitIO/Component/Log/Logger.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public function __construct(LogHandlerInterface $handler = null, $level = LogLev
6060
public function log($level, $message, array $context = array())
6161
{
6262
if ($this->logLevels[$level] <= $this->logLevel) {
63+
if (is_array($message)) {
64+
$message = json_encode($message);
65+
}
6366
$this->handler->write($level, $message);
6467
}
6568
}

src/SplitIO/Sdk/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Client implements ClientInterface
1919

2020
private $evaluator = null;
2121
private $impressionListener = null;
22+
private $queueMetadata = null;
2223

2324
/**
2425
* Flag to get Impression's labels feature enabled

src/SplitIO/Sdk/ClientInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface ClientInterface
2929
*
3030
* <p>
3131
* This method does not throw any exceptions.
32-
* It also never returns null.
32+
* It also never returns null.
3333
*
3434
* @param $key
3535
* @param $featureName
@@ -74,7 +74,7 @@ public function getTreatment($key, $featureName, array $attributes = null);
7474
* @param $key
7575
* @param $featureName
7676
* @param $attributes
77-
* @return string
77+
* @return array
7878
*/
7979
public function getTreatmentWithConfig($key, $featureName, array $attributes = null);
8080

src/SplitIO/Sdk/LocalhostClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ public function getTreatmentWithConfig($key, $featureName, array $attributes = n
191191
*/
192192
public function getTreatments($key, $featureNames, array $attributes = null)
193193
{
194+
$result = array();
195+
194196
$splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatments");
195197
if (is_null($splitNames)) {
196-
return null;
198+
return $result;
197199
}
198200

199201
$key = InputValidator::validateKey($key, "getTreatments");
200202
if (is_null($key)) {
201203
return array_fill_keys($splitNames, TreatmentEnum::CONTROL);
202204
}
203205

204-
$result = array();
205-
206206
foreach ($splitNames as $split) {
207207
$result[$split] = $this->getTreatment($key["matchingKey"], $split, $attributes);
208208
};
@@ -215,18 +215,18 @@ public function getTreatments($key, $featureNames, array $attributes = null)
215215
*/
216216
public function getTreatmentsWithConfig($key, $featureNames, array $attributes = null)
217217
{
218+
$result = array();
219+
218220
$splitNames = InputValidator::validateFeatureNames($featureNames, "getTreatmentsWithConfig");
219221
if (is_null($splitNames)) {
220-
return null;
222+
return $result;
221223
}
222224

223225
$key = InputValidator::validateKey($key, "getTreatmentsWithConfig");
224226
if (is_null($key)) {
225227
return array_fill_keys($splitNames, array('treatment' => TreatmentEnum::CONTROL, 'config' => null));
226228
}
227229

228-
$result = array();
229-
230230
foreach ($splitNames as $split) {
231231
$result[$split] = $this->getTreatmentWithConfig($key["matchingKey"], $split, $attributes);
232232
};

src/SplitIO/TreatmentImpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class TreatmentImpression
1515
public static function log($impressions, QueueMetadataMessage $metadata)
1616
{
1717
try {
18-
Di::getLogger()->debug($impressions);
1918
if (is_null($impressions) || (is_array($impressions) && 0 == count($impressions))) {
19+
Di::getLogger()->debug("no impressions were sent");
2020
return null;
2121
}
2222
$impressionCache = new ImpressionCache();

src/SplitIO/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
class Version
55
{
6-
const CURRENT = '7.1.4';
6+
const CURRENT = '7.1.6';
77
}

tests/Suite/InputValidation/GetTreatmentValidationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,23 @@ public function testGetTreatmentWithConfigWithNotExistantSplitName()
366366
$this->assertEquals('control', $result['treatment']);
367367
}
368368

369+
public function testGetTreatmentWitConfigWithhNullFeatureName()
370+
{
371+
$splitSdk = $this->getFactoryClient();
372+
373+
$logger = $this->getMockedLogger();
374+
375+
$logger->expects($this->once())
376+
->method('critical')
377+
->with($this->equalTo("getTreatmentWithConfig: you passed a null split name, split name must be a non-empty"
378+
. " string."));
379+
380+
$result = $splitSdk->getTreatmentWithConfig('some_key', null);
381+
$this->assertEquals('control', $result['treatment']);
382+
$this->assertEquals(null, $result['config']);
383+
384+
}
385+
369386
public static function tearDownAfterClass(): void
370387
{
371388
Utils\Utils::cleanCache();

tests/Suite/InputValidation/GetTreatmentsValidationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,34 @@ public function testGetTreatmenstConfigWithoutExistingFeatureName()
407407
$this->assertEquals('control', $treatmentResult['some_feature_non_existant']['treatment']);
408408
}
409409

410+
public function testGetTreatmenstConfigWithNullFeatures()
411+
{
412+
$splitSdk = $this->getFactoryClient();
413+
414+
$logger = $this->getMockedLogger();
415+
416+
$logger->expects($this->once())
417+
->method('critical')
418+
->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.'));
419+
420+
$treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", null);
421+
$this->assertEquals(array(), $treatmentResult);
422+
}
423+
424+
public function testGetTreatmenstConfigWithEmptyFeatures()
425+
{
426+
$splitSdk = $this->getFactoryClient();
427+
428+
$logger = $this->getMockedLogger();
429+
430+
$logger->expects($this->once())
431+
->method('critical')
432+
->with($this->equalTo('getTreatmentsWithConfig: featureNames must be a non-empty array.'));
433+
434+
$treatmentResult = $splitSdk->getTreatmentsWithConfig("some_key", array());
435+
$this->assertEquals(array(), $treatmentResult);
436+
}
437+
410438
public static function tearDownAfterClass(): void
411439
{
412440
Utils\Utils::cleanCache();

0 commit comments

Comments
 (0)