Skip to content

Commit bc08632

Browse files
authored
Merge pull request #198 from splitio/task/context
replaced Di in favor of Context
2 parents ad6c40c + 092d94c commit bc08632

24 files changed

+54
-67
lines changed

src/SplitIO/Component/Cache/EventsCache.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace SplitIO\Component\Cache;
33

4-
use SplitIO\Component\Common\Di;
4+
use SplitIO\Component\Common\Context;
55
use SplitIO\Sdk\Events\EventQueueMessage;
66
use SplitIO\Component\Cache\Pool;
77

@@ -26,8 +26,7 @@ public function addEvent(EventQueueMessage $message)
2626
{
2727
$queueJSONmessage = json_encode($message->toArray());
2828

29-
// @TODO REMOVE LOGGER DI
30-
Di::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
29+
Context::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
3130
return ($this->cache->rightPushInList(self::KEY_EVENTS_LIST, $queueJSONmessage) > 0);
3231
}
3332
}

src/SplitIO/Component/Cache/ImpressionCache.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace SplitIO\Component\Cache;
33

4-
use SplitIO\Component\Common\Di;
4+
use SplitIO\Component\Common\Context;
55
use SplitIO\Component\Cache\KeyFactory;
66
use SplitIO\Sdk\QueueMetadataMessage;
77
use SplitIO\Component\Cache\Pool;
@@ -44,8 +44,7 @@ function ($imp) use ($metadata) {
4444
$impressions
4545
);
4646

47-
// @TODO REMOVE LOGGER DI
48-
Di::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
47+
Context::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
4948
$count = $this->cache->rightPushInList(self::IMPRESSIONS_QUEUE_KEY, $toStore);
5049
if ($count == count($impressions)) {
5150
$this->cache->expireKey(self::IMPRESSIONS_QUEUE_KEY, self::IMPRESSION_KEY_DEFAULT_TTL);

src/SplitIO/Component/Cache/Pool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use SplitIO\Component\Cache\Storage\Adapter\PRedis as PRedisAdapter;
55
use SplitIO\Component\Cache\Storage\Adapter\SafeRedisWrapper;
6-
use SplitIO\Component\Common\Di;
6+
use SplitIO\Component\Common\Context;
77

88
class Pool extends CacheKeyTrait
99
{
@@ -39,7 +39,7 @@ public function __construct(array $options = array())
3939
public function get($key)
4040
{
4141
$this->assertValidKey($key);
42-
Di::getLogger()->debug("Fetching item ** $key ** from cache");
42+
Context::getLogger()->debug("Fetching item ** $key ** from cache");
4343
return $this->adapter->get($key);
4444
}
4545

src/SplitIO/Component/Cache/SegmentCache.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace SplitIO\Component\Cache;
33

4-
use SplitIO\Component\Common\Di;
5-
64
class SegmentCache implements SegmentCacheInterface
75
{
86
const KEY_SEGMENT_DATA = 'SPLITIO.segment.{segmentName}';

src/SplitIO/Component/Cache/SplitCache.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace SplitIO\Component\Cache;
33

4-
use SplitIO\Component\Common\Di;
5-
64
class SplitCache implements SplitCacheInterface
75
{
86
const KEY_TILL_CACHED_ITEM = 'SPLITIO.splits.till';

src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
55
use SplitIO\Component\Cache\Item;
66
use SplitIO\Component\Utils as SplitIOUtils;
7-
use SplitIO\Component\Common\Di;
7+
use SplitIO\Component\Common\Context;
88

99
/**
1010
* Class PRedis
@@ -170,7 +170,7 @@ private function getRedisConfiguration($options)
170170
} else {
171171
// @TODO remove this statement when replication will be deprecated
172172
if (isset($_options['replication'])) {
173-
Di::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
173+
Context::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
174174
if (!isset($_options['distributedStrategy'])) {
175175
$_options['distributedStrategy'] = $_options['replication'];
176176
}

src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
55
use SplitIO\Component\Cache\Item;
66
use SplitIO\Component\Utils as SplitIOUtils;
7-
use SplitIO\Component\Common\Di;
7+
use SplitIO\Component\Common\Context;
88

99
/**
1010
* Class SafeRedisWrapper
@@ -32,9 +32,9 @@ public function get($key)
3232
try {
3333
return $this->cacheAdapter->get($key);
3434
} catch (\Exception $e) {
35-
Di::getLogger()->critical("An error occurred getting " . $key . " from redis.");
36-
Di::getLogger()->critical($e->getMessage());
37-
Di::getLogger()->critical($e->getTraceAsString());
35+
Context::getLogger()->critical("An error occurred getting " . $key . " from redis.");
36+
Context::getLogger()->critical($e->getMessage());
37+
Context::getLogger()->critical($e->getTraceAsString());
3838
return null;
3939
}
4040
}
@@ -53,9 +53,9 @@ public function fetchMany(array $keys = array())
5353
try {
5454
return $this->cacheAdapter->fetchMany($keys);
5555
} catch (\Exception $e) {
56-
Di::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
57-
Di::getLogger()->critical($e->getMessage());
58-
Di::getLogger()->critical($e->getTraceAsString());
56+
Context::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
57+
Context::getLogger()->critical($e->getMessage());
58+
Context::getLogger()->critical($e->getTraceAsString());
5959
return array();
6060
}
6161
}
@@ -70,9 +70,9 @@ public function isOnList($key, $value)
7070
try {
7171
return $this->cacheAdapter->isOnList($key, $value);
7272
} catch (\Exception $e) {
73-
Di::getLogger()->critical("An error occurred for " . $key);
74-
Di::getLogger()->critical($e->getMessage());
75-
Di::getLogger()->critical($e->getTraceAsString());
73+
Context::getLogger()->critical("An error occurred for " . $key);
74+
Context::getLogger()->critical($e->getMessage());
75+
Context::getLogger()->critical($e->getTraceAsString());
7676
return false;
7777
}
7878
}
@@ -86,9 +86,9 @@ public function getKeys($pattern = '*')
8686
try {
8787
return $this->cacheAdapter->getKeys($pattern);
8888
} catch (\Exception $e) {
89-
Di::getLogger()->critical("An error occurred getting " . $pattern);
90-
Di::getLogger()->critical($e->getMessage());
91-
Di::getLogger()->critical($e->getTraceAsString());
89+
Context::getLogger()->critical("An error occurred getting " . $pattern);
90+
Context::getLogger()->critical($e->getMessage());
91+
Context::getLogger()->critical($e->getTraceAsString());
9292
return array();
9393
}
9494
}
@@ -103,9 +103,9 @@ public function rightPushQueue($queueName, $item)
103103
try {
104104
return $this->cacheAdapter->rightPushQueue($queueName, $item);
105105
} catch (\Exception $e) {
106-
Di::getLogger()->critical("An error occurred performing RPUSH into " . $queueName);
107-
Di::getLogger()->critical($e->getMessage());
108-
Di::getLogger()->critical($e->getTraceAsString());
106+
Context::getLogger()->critical("An error occurred performing RPUSH into " . $queueName);
107+
Context::getLogger()->critical($e->getMessage());
108+
Context::getLogger()->critical($e->getTraceAsString());
109109
return 0;
110110
}
111111
}
@@ -120,9 +120,9 @@ public function expireKey($key, $ttl)
120120
try {
121121
return $this->cacheAdapter->expireKey($key, $ttl);
122122
} catch (\Exception $e) {
123-
Di::getLogger()->critical("An error occurred setting expiration for " . $key);
124-
Di::getLogger()->critical($e->getMessage());
125-
Di::getLogger()->critical($e->getTraceAsString());
123+
Context::getLogger()->critical("An error occurred setting expiration for " . $key);
124+
Context::getLogger()->critical($e->getMessage());
125+
Context::getLogger()->critical($e->getTraceAsString());
126126
return false;
127127
}
128128
}

src/SplitIO/Component/Common/Di.php renamed to src/SplitIO/Component/Common/Context.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use SplitIO\Component\Log\Logger;
55

66
/**
7-
* Class Di
7+
* Class Context
88
* @package SplitIO\Common
99
*/
10-
class Di
10+
class Context
1111
{
1212
const SAME_APIKEY = "Factory Instantiation: You already have %s factory/factories with this API Key. "
1313
. "We recommend keeping only one instance of the factory at all times (Singleton pattern) and "

src/SplitIO/Engine.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use SplitIO\Engine\Splitter;
77
use SplitIO\Grammar\Condition\ConditionTypeEnum;
88
use SplitIO\Sdk\Impressions\ImpressionLabel;
9-
use SplitIO\Component\Common\Di;
109

1110
class Engine
1211
{

src/SplitIO/Sdk.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use SplitIO\Exception\Exception;
88
use SplitIO\Sdk\Factory\LocalhostSplitFactory;
99
use SplitIO\Sdk\Factory\SplitFactory;
10-
use SplitIO\Component\Common\Di;
10+
use SplitIO\Component\Common\Context;
1111
use SplitIO\Engine\Splitter;
1212
use SplitIO\Component\Cache\Pool;
1313

@@ -32,7 +32,7 @@ public static function factory($apiKey = 'localhost', array $options = array())
3232
$options['apiKey'] = $apiKey;
3333

3434
//Tracking Factory Instantiation
35-
Di::trackFactory($apiKey);
35+
Context::trackFactory($apiKey);
3636

3737
//Register Logger
3838
self::registerLogger((isset($options['log'])) ? $options['log'] : array());
@@ -57,7 +57,7 @@ public static function factory($apiKey = 'localhost', array $options = array())
5757
private static function registerLogger(array $options)
5858
{
5959
$logger = LoggerFactory::setupLogger($options);
60-
Di::setLogger($logger);
60+
Context::setLogger($logger);
6161
}
6262

6363
private static function configureCache(array $options)
@@ -88,6 +88,6 @@ private static function configureCache(array $options)
8888

8989
private static function setIP($ip)
9090
{
91-
\SplitIO\Component\Common\Di::setIPAddress($ip);
91+
\SplitIO\Component\Common\Context::setIPAddress($ip);
9292
}
9393
}

0 commit comments

Comments
 (0)