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
}

src/SplitIO/Sdk/Manager/SplitManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace SplitIO\Sdk\Manager;
33

44
use \stdClass;
5-
use SplitIO\Component\Common\Di;
65
use SplitIO\Grammar\Condition;
76
use SplitIO\Grammar\Split;
87
use SplitIO\Split as SplitApp;

src/SplitIO/Split.php

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

4-
use SplitIO\Component\Common\Di;
4+
use SplitIO\Component\Common\Context;
55

66
class Split
77
{
@@ -11,6 +11,6 @@ class Split
1111
*/
1212
public static function logger()
1313
{
14-
return Di::getLogger();
14+
return Context::getLogger();
1515
}
1616
}

src/SplitIO/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function parseSplitsFile($fileContent)
7171

7272
function getHostIpAddress()
7373
{
74-
$diIpAddress = \SplitIO\Component\Common\Di::getIPAddress();
74+
$diIpAddress = \SplitIO\Component\Common\Context::getIPAddress();
7575
if (!is_null($diIpAddress) && is_string($diIpAddress) && trim($diIpAddress)) {
7676
return $diIpAddress;
7777
} elseif (isset($_SERVER['SERVER_ADDR']) && is_string($_SERVER['SERVER_ADDR'])

tests/Suite/Attributes/SdkAttributesTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Monolog\Handler\ErrorLogHandler;
66
use SplitIO\Component\Cache\SegmentCache;
77
use SplitIO\Component\Cache\SplitCache;
8-
use SplitIO\Component\Common\Di;
98

109
use SplitIO\Test\Utils;
1110

tests/Suite/Component/TrafficTypeTests.php

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

44
use SplitIO\Component\Cache\SplitCache;
55
use SplitIO\Test\Suite\Redis\ReflectiveTools;
6-
use SplitIO\Component\Common\Di;
6+
use SplitIO\Component\Common\Context;
77

88
class TrafficTypeTest extends \PHPUnit\Framework\TestCase
99
{
@@ -17,7 +17,7 @@ private function getMockedLogger()
1717
'alert', 'notice', 'write', 'log'))
1818
->getMock();
1919

20-
Di::setLogger($logger);
20+
Context::setLogger($logger);
2121

2222
return $logger;
2323
}
@@ -42,7 +42,7 @@ public function testTrafficTypeWarning()
4242

4343
$this->assertEquals($keyTrafficType, 'SPLITIO.trafficType.abc');
4444

45-
$redisClient = ReflectiveTools::clientFromCachePool(Di::getCache());
45+
$redisClient = ReflectiveTools::clientFromCachePool(Context::getCache());
4646
$redisClient->del($keyTrafficType);
4747

4848
$splitCache = new SplitCache();

tests/Suite/DynamicConfigurations/SplitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace SplitIO\Test\Suite\Sdk;
33

4-
use SplitIO\Component\Common\Di;
54
use SplitIO\Test\Suite\Redis\ReflectiveTools;
65
use SplitIO\Component\Cache\SplitCache;
76
use SplitIO\Grammar\Split;

tests/Suite/Engine/HashTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use SplitIO\Engine\Hash\HashAlgorithmEnum;
99
use SplitIO\Grammar\Split;
1010
use SplitIO\Test\Suite\Redis\ReflectiveTools;
11-
use SplitIO\Component\Common\Di;
1211

1312
use SplitIO\Test\Utils;
1413

tests/Suite/Engine/SplitterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
use SplitIO\Engine\Hash\HashAlgorithmEnum;
1010
use SplitIO\Grammar\Split;
1111
use SplitIO\Engine;
12-
use SplitIO\Component\Common\Di;
12+
use SplitIO\Component\Common\Context;
1313

1414
class SplitterTest extends \PHPUnit\Framework\TestCase
1515
{
1616

1717
public function testDiLog()
1818
{
1919
$logger = LoggerFactory::setupLogger(array('adapter' => 'stdout', 'level' => 'error'));
20-
Di::setLogger($logger);
20+
Context::setLogger($logger);
2121

2222
$this->assertTrue(true);
2323
}

tests/Suite/Matchers/MatchersTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use SplitIO\Component\Cache\SplitCache;
88
use SplitIO\Grammar\Condition\Matcher;
99
use SplitIO\Grammar\Condition\Matcher\DataType\DateTime;
10-
use SplitIO\Component\Common\Di;
1110
use SplitIO\Test\Suite\Redis\ReflectiveTools;
1211
use \ReflectionMethod;
1312

tests/Suite/Redis/CacheInterfacesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use SplitIO\Component\Cache\Pool;
66
use SplitIO\Component\Cache\SegmentCache;
77
use SplitIO\Component\Cache\SplitCache;
8-
use SplitIO\Component\Common\Di;
8+
use SplitIO\Component\Common\Context;
99
use SplitIO\Component\Cache\BlockUntilReadyCache;
1010
use SplitIO\Component\Log\Handler\Stdout;
1111
use SplitIO\Component\Log\Logger;
@@ -42,7 +42,7 @@ public function testDiLog()
4242

4343
$logger = new Logger($logAdapter, LogLevelEnum::INFO);
4444

45-
Di::getInstance()->setLogger($logger);
45+
Context::getInstance()->setLogger($logger);
4646

4747
$this->assertTrue(true);
4848
}

0 commit comments

Comments
 (0)