Skip to content

Conversation

emyller
Copy link

@emyller emyller commented Sep 18, 2025

Contributes to #98

  • New engine
  • Delete old engine
  • New client
  • Delete old client

The engine work is largely inspired by flagsmith-engine.

Note

Notes are added to call for discussion or follow up.

@emyller emyller force-pushed the feat/context-values branch 6 times, most recently from 8a8c07a to 3f2eaf4 Compare September 24, 2025 23:22
@emyller emyller force-pushed the feat/context-values branch from 3f2eaf4 to 7295ca8 Compare September 24, 2025 23:25
@emyller emyller self-assigned this Sep 24, 2025
Comment on lines +191 to +234
$any = false;
foreach ($rule->conditions as $condition) {
$conditionMatches = self::_contextMatchesCondition(
$context,
$condition,
$segmentKey,
);

switch ($rule->type) {
case SegmentRuleType::ALL:
if (!$conditionMatches) {
return false;
}
break;
case SegmentRuleType::NONE:
if ($conditionMatches) {
return false;
}
break;
case SegmentRuleType::ANY:
if ($conditionMatches) {
$any = true;
break 2;
}
break;
}
}

if ($rule->type === SegmentRuleType::ANY && !$any) {
return false;
}

foreach ($rule->rules as $subRule) {
$ruleMatches = self::_contextMatchesRule(
$context,
$subRule,
$segmentKey,
);
if (!$ruleMatches) {
return false;
}
}

return true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Compared to the Python SDK's, this is improved with short-circuiting in both conditions and sub-rule testing.

Comment on lines +44 to +48
// Hack to allow comparing flags as associative arrays (<feature_name>: <flag>)
$wanted = array_column($expectedEvaluationResult->flags, null, 'name');
$expectedEvaluationResult->flags = $wanted;
$actual = array_column($evaluationResult->flags, null, 'name');
$evaluationResult->flags = $actual;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

I would prefer EvaluationResult->flags to be an associative array <feature_name> => <flag>, rather than an indexed array. This would improve data consistency and avoid this hack. cc @khvn26

Comment on lines +31 to +51
/** @return array<string, mixed> */
public function jsonSerialize(): array
{
$json = [
'key' => $this->key,
'feature_key' => $this->feature_key,
'name' => $this->name,
'enabled' => $this->enabled,
'value' => $this->value,
];

if ($this->priority !== null) {
$json['priority'] = $this->priority;
}

if ($this->variants) {
$json['variants'] = $this->variants;
}

return $json;
}
Copy link
Author

@emyller emyller Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This only exists because the keys variants and priority are nullable in the compiled context. It can be avoided if both values are always present in the context but with insignificant values, such as rules and conditions are empty arrays by default.

@emyller emyller force-pushed the feat/context-values branch from 38c5cef to fe68922 Compare September 26, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant