Skip to content

Commit 61eba47

Browse files
LaunchDarklyReleaseBoteli-darklyhroederldLaunchDarklyCIbwoskow-ld
authored
prepare 4.2.0 release (#158)
* fix version string * add new version of allFlags() that captures more metadata * linter * missing array key guard * missing array key guards * use the standard method for specifying custom JSON serialization * indents * add ability to filter for client-side flags only * fix test to fill in all required flag fields * implement evaluation with explanations * add another evaluation test * linter * fix test method * fix for ch22995 - include prereq value in event even if prereq is off * cache flag data in allFlags * rm unused imports * add option to reduce front-end metadata for untracked flags * add ability to load flags from a file * linter * data completeness * more data fixes * more data fixes * more data fixes * readme link * rm unused parameters * fix incorrect doc comment * add DynamoDB integration * fix test config * fix string check * readme * fix test data * factor out base class, implement caching, make configuration simpler * fix comment * rm unused const * can't scope constants * linter * add Consul integration * typo * regenerate lockfile using PHP 5.5 * we need at least version 2.1 of the Consul package * update lockfile * rm comment * remove lockfile * add delay for creating test table * move feature requester code into Integrations namespace * linter * misc test fixes * fix apc/apcu calls * fix comment * fix deprecated caching store classes * better caching abstraction * typo * linter * fix namespaces * fix tests * doc fixes * move a bunch more stuff * misc cleanup * add test for not having any flags * restore documentation for deprecated properties * version 3.5.0 * revert accidental commit * add experimentation event overrides for rules and fallthrough * linter * misc fixes * misc test fixes * Hr/ch34492/waitonconsul (#39) * add step to wait on Consul * coerce user attributes to strings when necessary, don't send events without valid users * explanatory comments * add release script (version update only) * use newer readme footer format * support metric value in track() * linter * update method description * add param to skip db tests, update docs for new repo name * wrong method name * add tests for rollout calculations, + misc test cleanup * misc doc fixes * misc doc fixes * update package name (#45) * add test for cached get all * typo * revert bugfix to test the test * reinstate bugfix * mix fixes, rename file * fix filename * misc cleanup * linter * misc fixes * test state cleanup * linter + fix filename in instructions * misc CI fixes, don't try to install phpredis in 5.6 * don't let user fall outside of last bucket in rollout * PHP 5.5 requires even null properties to be defined * minor cleanup * more accurate changelog text regarding phpredis * Add circle jobs for newer PHP versions. * Revert "Add circle jobs for newer PHP versions." This reverts commit 8939cb2. * implement doc generation with phpDocumentor 3 (prerelease), clean up doc tags (#50) * Add CI jobs for PHP 7.3 + 7.4 (#51) * ensure events aren't sent if send_events is false * clarify test with comment * make prefix concatenation in DynamoDB consistent with other SDKs * fix test * fix PHP 5.5 CI build by pinning Composer version (#54) * Updating warning log in Identify to not say Track was called (#56) * Removed the guides link * add alias functionality and some related tests * Revert "add alias functionality and some related tests" This reverts commit 2bf1cba. * add alias events support (#57) * add alias function to LDClient * add `contextKind` to events that require the new field * add tests for alias and contextKind * merge exp-alloc * drop support for EOL php versions and update deps (#60) * fix test class * remove database integrations from SDK (#63) * add type hints to FeatureRequesterBase methods * fix PHPRedis logic for prefix & custom client, add unit tests (#64) * add psalm lints and php hints (#62) * remove deprecated members (#65) * change default base URL to sdk.launchdarkly.com * move non-public classes into Impl namespace (#66) * add CI job for PHP 8.0 (#69) * use phpDocumentor 3 + misc doc comment cleanup (#68) * Updates docs URLs * pin Psalm to 4.9.2 to prevent a spurious linting error (#71) * use Releaser v2 config + add badge links in readme (#72) * use Releaser v2 config + add badge links in readme * fix badge URL * use Releaser PHP project template (#73) * use Releaser PHP project template * exclude implementation classes from docs * remove obsolete line that's no longer used because $seed is computed elsewhere * remove obsolete VERSION file * Fix test confirming send_events = false is honored (#78) * Minor cleanup and consistency changes (#79) * Add integration test for curl event publisher (#77) * Curl honor connect_timeout (#81) * Set required connect_timeout option in test (#82) * Add Windows support for "Curl" publisher (#80) * Add cs-check to build process (#83) * Don't treat numeric strings as numbers (#84) * Decrease psalm error level (#85) * added TestData, FlagBuilder; added TestDataTest; started implementing FlagBuilder methods * made props protected, made basic build method, made variations method with tests * continued implementing test data and tests for test data * implemented varationForAllUsers, valueForAllUsers, and variationForUsers along with corresponding tests * reorganized functions, added needed classes and functions, left some bodys blank to complete later, implemeted others, organized tests, added missing assertions * broken - transitioning build to return a FeatureFlag, finished implementing some methods * reverted build to return array, implemented getFeature and getAllFeatures methods in FeatureRequester interface for TestData * fixed build, implemented FeatureRequester, added simple test case * Event attribute filtering is overly aggressively (#86) If you try to create a custom attribute with a value of 0, our event serialization code would filter that out because `0 != null` is false. However, it is reasonable to expect that a user might want to provide the value of 0 as a custom value. The code has been updated to only exclude explicitly null values. * Account for traffic allocation on all flags (#87) * finished FlagRuleBuilder implementation; fixed psalm errors; improved comment blocks to adhere better to phpdoc; fixed formatting errors in both TestData and TestDataTest * fixed php-cs-fixer warnings in TestDataTest.php * Apply suggestions from code review Co-authored-by: Matthew M. Keeler <[email protected]> * replace use of array_push with append operator; standardized capitalization of booleans including in code blogs; other formatting adjustments * remove array_splice() implementation of existing user key removal due to breakage in unit tests * converted variationForUser to use array_splice but fixed issue caused by pass by reference instead of pass by value * fixed missing indexes required to decode FlagBuilder into a FeatureFlag using the decode() method * split off TestData\FlagBuilder and TestData\FlagRuleBuilder from TestData; add test coverage for TestData class * additional cleanup; added missing type hint; minor refactoring * remove special handling of singleton arrays in FlagBuilder::variations() * run php-cs-fixer on TestData-related files * started writing repetitive tests using the phpunit @dataProvider feature * swapped positions of expected and actual in dataProvider-driven test * fix typos in code in comment blocks * Apply whitespace fixes from code review Co-authored-by: Matthew M. Keeler <[email protected]> * split unwieldy tests in TestDataTest into separate tests; address TODO item * added annotations to dataProvider-driven tests * changed _isBooleanFlag() implementation to use strict equality * Add unit test to verify `in` operator in TestData (#89) * Add support for psr/log 2 and 3 (#91) Co-authored-by: Eli Bishop <[email protected]> Co-authored-by: Eli Bishop <[email protected]> Co-authored-by: hroederld <[email protected]> Co-authored-by: LaunchDarklyCI <[email protected]> Co-authored-by: Ben Woskow <[email protected]> Co-authored-by: Ben Woskow <[email protected]> Co-authored-by: Gavin Whelan <[email protected]> Co-authored-by: elliot <[email protected]> Co-authored-by: Elliot Haisley <[email protected]> Co-authored-by: Harpo Roeder <[email protected]> Co-authored-by: LaunchDarklyReleaseBot <[email protected]> Co-authored-by: Ember Stevens <[email protected]> Co-authored-by: ember-stevens <[email protected]> Co-authored-by: Matthew M. Keeler <[email protected]> Co-authored-by: charukiewicz <[email protected]> Co-authored-by: Joey Malinowski <[email protected]> Co-authored-by: Christian Charukiewicz <[email protected]> Co-authored-by: Matthew M. Keeler <[email protected]>
1 parent 278a8e1 commit 61eba47

File tree

5 files changed

+1162
-1
lines changed

5 files changed

+1162
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require": {
1717
"php": ">=7.3",
1818
"monolog/monolog": "^1.6|^2.0",
19-
"psr/log": "^1.0"
19+
"psr/log": "^1.0|^2.0|^3.0"
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": ">=2.2.19 <3.0",
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
namespace LaunchDarkly\Integrations;
4+
5+
use LaunchDarkly\FeatureRequester;
6+
use LaunchDarkly\Impl\Model\FeatureFlag;
7+
use LaunchDarkly\Impl\Model\Segment;
8+
use LaunchDarkly\Integrations\TestData\FlagBuilder;
9+
10+
class TestData implements FeatureRequester
11+
{
12+
/** @var array */
13+
protected $_flagBuilders;
14+
/** @var array */
15+
protected $_currentFlags;
16+
17+
public function __construct()
18+
{
19+
$this->_flagBuilders = [];
20+
$this->_currentFlags = [];
21+
}
22+
23+
/**
24+
* Gets the configuration for a specific feature flag.
25+
*
26+
* @param string $key feature key
27+
* @return FeatureFlag|null The decoded FeatureFlag, or null if missing
28+
*/
29+
public function getFeature(string $key): ?FeatureFlag
30+
{
31+
return $this->_currentFlags[$key] ?? null;
32+
}
33+
34+
/**
35+
* Gets the configuration for a specific user segment.
36+
*
37+
* @param string $key segment key
38+
* @return Segment|null The decoded Segment, or null if missing
39+
*/
40+
public function getSegment(string $key): ?Segment
41+
{
42+
return null;
43+
}
44+
45+
/**
46+
* Gets all feature flags.
47+
*
48+
* @return array<string, FeatureFlag>|null The decoded FeatureFlags, or null if missing
49+
*/
50+
public function getAllFeatures(): ?array
51+
{
52+
return $this->_currentFlags;
53+
}
54+
55+
/**
56+
* Creates a new instance of the test data source
57+
*
58+
* @return TestData a new configurable test data source
59+
*/
60+
public function dataSource(): TestData
61+
{
62+
return new TestData();
63+
}
64+
65+
/**
66+
* Creates or copies a `FlagBuilder` for building a test flag configuration.
67+
*
68+
* If this flag key has already been defined in this `TestData` instance, then the builder
69+
* starts with the same configuration that was last provided for this flag.
70+
*
71+
* Otherwise, it starts with a new default configuration in which the flag has `true` and
72+
* `false` variations, is `true` for all users when targeting is turned on and
73+
* `false` otherwise, and currently has targeting turned on. You can change any of those
74+
* properties, and provide more complex behavior, using the `FlagBuilder` methods.
75+
*
76+
* Once you have set the desired configuration, pass the builder to `update`.
77+
*
78+
* @param string $key the flag key
79+
* @return FlagBuilder the flag configuration builder object
80+
*/
81+
public function flag(string $key): FlagBuilder
82+
{
83+
if (isset($this->_flagBuilders[$key])) {
84+
return $this->_flagBuilders[$key]->copy();
85+
} else {
86+
$flagBuilder = new FlagBuilder($key);
87+
return $flagBuilder->booleanFlag();
88+
}
89+
}
90+
91+
/**
92+
* Updates the test data with the specified flag configuration.
93+
*
94+
* This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard.
95+
* It immediately propagates the flag change to any `LDClient` instance(s) that you have
96+
* already configured to use this `TestData`. If no `LDClient` has been started yet,
97+
* it simply adds this flag to the test data which will be provided to any `LDClient` that
98+
* you subsequently configure.
99+
*
100+
* Any subsequent changes to this `FlagBuilder` instance do not affect the test data,
101+
* unless you call `update(FlagBuilder)` again.
102+
*
103+
* @param FlagBuilder $flagBuilder a flag configuration builder
104+
* @return TestData the same `TestData` instance
105+
*/
106+
public function update(FlagBuilder $flagBuilder): TestData
107+
{
108+
$key = $flagBuilder->getKey();
109+
$oldVersion = 0;
110+
111+
$oldFlag = $this->_currentFlags[$key] ?? null;
112+
if ($oldFlag) {
113+
$oldVersion = $oldFlag['version'];
114+
}
115+
116+
$newFlag = $flagBuilder->build($oldVersion + 1);
117+
$newFeatureFlag = FeatureFlag::decode($newFlag);
118+
$this->_currentFlags[$key] = $newFeatureFlag;
119+
$this->_flagBuilders[$key] = $flagBuilder->copy();
120+
return $this;
121+
}
122+
}

0 commit comments

Comments
 (0)