Skip to content

Commit e923e71

Browse files
committed
Merge branch 'task/multipleFactory' of github.com:splitio/php-client into task/DiLogger
2 parents f7a8d13 + c5a8afb commit e923e71

File tree

5 files changed

+19
-37
lines changed

5 files changed

+19
-37
lines changed

src/SplitIO/Grammar/Condition/Matcher/Dependency.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function evalKey($key, $attributes = null, $bucketingKey = null, $context
3131
{
3232
if (!isset($context['evaluator'])) {
3333
throw new Exception('Evaluator not present in matcher context.');
34-
return false;
3534
}
3635
$evaluator = $context['evaluator'];
3736
$result = $evaluator->evaluateFeature($key, $bucketingKey, $this->splitName, $attributes);

src/SplitIO/Grammar/Condition/Matcher/Segment.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ protected function evalKey($key, array $context = null)
3939
$segmentName = $this->userDefinedSegmentMatcherData;
4040
if (!isset($context['segmentCache'])) {
4141
throw new Exception('Segment storage not present in matcher context.');
42-
return false;
4342
}
4443
$segmentCache = $context['segmentCache'];
4544

src/SplitIO/Sdk.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function factory($apiKey = 'localhost', array $options = array())
4343
self::registerLogger((isset($options['log'])) ? $options['log'] : array());
4444

4545
//Register Cache
46-
$cache = self::registerCache((isset($options['cache'])) ? $options['cache'] : array());
46+
$cache = self::configureCache((isset($options['cache'])) ? $options['cache'] : array());
4747

4848
if (isset($options['ipAddress'])) {
4949
self::setIP($options['ipAddress']);
@@ -62,7 +62,7 @@ private static function registerLogger(array $options)
6262
ServiceProvider::registerLogger($logger);
6363
}
6464

65-
private static function registerCache(array $options)
65+
private static function configureCache(array $options)
6666
{
6767
$_options = array();
6868
$cacheAdapter = isset($options['adapter']) ? $options['adapter'] : 'redis';

src/SplitIO/Sdk/Client.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ class Client implements ClientInterface
4343
*/
4444
private $eventCache;
4545

46-
/**
47-
* @var \SplitIO\Sdk\Validator\InputValidator
48-
*/
49-
private $inputValidator;
50-
5146
/**
5247
* @param array $options
5348
* @param array $storages
@@ -66,7 +61,6 @@ public function __construct($storages, $options = array())
6661
$this->queueMetadata = new QueueMetadataMessage(
6762
isset($options['IPAddressesEnabled']) ? $options['IPAddressesEnabled'] : true
6863
);
69-
$this->inputValidator = new InputValidator($this->splitCache);
7064
}
7165

7266
/**
@@ -103,17 +97,17 @@ private function createImpression($key, $feature, $treatment, $changeNumber, $la
10397
*/
10498
private function doInputValidationForTreatment($key, $featureName, array $attributes = null, $operation)
10599
{
106-
$key = $this->inputValidator->validateKey($key, $operation);
100+
$key = InputValidator::validateKey($key, $operation);
107101
if (is_null($key)) {
108102
return null;
109103
}
110104

111-
$featureName = $this->inputValidator->validateFeatureName($featureName, $operation);
105+
$featureName = InputValidator::validateFeatureName($featureName, $operation);
112106
if (is_null($featureName)) {
113107
return null;
114108
}
115109

116-
if (!$this->inputValidator->validAttributes($attributes, $operation)) {
110+
if (!InputValidator::validAttributes($attributes, $operation)) {
117111
return null;
118112
}
119113

@@ -148,7 +142,7 @@ private function doEvaluation($operation, $metricName, $key, $featureName, $attr
148142
$featureName = $inputValidation['featureName'];
149143
try {
150144
$result = $this->evaluator->evaluateFeature($matchingKey, $bucketingKey, $featureName, $attributes);
151-
if (!$this->inputValidator->isSplitFound($result['impression']['label'], $featureName, $operation)) {
145+
if (!InputValidator::isSplitFound($result['impression']['label'], $featureName, $operation)) {
152146
return $default;
153147
}
154148
// Creates impression
@@ -244,13 +238,13 @@ public function getTreatmentWithConfig($key, $featureName, array $attributes = n
244238
*/
245239
private function doInputValidationForTreatments($key, $featureNames, array $attributes = null, $operation)
246240
{
247-
$splitNames = $this->inputValidator->validateFeatureNames($featureNames, $operation);
241+
$splitNames = InputValidator::validateFeatureNames($featureNames, $operation);
248242
if (is_null($splitNames)) {
249243
return null;
250244
}
251245

252-
$key = $this->inputValidator->validateKey($key, $operation);
253-
if (is_null($key) || !$this->inputValidator->validAttributes($attributes, $operation)) {
246+
$key = InputValidator::validateKey($key, $operation);
247+
if (is_null($key) || !InputValidator::validAttributes($attributes, $operation)) {
254248
return array(
255249
'controlTreatments' => array_fill_keys(
256250
$splitNames,
@@ -320,7 +314,7 @@ private function doEvaluationForTreatments($operation, $metricName, $key, $featu
320314
$attributes
321315
);
322316
foreach ($evaluationResults['evaluations'] as $splitName => $evalResult) {
323-
if ($this->inputValidator->isSplitFound($evalResult['impression']['label'], $splitName, $operation)) {
317+
if (InputValidator::isSplitFound($evalResult['impression']['label'], $splitName, $operation)) {
324318
// Creates impression
325319
$impressions[] = $this->createImpression(
326320
$matchingKey,
@@ -368,7 +362,7 @@ function ($feature) {
368362
);
369363
} catch (\Exception $e) {
370364
SplitApp::logger()->critical('getTreatments method is throwing exceptions');
371-
$splitNames = $this->inputValidator->validateFeatureNames($featureNames, 'getTreatments');
365+
$splitNames = InputValidator::validateFeatureNames($featureNames, 'getTreatments');
372366
return is_null($splitNames) ? array() : array_fill_keys($splitNames, TreatmentEnum::CONTROL);
373367
}
374368
}
@@ -388,7 +382,7 @@ public function getTreatmentsWithConfig($key, $featureNames, array $attributes =
388382
);
389383
} catch (\Exception $e) {
390384
SplitApp::logger()->critical('getTreatmentsWithConfig method is throwing exceptions');
391-
$splitNames = $this->inputValidator->validateFeatureNames($featureNames, 'getTreatmentsWithConfig');
385+
$splitNames = InputValidator::validateFeatureNames($featureNames, 'getTreatmentsWithConfig');
392386
return is_null($splitNames) ? array() :
393387
array_fill_keys($splitNames, array('treatment' => TreatmentEnum::CONTROL, 'config' => null));
394388
}
@@ -423,11 +417,11 @@ public function isTreatment($key, $featureName, $treatment)
423417
*/
424418
public function track($key, $trafficType, $eventType, $value = null, $properties = null)
425419
{
426-
$key = $this->inputValidator->validateTrackKey($key);
427-
$trafficType = $this->inputValidator->validateTrafficType($trafficType);
428-
$eventType = $this->inputValidator->validateEventType($eventType);
429-
$value = $this->inputValidator->validateValue($value);
430-
$properties = $this->inputValidator->validProperties($properties);
420+
$key = InputValidator::validateTrackKey($key);
421+
$trafficType = InputValidator::validateTrafficType($this->splitCache, $trafficType);
422+
$eventType = InputValidator::validateEventType($eventType);
423+
$value = InputValidator::validateValue($value);
424+
$properties = InputValidator::validProperties($properties);
431425

432426
if (is_null($key) || is_null($trafficType) || is_null($eventType) || $value === false
433427
|| $properties === false) {

src/SplitIO/Sdk/Validator/InputValidator.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515

1616
class InputValidator
1717
{
18-
/**
19-
* @var \SplitIO\Component\Cache\SplitCache
20-
*/
21-
private $splitCache;
22-
23-
public function __construct(SplitCache $splitCache)
24-
{
25-
$this->splitCache = $splitCache;
26-
}
27-
2818
/**
2919
* @param $value
3020
* @param $name
@@ -183,7 +173,7 @@ public static function validateTrackKey($key)
183173
* @param $trafficType
184174
* @return string|null
185175
*/
186-
public function validateTrafficType($trafficType)
176+
public static function validateTrafficType(\SplitIO\Component\Cache\SplitCache $splitCache, $trafficType)
187177
{
188178
if (!self::validString($trafficType, 'traffic type', 'track')) {
189179
return null;
@@ -193,7 +183,7 @@ public function validateTrafficType($trafficType)
193183
SplitApp::logger()->warning("track: '" . $trafficType . "' should be all lowercase - converting string to "
194184
. "lowercase.");
195185
}
196-
if (!$this->splitCache->trafficTypeExists($toLowercase)) {
186+
if (!$splitCache->trafficTypeExists($toLowercase)) {
197187
SplitApp::logger()->warning("track: Traffic Type '". $toLowercase . "' does not have any corresponding "
198188
. "Splits in this environment, make sure you’re tracking your events to a valid traffic type "
199189
. "defined in the Split console.");

0 commit comments

Comments
 (0)