22
33namespace Featurevisor ;
44
5+ use Featurevisor \Datafile \Conditions ;
56use Psr \Log \LoggerInterface ;
67
78class DatafileReader
@@ -93,77 +94,7 @@ public function getRegex(string $regexString, string $regexFlags = ''): string
9394
9495 public function allConditionsAreMatched ($ conditions , array $ context ): bool
9596 {
96- if (is_string ($ conditions )) {
97- if ($ conditions === '* ' ) {
98- return true ;
99- }
100- // Try to parse as JSON
101- $ parsed = json_decode ($ conditions , true );
102- if (json_last_error () === JSON_ERROR_NONE ) {
103- $ conditions = $ parsed ;
104- } else {
105- return false ;
106- }
107- }
108-
109- $ getRegex = function (string $ regexString , string $ regexFlags ) {
110- return $ this ->getRegex ($ regexString , $ regexFlags );
111- };
112-
113- if (is_array ($ conditions )) {
114- // If it's an empty array, always match (true)
115- if (count ($ conditions ) === 0 ) {
116- return true ;
117- }
118- // Logical operators
119- if (isset ($ conditions ['and ' ]) && is_array ($ conditions ['and ' ])) {
120- foreach ($ conditions ['and ' ] as $ subCondition ) {
121- if (!$ this ->allConditionsAreMatched ($ subCondition , $ context )) {
122- return false ;
123- }
124- }
125- return true ;
126- }
127- if (isset ($ conditions ['or ' ]) && is_array ($ conditions ['or ' ])) {
128- foreach ($ conditions ['or ' ] as $ subCondition ) {
129- if ($ this ->allConditionsAreMatched ($ subCondition , $ context )) {
130- return true ;
131- }
132- }
133- return false ;
134- }
135- if (isset ($ conditions ['not ' ]) && is_array ($ conditions ['not ' ])) {
136- foreach ($ conditions ['not ' ] as $ subCondition ) {
137- if ($ this ->allConditionsAreMatched ($ subCondition , $ context )) {
138- return false ;
139- }
140- }
141- return true ;
142- }
143- // If it's a plain array, treat as AND (all must match)
144- if (array_keys ($ conditions ) === range (0 , count ($ conditions ) - 1 )) {
145- foreach ($ conditions as $ subCondition ) {
146- if (!$ this ->allConditionsAreMatched ($ subCondition , $ context )) {
147- return false ;
148- }
149- }
150- return true ;
151- }
152- // If it's a single condition (associative array)
153- if (isset ($ conditions ['attribute ' ])) {
154- try {
155- return Conditions::conditionIsMatched ($ conditions , $ context , $ getRegex );
156- } catch (\Exception $ e ) {
157- $ this ->logger ->warning ($ e ->getMessage (), [
158- 'exception ' => $ e ,
159- 'condition ' => $ conditions ,
160- 'context ' => $ context ,
161- ]);
162- return false ;
163- }
164- }
165- }
166- return false ;
97+ return Conditions::createFromMixed ($ conditions )->isSatisfiedBy ($ context );
16798 }
16899
169100 public function segmentIsMatched (array $ segment , array $ context ): bool
@@ -173,6 +104,7 @@ public function segmentIsMatched(array $segment, array $context): bool
173104
174105 public function allSegmentsAreMatched ($ groupSegments , array $ context ): bool
175106 {
107+ var_dump ($ groupSegments );
176108 if ($ groupSegments === '* ' ) {
177109 return true ;
178110 }
0 commit comments