Skip to content

Commit

Permalink
fix: changelog update [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamg1304 authored and rohitesh-wingify committed Jul 17, 2024
1 parent 764e9d0 commit a34d56b
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 63 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


[1.2.1] - 2024-07-17
### Added

- Support for optional parameter SettingsFile in init
- Support for gt,gte,lt,lte in Custom Variable pre-segmentation


[1.1.1] - 2024-07-04
### Changed
- **Testing**
- PHPUnit version changed to support in lower php versions


[1.1.0] - 2024-07-02
### Changed
- **Refactoring**

- Redesigned models to use private properties instead of public properties.
- Implemented object notation with getter and setter functions for all models.

- **Unit and E2E Testing**

- Set up Test framework using `Jest`
- Wrote unit and E2E tests to ensure nothing breaks while pushing new code
- Ensure criticla components are working properly on every build


[1.0.0] - 2024-06-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vwo/vwo-fme-php-sdk",
"version": "1.2.0",
"version": "1.2.1",
"keywords": ["vwo", "fme", "sdk"],
"license": "Apache-2.0",
"authors": [{
Expand Down
53 changes: 35 additions & 18 deletions src/Api/GetFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

interface IGetFlag
{
public function get($featureKey, $settings, $context, $hookManager);
public function get($featureKey, $settings, $context, $hookManager, $settingsFilePassedInOptions = false);
}

class GetFlag implements IGetFlag
{
public function get($featureKey, $settings, $context, $hookManager)
public function get($featureKey, $settings, $context, $hookManager, $settingsFilePassedInOptions = false)
{
// initialize contextUtil object
$decision = $this->createDecision($settings, $featureKey, $context);
Expand All @@ -51,7 +51,7 @@ public function get($featureKey, $settings, $context, $hookManager)
$rulesInformation = []; // for storing and integration callback
$evaluatedFeatureMap = array();
$shouldCheckForAbPersonalise = false;

$ruleStatus = [];

$storageService = new StorageService();
$storedData = (new StorageDecorator())->getFeatureFromStorage(
Expand All @@ -74,7 +74,8 @@ public function get($featureKey, $settings, $context, $hookManager)
);
return new GetFlagResultUtil(
true,
$variation->getVariables()
$variation->getVariables(),
$ruleStatus
);
}
}
Expand Down Expand Up @@ -106,22 +107,26 @@ public function get($featureKey, $settings, $context, $hookManager)
$feature = FunctionUtil::getFeatureFromKey($settings, $featureKey);
if (!is_object($feature) || $feature === null) {
LogManager::instance()->info("Feature not found for the key {$featureKey}");
return new GetFlagResultUtil(false, []);
return new GetFlagResultUtil(false, [], $ruleStatus);
}

$rollOutRules = FunctionUtil::getSpecificRulesBasedOnType($settings, $featureKey, CampaignTypeEnum::ROLLOUT);

if (count($rollOutRules) > 0 && !$isEnabled) {
foreach ($rollOutRules as $rule) {
$evaluateRuleResult = $this->evaluateRule($settings, $feature, $rule, $context, false, $decision);

$evaluateRuleResult = $this->evaluateRule($settings, $feature, $rule, $context, false, $decision, $settingsFilePassedInOptions);
if ($evaluateRuleResult[0]) {
$ruleToTrack[] = $rule;
$evaluatedFeatureMap[$featureKey] = [
'rolloutId' => $rule->getId(),
'rolloutKey' => $rule->getKey(),
'rolloutVariationId' => $rule->getVariations()[0]->getId()
];
$ruleStatus[$rule->getRuleKey()] = "Passed";
break;
} else {
$ruleStatus[$rule->getRuleKey()] = "Failed";
}
continue;
}
Expand All @@ -133,7 +138,7 @@ public function get($featureKey, $settings, $context, $hookManager)
if (count($ruleToTrack) > 0) {
$ruleElement = array_pop($ruleToTrack);
$campaign = $ruleElement;
$variation = $this->trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, $rulesInformation, $decision);
$variation = $this->trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, $rulesInformation, $decision, $settingsFilePassedInOptions);

if (DataTypeUtil::isObject($variation)) {
$isEnabled = true;
Expand Down Expand Up @@ -257,7 +262,8 @@ public function get($featureKey, $settings, $context, $hookManager)
$rule,
$context,
false,
$decision
$decision,
$settingsFilePassedInOptions
);

if ($abPersonalizeResult) {
Expand All @@ -272,7 +278,10 @@ public function get($featureKey, $settings, $context, $hookManager)
'experimentVariationId' => $whitelistedVariation['variationId']
]);
}
$ruleStatus[$rule->getRuleKey()] = "Passed";
break;
} else {
$ruleStatus[$rule->getRuleKey()] = "Failed";
}
$campaignToSkip[] = $rule->getId();
continue;
Expand All @@ -282,7 +291,7 @@ public function get($featureKey, $settings, $context, $hookManager)
if (count($ruleToTrack) > 0) {
$ruleElement = array_pop($ruleToTrack);
$campaign = $ruleElement;
$variation = $this->trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, $rulesInformation, $decision);
$variation = $this->trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, $rulesInformation, $decision, $settingsFilePassedInOptions);

if ($variation !== null) {
$isEnabled = true;
Expand All @@ -299,13 +308,19 @@ public function get($featureKey, $settings, $context, $hookManager)
$hookManager->execute($hookManager->get());
}

if ($feature->getImpactCampaign()->getcampaignId()) {
if ($feature->getImpactCampaign()->getcampaignId() && !$settingsFilePassedInOptions) {
$campaign = new \vwo\Models\CampaignModel();
$campaign->setId($feature->getImpactCampaign()->getCampaignId());

$variation = new \vwo\Models\VariationModel();
$variation->setId($isEnabled ? 2 : 1);

$this->createImpressionForVariationShown(
$settings,
$feature,
['id' => $feature->impactCampaign->campaignId],
$campaign,
$context['user'],
['id' => $isEnabled ? 2 : 1],
$variation,
true
);
}
Expand All @@ -317,7 +332,7 @@ public function get($featureKey, $settings, $context, $hookManager)
$variables = $rolloutVariationToReturn->getVariables() ?? null;
}

return new GetFlagResultUtil($isEnabled, $variables);
return new GetFlagResultUtil($isEnabled, $variables, $ruleStatus);
}

private function createDecision($settings, $featureKey, $context)
Expand All @@ -331,7 +346,7 @@ private function createDecision($settings, $featureKey, $context)
];
}

private function trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, &$rulesInformation, &$decision)
private function trafficCheckAndReturnVariation($settings, $feature, $campaign, $context, &$rulesInformation, &$decision, $settingsFilePassedInOptions)
{
$variation = DecisionUtil::evaluateTrafficAndGetVariation($settings, $campaign, $context['user']['id']);

Expand All @@ -355,7 +370,8 @@ private function trafficCheckAndReturnVariation($settings, $feature, $campaign,
$decision = array_merge($decision, $rulesInformation);

// Assuming createImpressionForVariationShown() accepts objects for $campaign and $variation
$this->createImpressionForVariationShown($settings, $feature, $campaign, $context['user'], $variation);
if (!$settingsFilePassedInOptions)
$this->createImpressionForVariationShown($settings, $feature, $campaign, $context['user'], $variation);

return $variation;
}
Expand All @@ -369,7 +385,7 @@ private function trafficCheckAndReturnVariation($settings, $feature, $campaign,
* @param user user object
* @returns
*/
public function evaluateRule($settings, $feature, $campaign, $context, $isMegWinnerRule, &$decision)
public function evaluateRule($settings, $feature, $campaign, $context, $isMegWinnerRule, &$decision, $settingsFilePassedInOptions = false)
{
// check for whitelisting and pre segmentation
$result = DecisionUtil::checkWhitelistingAndPreSeg(
Expand All @@ -389,12 +405,13 @@ public function evaluateRule($settings, $feature, $campaign, $context, $isMegWin
'experimentKey' => $campaign->getKey(),
'experimentVariationId' => $whitelistedObject->variationId,
]);
$this->createImpressionForVariationShown($settings, $feature, $campaign, $context['user'], $whitelistedObject['variation']);
if (!$settingsFilePassedInOptions)
$this->createImpressionForVariationShown($settings, $feature, $campaign, $context['user'], $whitelistedObject['variation']);
}
return [$preSegmentationResult, $whitelistedObject];
}

function createImpressionForVariationShown($settings, $feature, $campaign, $user, $variation, $isImpactCampaign = false)
function createImpressionForVariationShown($settings, $feature, $campaign, $user, $variation, $isImpactCampaign = false, $settingsFilePassedInOptions = false)
{
if (isset($user['userAgent'])) {
$userAgent = $user['userAgent'];
Expand Down
8 changes: 5 additions & 3 deletions src/Api/SetAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
use vwo\Enums\EventEnum;

interface ISetAttribute {
function setAttribute($settings, $attributeKey, $attributeValue, $context);
function setAttribute($settings, $attributeKey, $attributeValue, $context, $settingsFilePassedInOptions = false);
}

class SetAttribute implements ISetAttribute {
function setAttribute($settings, $attributeKey, $attributeValue, $context) {
createImpressionForAttribute($settings, $attributeKey, $attributeValue, $context);
function setAttribute($settings, $attributeKey, $attributeValue, $context, $settingsFilePassedInOptions = false) {
if (!$settingsFilePassedInOptions) {
createImpressionForAttribute($settings, $attributeKey, $attributeValue, $context);
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Api/TrackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@
// Interface for tracking functionality
interface ITrack
{
public function track( $settings, $eventName, $eventProperties, $context, $hookManager);
public function track( $settings, $eventName, $eventProperties, $context, $hookManager, $settingsFilePassedInOptions = false);
}

class TrackEvent implements ITrack
{
public function track( $settings, $eventName, $eventProperties, $context, $hookManager)
public function track( $settings, $eventName, $eventProperties, $context, $hookManager, $settingsFilePassedInOptions = false)
{
if (FunctionUtil::eventExists($eventName, $settings)) {
// Create impression for track
$this->createImpressionForTrack($settings, $eventName, $context['user'], $eventProperties);
if (!$settingsFilePassedInOptions) {
// Create impression for track
$this->createImpressionForTrack($settings, $eventName, $context['user'], $eventProperties);
}

// Integration callback for track
$hookManager->set([
Expand Down
10 changes: 10 additions & 0 deletions src/Models/CampaignModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CampaignModel
private $variationId;
private $campaignId;
private $weight;
private $ruleKey;

public function copy($campaignModel)
{
Expand Down Expand Up @@ -91,6 +92,7 @@ public function processCampaignKeys($campaign)
$this->segments = isset($campaign->segments) ? $campaign->segments : null;
$this->key = isset($campaign->key) ? $campaign->key : null;
$this->type = isset($campaign->type) ? $campaign->type : null;
$this->ruleKey = isset($campaign->ruleKey) ? $campaign->ruleKey : null;
}

public function getId()
Expand Down Expand Up @@ -167,6 +169,10 @@ public function getWeight()
{
return $this->weight;
}

public function getRuleKey() {
return $this->ruleKey;
}

public function setId($id)
{
Expand Down Expand Up @@ -238,4 +244,8 @@ public function setWeight($weight)
{
$this->weight = $weight;
}
public function setRuleKey($ruleKey)
{
$this->ruleKey = $ruleKey;
}
}
11 changes: 11 additions & 0 deletions src/Models/RuleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class RuleModel {
private $variationId;
private $campaignId;
private $type;
private $ruleKey;

public function modelFromDictionary($rule) {
$this->type = isset($rule->type) ? $rule->type : null;
$this->status = isset($rule->status) ? $rule->status : null;
$this->variationId = isset($rule->variationId) ? $rule->variationId : null;
$this->campaignId = isset($rule->campaignId) ? $rule->campaignId : null;
$this->ruleKey = isset($rule->ruleKey) ? $rule->ruleKey : null;
return $this;
}

Expand All @@ -48,6 +50,10 @@ public function getType() {
return $this->type;
}

public function getRuleKey() {
return $this->ruleKey;
}

public function setCampaignId($campaignId) {
$this->campaignId = $campaignId;
}
Expand All @@ -63,6 +69,11 @@ public function setStatus($status) {
public function setType($type) {
$this->type = $type;
}

public function setRuleKey($ruleKey) {
$this->ruleKey = $ruleKey;
}

}

?>
4 changes: 4 additions & 0 deletions src/Models/VariationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public function setType($type) {
$this->type = $type;
}

public function setId($id) {
$this->id = $id;
}

public function setPercentTraffic($percentTraffic) {
$this->percentTraffic = $percentTraffic;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Packages/Logger/Core/LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function handleTransports(): void {
$this->addTransport([
'level' => $this->config['level'],
'logHandler' => function ($message, $level) {
echo $message.PHP_EOL;
file_put_contents("php://stdout", $message . PHP_EOL);
}
]);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Packages/Logger/Core/LogTransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ public function log($level, $message): void {
$logHandler = $transport['logHandler'];
$logHandler($formattedMessage, $level);
} else {
if (method_exists($transport, $level)) {
$transport->{$level}($formattedMessage, $level);
}
// Use php://stdout for console logging
$this->logToConsole($level, $formattedMessage);
}
}
}
}

private function logToConsole($message) {
file_put_contents("php://stdout", $message . PHP_EOL);
}
}

?>
2 changes: 1 addition & 1 deletion src/Packages/Logger/Transports/ConsoleTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function error($message): void {

public function log($level, $message): void {
// Ensure the message is output to the console with a single newline
echo rtrim($message) . PHP_EOL;
file_put_contents("php://stdout", $message . PHP_EOL);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class SegmentOperandValueEnum {
public const ENDING_STAR_VALUE = 4;
public const REGEX_VALUE = 5;
public const EQUAL_VALUE = 6;
public const GREATER_THAN_VALUE = 7;
public const GREATER_THAN_EQUAL_TO_VALUE = 8;
public const LESS_THAN_VALUE = 9;
public const LESS_THAN_EQUAL_TO_VALUE = 10;
}

?>
Loading

0 comments on commit a34d56b

Please sign in to comment.