File tree Expand file tree Collapse file tree 4 files changed +24
-1
lines changed
Expand file tree Collapse file tree 4 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ public static function getEvaluationResult($context): EvaluationResult
5656 $ segmentResult = new SegmentResult ();
5757 $ segmentResult ->key = $ segment ->key ;
5858 $ segmentResult ->name = $ segment ->name ;
59+ $ segmentResult ->metadata = $ segment ->metadata ?? null ;
5960 $ evaluatedSegments [] = $ segmentResult ;
6061
6162 foreach ($ segment ->overrides as $ overrideFeature ) {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ public static function fromJsonObject($jsonContext)
4242 $ segment ->name = $ jsonSegment ->name ;
4343 $ segment ->rules = self ::_convertRules ($ jsonSegment ->rules ?? []);
4444 $ segment ->overrides = array_values (self ::_convertFeatures ($ jsonSegment ->overrides ?? []));
45+ $ segment ->metadata = (array ) ($ jsonSegment ->metadata ?? []);
4546 $ context ->segments [$ segment ->key ] = $ segment ;
4647 }
4748
Original file line number Diff line number Diff line change @@ -15,4 +15,7 @@ class SegmentContext
1515
1616 /** @var array<FeatureContext> */
1717 public $ overrides ;
18+
19+ /** @var ?array<string,mixed> */
20+ public $ metadata ;
1821}
Original file line number Diff line number Diff line change 22
33namespace Flagsmith \Engine \Utils \Types \Result ;
44
5- class SegmentResult
5+ class SegmentResult implements \JsonSerializable
66{
77 /** @var string */
88 public $ key ;
99
1010 /** @var string */
1111 public $ name ;
12+
13+ /** @var ?array<string,mixed> */
14+ public $ metadata ;
15+
16+ public function jsonSerialize (): array
17+ {
18+ $ data = [
19+ 'key ' => $ this ->key ,
20+ 'name ' => $ this ->name ,
21+ ];
22+
23+ // 'metadata' is only added if there is any
24+ if (!empty ($ this ->metadata )) {
25+ $ data ['metadata ' ] = $ this ->metadata ;
26+ }
27+
28+ return $ data ;
29+ }
1230}
You can’t perform that action at this time.
0 commit comments