Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
aa34e8b
fix version string
eli-darkly Jul 16, 2018
6a08f47
Merge pull request #26 from launchdarkly/3.2.1
eli-darkly Jul 16, 2018
0d4fc33
add new version of allFlags() that captures more metadata
eli-darkly Aug 20, 2018
0f76969
linter
eli-darkly Aug 20, 2018
9023ea6
missing array key guard
eli-darkly Aug 21, 2018
e215364
missing array key guards
eli-darkly Aug 21, 2018
30e9e3c
use the standard method for specifying custom JSON serialization
eli-darkly Aug 21, 2018
775f0a1
indents
eli-darkly Aug 21, 2018
c1ac079
Merge pull request #27 from launchdarkly/eb/ch22308/all-flags-state
eli-darkly Aug 21, 2018
2f80b4c
add ability to filter for client-side flags only
eli-darkly Aug 21, 2018
fd08375
fix test to fill in all required flag fields
eli-darkly Aug 21, 2018
42c1ff2
Merge pull request #28 from launchdarkly/eb/ch12124/client-side-filter
eli-darkly Aug 22, 2018
2e9829c
implement evaluation with explanations
eli-darkly Aug 24, 2018
5d8e2b0
add another evaluation test
eli-darkly Aug 24, 2018
1977097
linter
eli-darkly Aug 24, 2018
54759db
fix test method
eli-darkly Aug 25, 2018
5038b0d
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Aug 25, 2018
87417f1
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Aug 27, 2018
07eb1a7
Merge branch 'explanation' into eb/ch19976/explanations
eli-darkly Aug 29, 2018
39d5105
fix for ch22995 - include prereq value in event even if prereq is off
eli-darkly Aug 29, 2018
8391618
Merge pull request #29 from launchdarkly/eb/ch19976/explanations
eli-darkly Sep 4, 2018
180679f
cache flag data in allFlags
eli-darkly Sep 24, 2018
15720d0
rm unused imports
eli-darkly Sep 24, 2018
dd7f268
Merge pull request #30 from launchdarkly/eb/ch24369/all-flags-caching
eli-darkly Sep 25, 2018
08572c9
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Sep 25, 2018
d3c3932
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Sep 26, 2018
a2598c7
add option to reduce front-end metadata for untracked flags
eli-darkly Oct 5, 2018
78ed55f
Merge pull request #31 from launchdarkly/eb/ch24449/less-metadata
eli-darkly Nov 8, 2018
440a2ad
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Nov 21, 2018
7543cf3
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Nov 26, 2018
37e7eaf
add ability to load flags from a file
eli-darkly Jan 10, 2019
4b2f9ef
linter
eli-darkly Jan 10, 2019
226fd95
data completeness
eli-darkly Jan 10, 2019
e997d9f
more data fixes
eli-darkly Jan 10, 2019
804a170
more data fixes
eli-darkly Jan 10, 2019
5f74cb2
more data fixes
eli-darkly Jan 10, 2019
4587c04
readme link
eli-darkly Jan 10, 2019
4ae2bd9
rm unused parameters
eli-darkly Jan 10, 2019
529ec43
fix incorrect doc comment
eli-darkly Jan 10, 2019
96dc0b4
add DynamoDB integration
eli-darkly Jan 23, 2019
ea3268e
fix test config
eli-darkly Jan 23, 2019
5da57f3
fix string check
eli-darkly Jan 23, 2019
aa62488
readme
eli-darkly Jan 23, 2019
d8bcfbb
fix test data
eli-darkly Jan 23, 2019
895aa33
factor out base class, implement caching, make configuration simpler
eli-darkly Jan 23, 2019
10662d5
fix comment
eli-darkly Jan 23, 2019
2ee0e9e
rm unused const
eli-darkly Jan 23, 2019
1eeb153
can't scope constants
eli-darkly Jan 23, 2019
c82b7c7
linter
eli-darkly Jan 23, 2019
6aead62
add Consul integration
eli-darkly Jan 23, 2019
3887732
typo
eli-darkly Jan 24, 2019
10e0daf
regenerate lockfile using PHP 5.5
eli-darkly Jan 24, 2019
2ea5c52
Merge pull request #32 from launchdarkly/eb/ch26319/file-data-source
eli-darkly Jan 24, 2019
200229c
we need at least version 2.1 of the Consul package
eli-darkly Jan 24, 2019
1a7cd19
update lockfile
eli-darkly Jan 24, 2019
d2461d2
Merge branch 'master' into eb/ch28330/dynamodb
eli-darkly Jan 24, 2019
dd92f7f
Merge branch 'eb/ch28330/dynamodb' into eb/ch28432/consul
eli-darkly Jan 24, 2019
313a473
rm comment
eli-darkly Jan 24, 2019
2580f6f
remove lockfile
eli-darkly Jan 24, 2019
72f0ac8
add delay for creating test table
eli-darkly Jan 24, 2019
546bc1c
Merge branch 'eb/ch28330/dynamodb' into eb/ch28432/consul
eli-darkly Jan 24, 2019
fd536a5
move feature requester code into Integrations namespace
eli-darkly Jan 24, 2019
a8c1647
linter
eli-darkly Jan 24, 2019
f192e9a
misc test fixes
eli-darkly Jan 24, 2019
d1a2e41
Merge pull request #35 from launchdarkly/eb/ch30532/lockfile
eli-darkly Jan 25, 2019
c7f98fd
fix apc/apcu calls
eli-darkly Jan 25, 2019
9ff5c89
Merge branch 'master' into eb/ch28330/dynamodb
eli-darkly Jan 25, 2019
088aef2
Merge pull request #33 from launchdarkly/eb/ch28330/dynamodb
eli-darkly Jan 25, 2019
6f05a0f
Merge branch 'master' into eb/ch28432/consul
eli-darkly Jan 25, 2019
a49b3c1
fix comment
eli-darkly Jan 25, 2019
22498a0
Merge branch 'eb/ch28432/consul' into eb/ch30533/feature-requesters
eli-darkly Jan 25, 2019
24cf9e0
fix deprecated caching store classes
eli-darkly Jan 25, 2019
a9100fc
better caching abstraction
eli-darkly Jan 25, 2019
80a653b
typo
eli-darkly Jan 25, 2019
47c1bc2
linter
eli-darkly Jan 25, 2019
f6cf050
fix namespaces
eli-darkly Jan 25, 2019
55dd858
fix tests
eli-darkly Jan 25, 2019
17cca84
Merge pull request #36 from launchdarkly/eb/ch28432/consul
eli-darkly Jan 25, 2019
528fc91
doc fixes
eli-darkly Jan 25, 2019
68c81fb
move a bunch more stuff
eli-darkly Jan 26, 2019
613f881
misc cleanup
eli-darkly Jan 26, 2019
6d37fdd
add test for not having any flags
eli-darkly Jan 26, 2019
4014e19
restore documentation for deprecated properties
eli-darkly Jan 31, 2019
15b780d
Merge pull request #37 from launchdarkly/eb/ch30533/feature-requesters
eli-darkly Jan 31, 2019
86bc30f
version 3.5.0
eli-darkly Jan 31, 2019
5d092f0
Merge branch 'master' of github.com:launchdarkly/php-client
eli-darkly Feb 6, 2019
9c589d1
revert accidental commit
eli-darkly Feb 27, 2019
f533573
Merge commit 'b34a45325c615db18fde2038ea3e627e9d6d80ff'
eli-darkly Mar 13, 2019
87dadb3
Hr/ch34492/waitonconsul (#39)
hroederld Mar 26, 2019
30f10c8
coerce user attributes to strings when necessary, don't send events w…
eli-darkly Apr 2, 2019
2d3120b
explanatory comments
eli-darkly Apr 3, 2019
1f6cd8b
Merge pull request #40 from launchdarkly/eb/ch35189-35206/stringify-a…
eli-darkly Apr 3, 2019
22bdf25
prepare 3.5.1 release
eli-darkly Apr 3, 2019
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
9 changes: 8 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
sudo apt-get -q update &&
sudo apt-cache policy docker-ce &&
sudo apt-get -qy install docker-ce
- run: sudo apt-get -qy install redis-server
- run: sudo apt-get -qy install redis-server curl
- checkout
- run:
name: validate composer.json
Expand All @@ -109,6 +109,13 @@ jobs:
name: start Consul
command: ./consul agent -dev
background: true
- run:
name: wait on Consul
command: |
until $(curl --output /dev/null --silent --fail --request PUT --data 'test' http://localhost:8500/v1/kv/initchecker); do
echo 'still waiting on Consul...'; sleep 2;
done
timeout: 50
- run:
name: run tests
command: vendor/bin/phpunit --log-junit ~/phpunit/junit.xml --coverage-text tests
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to the LaunchDarkly PHP SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [3.5.1] - 2019-04-03
### Fixed:
- Setting user attributes to non-string values when a string was expected would cause analytics events not to be processed. The SDK will now convert attribute values to strings as needed.
- If `track` or `identify` is called without a user, the SDK now logs a warning, and does not send an analytics event to LaunchDarkly (since it would not be processed without a user).

## [3.5.0] - 2019-01-30
### Added:
- It is now possible to use Consul or DynamoDB as a data store with `ld-relay`, similar to the existing Redis integration. See `LaunchDarkly\Integrations\Consul` and `LaunchDarkly\Integrations\DynamoDb`, and the reference guide [Using a persistent feature store](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.0
3.5.1
16 changes: 9 additions & 7 deletions src/LaunchDarkly/EventSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function filterEvent($e)
return $ret;
}

private function filterAttrs($attrs, &$json, $userPrivateAttrs, &$allPrivateAttrs)
private function filterAttrs($attrs, &$json, $userPrivateAttrs, &$allPrivateAttrs, $stringify)
{
foreach ($attrs as $key => $value) {
if ($value != null) {
Expand All @@ -46,15 +46,15 @@ private function filterAttrs($attrs, &$json, $userPrivateAttrs, &$allPrivateAttr
array_search($key, $this->_privateAttrNames) !== false) {
$allPrivateAttrs[$key] = true;
} else {
$json[$key] = $value;
$json[$key] = $stringify ? strval($value) : $value;
}
}
}
}

private function serializeUser($user)
{
$json = array("key" => $user->getKey());
$json = array("key" => strval($user->getKey()));
$userPrivateAttrs = $user->getPrivateAttributeNames();
$allPrivateAttrs = array();

Expand All @@ -66,13 +66,15 @@ private function serializeUser($user)
'name' => $user->getName(),
'avatar' => $user->getAvatar(),
'firstName' => $user->getFirstName(),
'lastName' => $user->getLastName(),
'anonymous' => $user->getAnonymous()
'lastName' => $user->getLastName()
);
$this->filterAttrs($attrs, $json, $userPrivateAttrs, $allPrivateAttrs);
$this->filterAttrs($attrs, $json, $userPrivateAttrs, $allPrivateAttrs, true);
if ($user->getAnonymous()) {
$json['anonymous'] = true;
}
if (!empty($user->getCustom())) {
$customs = array();
$this->filterAttrs($user->getCustom(), $customs, $userPrivateAttrs, $allPrivateAttrs);
$this->filterAttrs($user->getCustom(), $customs, $userPrivateAttrs, $allPrivateAttrs, false);
if ($customs) { // if this is empty, we will return a json array for 'custom' instead of an object
$json['custom'] = $customs;
}
Expand Down
4 changes: 3 additions & 1 deletion src/LaunchDarkly/LDClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public function track($eventName, $user, $data)
}
if (is_null($user) || $user->isKeyBlank()) {
$this->_logger->warning("Track called with null user or null/empty user key!");
return;
}

$event = array();
Expand All @@ -293,13 +294,14 @@ public function identify($user)
}
if (is_null($user) || $user->isKeyBlank()) {
$this->_logger->warning("Track called with null user or null/empty user key!");
return;
}

$event = array();
$event['user'] = $user;
$event['kind'] = "identify";
$event['creationDate'] = Util::currentTimeUnixMillis();
$event['key'] = $user->getKey();
$event['key'] = strval($user->getKey());
$this->_eventProcessor->enqueue($event);
}

Expand Down
2 changes: 1 addition & 1 deletion src/LaunchDarkly/VariationOrRollout.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function bucketUser($user, $_key, $attr, $_salt)
if (is_string($userValue)) {
$idHash = $userValue;
if ($user->getSecondary() !== null) {
$idHash = $idHash . "." . $user->getSecondary();
$idHash = $idHash . "." . strval($user->getSecondary());
}
$hash = substr(sha1($_key . "." . $_salt . "." . $idHash), 0, 15);
$longVal = base_convert($hash, 16, 10);
Expand Down
56 changes: 46 additions & 10 deletions tests/EventSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testUserKey()
$builder = new LDUserBuilder("[email protected]");
$user = $builder->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("[email protected]", $json['key']);
$this->assertSame("[email protected]", $json['key']);
}

public function testEmptyCustom()
Expand All @@ -150,70 +150,106 @@ public function testUserSecondary()
$builder = new LDUserBuilder("[email protected]");
$user = $builder->secondary("secondary")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("secondary", $json['secondary']);
$this->assertSame("secondary", $json['secondary']);
}

public function testUserIP()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->ip("127.0.0.1")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("127.0.0.1", $json['ip']);
$this->assertSame("127.0.0.1", $json['ip']);
}

public function testUserCountry()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->country("US")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("US", $json['country']);
$this->assertSame("US", $json['country']);
}

public function testUserEmail()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->email("[email protected]")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("[email protected]", $json['email']);
$this->assertSame("[email protected]", $json['email']);
}

public function testUserName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->name("Foo Bar")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Foo Bar", $json['name']);
$this->assertSame("Foo Bar", $json['name']);
}

public function testUserAvatar()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->avatar("http://www.gravatar.com/avatar/1")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("http://www.gravatar.com/avatar/1", $json['avatar']);
$this->assertSame("http://www.gravatar.com/avatar/1", $json['avatar']);
}

public function testUserFirstName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->firstName("Foo")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Foo", $json['firstName']);
$this->assertSame("Foo", $json['firstName']);
}

public function testUserLastName()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->lastName("Bar")->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals("Bar", $json['lastName']);
$this->assertSame("Bar", $json['lastName']);
}

public function testUserAnonymous()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->anonymous(true)->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertEquals(true, $json['anonymous']);
$this->assertSame(true, $json['anonymous']);
}

public function testUserNotAnonymous()
{
$builder = new LDUserBuilder("[email protected]");
$user = $builder->anonymous(false)->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertFalse(isset($json['anonymous'])); // omitted rather than set to false, for efficiency
}

public function testNonStringAttributes()
{
$builder = new LDUserBuilder(1);
$user = $builder->secondary(2)
->ip(3)
->country(4)
->email(5)
->name(6)
->avatar(7)
->firstName(8)
->lastName(9)
->anonymous(true)
->customAttribute('foo', 10)
->build();
$json = $this->getJsonForUserBySerializingEvent($user);
$this->assertSame('1', $json['key']);
$this->assertSame('2', $json['secondary']);
$this->assertSame('3', $json['ip']);
$this->assertSame('4', $json['country']);
$this->assertSame('5', $json['email']);
$this->assertSame('6', $json['name']);
$this->assertSame('7', $json['avatar']);
$this->assertSame('8', $json['firstName']);
$this->assertSame('9', $json['lastName']);
$this->assertSame(true, $json['anonymous']); // We do NOT want "anonymous" to be stringified
$this->assertSame(10, $json['custom']['foo']); // We do NOT want custom attribute values to be stringified
}
}
31 changes: 31 additions & 0 deletions tests/FeatureFlagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,37 @@ public function testFlagReturnsErrorIfRuleHasRolloutWithNoVariations()
self::assertEquals(array(), $result->getPrerequisiteEvents());
}

public function testSecondaryKeyIsCoercedToStringForRolloutCalculation()
{
// We can't really verify that the rollout calculation works correctly, but we can at least
// make sure it doesn't error out if there's a non-string secondary value (ch35189)
$flag = $this->makeBooleanFlagWithRules(array(
array(
'id' => 'ruleid',
'clauses' => array(
array('attribute' => 'key', 'op' => 'in', 'values' => array('userkey'), 'negate' => false)
),
'rollout' => array(
'salt' => '',
'variations' => array(
array(
'weight' => 100000,
'variation' => 1
)
)
)
)
));
$ub = new LDUserBuilder('userkey');
$ub->secondary(999);
$user = $ub->build();

$result = $flag->evaluate($user, null);
$detail = new EvaluationDetail(true, 1, EvaluationReason::ruleMatch(0, 'ruleid'));
self::assertEquals($detail, $result->getDetail());
self::assertEquals(array(), $result->getPrerequisiteEvents());
}

public function clauseCanMatchBuiltInAttribute()
{
$clause = array('attribute' => 'name', 'op' => 'in', 'values' => array('Bob'), 'negate' => false);
Expand Down
8 changes: 4 additions & 4 deletions tests/LDClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ public function testVariationSendsEvent()

public function testVariationDetailSendsEvent()
{
$flag = $this->makeOffFlagWithValue('FUCKINGWEIRDflagkey', 'flagvalue');
MockFeatureRequester::$flags = array('FUCKINGWEIRDflagkey' => $flag);
$flag = $this->makeOffFlagWithValue('flagkey', 'flagvalue');
MockFeatureRequester::$flags = array('flagkey' => $flag);
$client = new LDClient("someKey", array(
'feature_requester_class' => MockFeatureRequester::class,
'events' => true
));

$user = new LDUser('userkey');
$client->variationDetail('FUCKINGWEIRDflagkey', $user, 'default');
$client->variationDetail('flagkey', $user, 'default');
$proc = $this->getPrivateField($client, '_eventProcessor');
$queue = $this->getPrivateField($proc, '_queue');
$this->assertEquals(1, sizeof($queue));
$event = $queue[0];
$this->assertEquals('feature', $event['kind']);
$this->assertEquals('FUCKINGWEIRDflagkey', $event['key']);
$this->assertEquals('flagkey', $event['key']);
$this->assertEquals($flag->getVersion(), $event['version']);
$this->assertEquals('flagvalue', $event['value']);
$this->assertEquals(1, $event['variation']);
Expand Down