@@ -93,6 +93,16 @@ class DatafileProjectConfig implements ProjectConfigInterface
93
93
*/
94
94
private $ datafile ;
95
95
96
+ /**
97
+ * @var string environmentKey of the config.
98
+ */
99
+ private $ environmentKey ;
100
+
101
+ /**
102
+ * @var string sdkKey of the config.
103
+ */
104
+ private $ sdkKey ;
105
+
96
106
/**
97
107
* @var string Revision of the datafile.
98
108
*/
@@ -172,6 +182,34 @@ class DatafileProjectConfig implements ProjectConfigInterface
172
182
*/
173
183
private $ _rollouts ;
174
184
185
+ /**
186
+ * list of Attributes that will be parsed from the datafile
187
+ *
188
+ * @var [Attribute]
189
+ */
190
+ private $ attributes ;
191
+
192
+ /**
193
+ * list of Audiences that will be parsed from the datafile
194
+ *
195
+ * @var [Audience]
196
+ */
197
+ private $ audiences ;
198
+
199
+ /**
200
+ * list of Events that will be parsed from the datafile
201
+ *
202
+ * @var [Event]
203
+ */
204
+ private $ events ;
205
+
206
+ /**
207
+ * list of Typed Audiences that will be parsed from the datafile
208
+ *
209
+ * @var [Audience]
210
+ */
211
+ private $ typedAudiences ;
212
+
175
213
/**
176
214
* internal mapping of feature keys to feature flag models.
177
215
*
@@ -222,6 +260,8 @@ public function __construct($datafile, $logger, $errorHandler)
222
260
$ this ->_logger = $ logger ;
223
261
$ this ->_errorHandler = $ errorHandler ;
224
262
$ this ->_version = $ config ['version ' ];
263
+ $ this ->environmentKey = isset ($ config ['environmentKey ' ]) ? $ config ['environmentKey ' ] : '' ;
264
+ $ this ->sdkKey = isset ($ config ['sdkKey ' ]) ? $ config ['sdkKey ' ] : '' ;
225
265
if (!in_array ($ this ->_version , $ supportedVersions )) {
226
266
throw new InvalidDatafileVersionException (
227
267
"This version of the PHP SDK does not support the given datafile version: {$ this ->_version }. "
@@ -237,10 +277,10 @@ public function __construct($datafile, $logger, $errorHandler)
237
277
238
278
$ groups = $ config ['groups ' ] ?: [];
239
279
$ experiments = $ config ['experiments ' ] ?: [];
240
- $ events = $ config ['events ' ] ? : [];
241
- $ attributes = $ config ['attributes ' ] ? : [];
242
- $ audiences = $ config ['audiences ' ] ? : [];
243
- $ typedAudiences = isset ($ config ['typedAudiences ' ]) ? $ config ['typedAudiences ' ]: [];
280
+ $ this -> attributes = isset ( $ config ['attributes ' ]) ? $ config [ ' attributes ' ] : [];
281
+ $ this -> audiences = isset ( $ config ['audiences ' ]) ? $ config [ ' audiences ' ] : [];
282
+ $ this -> events = isset ( $ config ['events ' ]) ? $ config [ ' events ' ] : [];
283
+ $ this -> typedAudiences = isset ($ config ['typedAudiences ' ]) ? $ config ['typedAudiences ' ] : [];
244
284
$ rollouts = isset ($ config ['rollouts ' ]) ? $ config ['rollouts ' ] : [];
245
285
$ featureFlags = isset ($ config ['featureFlags ' ]) ? $ config ['featureFlags ' ]: [];
246
286
@@ -258,10 +298,10 @@ public function __construct($datafile, $logger, $errorHandler)
258
298
259
299
$ this ->_groupIdMap = ConfigParser::generateMap ($ groups , 'id ' , Group::class);
260
300
$ this ->_experimentIdMap = ConfigParser::generateMap ($ experiments , 'id ' , Experiment::class);
261
- $ this ->_eventKeyMap = ConfigParser::generateMap ($ events , 'key ' , Event::class);
262
- $ this ->_attributeKeyMap = ConfigParser::generateMap ($ attributes , 'key ' , Attribute::class);
263
- $ typedAudienceIdMap = ConfigParser::generateMap ($ typedAudiences , 'id ' , Audience::class);
264
- $ this ->_audienceIdMap = ConfigParser::generateMap ($ audiences , 'id ' , Audience::class);
301
+ $ this ->_eventKeyMap = ConfigParser::generateMap ($ this -> events , 'key ' , Event::class);
302
+ $ this ->_attributeKeyMap = ConfigParser::generateMap ($ this -> attributes , 'key ' , Attribute::class);
303
+ $ typedAudienceIdMap = ConfigParser::generateMap ($ this -> typedAudiences , 'id ' , Audience::class);
304
+ $ this ->_audienceIdMap = ConfigParser::generateMap ($ this -> audiences , 'id ' , Audience::class);
265
305
$ this ->_rollouts = ConfigParser::generateMap ($ rollouts , null , Rollout::class);
266
306
$ this ->_featureFlags = ConfigParser::generateMap ($ featureFlags , null , FeatureFlag::class);
267
307
@@ -449,6 +489,22 @@ public function getRevision()
449
489
return $ this ->_revision ;
450
490
}
451
491
492
+ /**
493
+ * @return string Config environmentKey.
494
+ */
495
+ public function getEnvironmentKey ()
496
+ {
497
+ return $ this ->environmentKey ;
498
+ }
499
+
500
+ /**
501
+ * @return string Config sdkKey.
502
+ */
503
+ public function getSdkKey ()
504
+ {
505
+ return $ this ->sdkKey ;
506
+ }
507
+
452
508
/**
453
509
* @return array List of feature flags parsed from the datafile
454
510
*/
@@ -457,6 +513,38 @@ public function getFeatureFlags()
457
513
return $ this ->_featureFlags ;
458
514
}
459
515
516
+ /**
517
+ * @return array List of attributes parsed from the datafile
518
+ */
519
+ public function getAttributes ()
520
+ {
521
+ return $ this ->attributes ;
522
+ }
523
+
524
+ /**
525
+ * @return array List of audiences parsed from the datafile
526
+ */
527
+ public function getAudiences ()
528
+ {
529
+ return $ this ->audiences ;
530
+ }
531
+
532
+ /**
533
+ * @return array List of events parsed from the datafile
534
+ */
535
+ public function getEvents ()
536
+ {
537
+ return $ this ->events ;
538
+ }
539
+
540
+ /**
541
+ * @return array List of typed audiences parsed from the datafile
542
+ */
543
+ public function getTypedAudiences ()
544
+ {
545
+ return $ this ->typedAudiences ;
546
+ }
547
+
460
548
/**
461
549
* @return array List of all experiments (including group experiments)
462
550
* parsed from the datafile
@@ -470,7 +558,7 @@ public function getAllExperiments()
470
558
$ rolloutExperimentIds [] = $ experiment ->getId ();
471
559
}
472
560
}
473
- return array_filter (array_values ($ this ->_experimentKeyMap ), function ($ experiment ) use ($ rolloutExperimentIds ) {
561
+ return array_filter (array_values ($ this ->_experimentIdMap ), function ($ experiment ) use ($ rolloutExperimentIds ) {
474
562
return !in_array ($ experiment ->getId (), $ rolloutExperimentIds );
475
563
});
476
564
}
0 commit comments