Skip to content

replaced Di in favor of Context #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/SplitIO/Component/Cache/EventsCache.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;
use SplitIO\Sdk\Events\EventQueueMessage;
use SplitIO\Component\Cache\Pool;

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

// @TODO REMOVE LOGGER DI
Di::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
Context::getLogger()->debug("Adding event item into queue: ". $queueJSONmessage);
return ($this->cache->rightPushInList(self::KEY_EVENTS_LIST, $queueJSONmessage) > 0);
}
}
5 changes: 2 additions & 3 deletions src/SplitIO/Component/Cache/ImpressionCache.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;
use SplitIO\Component\Cache\KeyFactory;
use SplitIO\Sdk\QueueMetadataMessage;
use SplitIO\Component\Cache\Pool;
Expand Down Expand Up @@ -44,8 +44,7 @@ function ($imp) use ($metadata) {
$impressions
);

// @TODO REMOVE LOGGER DI
Di::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
Context::getLogger()->debug("Adding impressions into queue: ". implode(",", $toStore));
$count = $this->cache->rightPushInList(self::IMPRESSIONS_QUEUE_KEY, $toStore);
if ($count == count($impressions)) {
$this->cache->expireKey(self::IMPRESSIONS_QUEUE_KEY, self::IMPRESSION_KEY_DEFAULT_TTL);
Expand Down
4 changes: 2 additions & 2 deletions src/SplitIO/Component/Cache/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use SplitIO\Component\Cache\Storage\Adapter\PRedis as PRedisAdapter;
use SplitIO\Component\Cache\Storage\Adapter\SafeRedisWrapper;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

class Pool extends CacheKeyTrait
{
Expand Down Expand Up @@ -39,7 +39,7 @@ public function __construct(array $options = array())
public function get($key)
{
$this->assertValidKey($key);
Di::getLogger()->debug("Fetching item ** $key ** from cache");
Context::getLogger()->debug("Fetching item ** $key ** from cache");
return $this->adapter->get($key);
}

Expand Down
2 changes: 0 additions & 2 deletions src/SplitIO/Component/Cache/SegmentCache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;

class SegmentCache implements SegmentCacheInterface
{
const KEY_SEGMENT_DATA = 'SPLITIO.segment.{segmentName}';
Expand Down
2 changes: 0 additions & 2 deletions src/SplitIO/Component/Cache/SplitCache.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace SplitIO\Component\Cache;

use SplitIO\Component\Common\Di;

class SplitCache implements SplitCacheInterface
{
const KEY_TILL_CACHED_ITEM = 'SPLITIO.splits.till';
Expand Down
4 changes: 2 additions & 2 deletions src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
use SplitIO\Component\Cache\Item;
use SplitIO\Component\Utils as SplitIOUtils;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

/**
* Class PRedis
Expand Down Expand Up @@ -170,7 +170,7 @@ private function getRedisConfiguration($options)
} else {
// @TODO remove this statement when replication will be deprecated
if (isset($_options['replication'])) {
Di::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
Context::getLogger()->warning("'replication' option was deprecated please use 'distributedStrategy'");
if (!isset($_options['distributedStrategy'])) {
$_options['distributedStrategy'] = $_options['replication'];
}
Expand Down
38 changes: 19 additions & 19 deletions src/SplitIO/Component/Cache/Storage/Adapter/SafeRedisWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use SplitIO\Component\Cache\Storage\Exception\AdapterException;
use SplitIO\Component\Cache\Item;
use SplitIO\Component\Utils as SplitIOUtils;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

/**
* Class SafeRedisWrapper
Expand Down Expand Up @@ -32,9 +32,9 @@ public function get($key)
try {
return $this->cacheAdapter->get($key);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred getting " . $key . " from redis.");
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred getting " . $key . " from redis.");
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return null;
}
}
Expand All @@ -53,9 +53,9 @@ public function fetchMany(array $keys = array())
try {
return $this->cacheAdapter->fetchMany($keys);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred getting " . json_encode($keys) . " from redis.");
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return array();
}
}
Expand All @@ -70,9 +70,9 @@ public function isOnList($key, $value)
try {
return $this->cacheAdapter->isOnList($key, $value);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred for " . $key);
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred for " . $key);
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return false;
}
}
Expand All @@ -86,9 +86,9 @@ public function getKeys($pattern = '*')
try {
return $this->cacheAdapter->getKeys($pattern);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred getting " . $pattern);
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred getting " . $pattern);
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return array();
}
}
Expand All @@ -103,9 +103,9 @@ public function rightPushQueue($queueName, $item)
try {
return $this->cacheAdapter->rightPushQueue($queueName, $item);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred performing RPUSH into " . $queueName);
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred performing RPUSH into " . $queueName);
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return 0;
}
}
Expand All @@ -120,9 +120,9 @@ public function expireKey($key, $ttl)
try {
return $this->cacheAdapter->expireKey($key, $ttl);
} catch (\Exception $e) {
Di::getLogger()->critical("An error occurred setting expiration for " . $key);
Di::getLogger()->critical($e->getMessage());
Di::getLogger()->critical($e->getTraceAsString());
Context::getLogger()->critical("An error occurred setting expiration for " . $key);
Context::getLogger()->critical($e->getMessage());
Context::getLogger()->critical($e->getTraceAsString());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use SplitIO\Component\Log\Logger;

/**
* Class Di
* Class Context
* @package SplitIO\Common
*/
class Di
class Context
{
const SAME_APIKEY = "Factory Instantiation: You already have %s factory/factories with this API Key. "
. "We recommend keeping only one instance of the factory at all times (Singleton pattern) and "
Expand Down
1 change: 0 additions & 1 deletion src/SplitIO/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use SplitIO\Engine\Splitter;
use SplitIO\Grammar\Condition\ConditionTypeEnum;
use SplitIO\Sdk\Impressions\ImpressionLabel;
use SplitIO\Component\Common\Di;

class Engine
{
Expand Down
8 changes: 4 additions & 4 deletions src/SplitIO/Sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SplitIO\Exception\Exception;
use SplitIO\Sdk\Factory\LocalhostSplitFactory;
use SplitIO\Sdk\Factory\SplitFactory;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;
use SplitIO\Engine\Splitter;
use SplitIO\Component\Cache\Pool;

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

//Tracking Factory Instantiation
Di::trackFactory($apiKey);
Context::trackFactory($apiKey);

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

private static function configureCache(array $options)
Expand Down Expand Up @@ -88,6 +88,6 @@ private static function configureCache(array $options)

private static function setIP($ip)
{
\SplitIO\Component\Common\Di::setIPAddress($ip);
\SplitIO\Component\Common\Context::setIPAddress($ip);
}
}
1 change: 0 additions & 1 deletion src/SplitIO/Sdk/Manager/SplitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace SplitIO\Sdk\Manager;

use \stdClass;
use SplitIO\Component\Common\Di;
use SplitIO\Grammar\Condition;
use SplitIO\Grammar\Split;
use SplitIO\Split as SplitApp;
Expand Down
4 changes: 2 additions & 2 deletions src/SplitIO/Split.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace SplitIO;

use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

class Split
{
Expand All @@ -11,6 +11,6 @@ class Split
*/
public static function logger()
{
return Di::getLogger();
return Context::getLogger();
}
}
2 changes: 1 addition & 1 deletion src/SplitIO/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function parseSplitsFile($fileContent)

function getHostIpAddress()
{
$diIpAddress = \SplitIO\Component\Common\Di::getIPAddress();
$diIpAddress = \SplitIO\Component\Common\Context::getIPAddress();
if (!is_null($diIpAddress) && is_string($diIpAddress) && trim($diIpAddress)) {
return $diIpAddress;
} elseif (isset($_SERVER['SERVER_ADDR']) && is_string($_SERVER['SERVER_ADDR'])
Expand Down
1 change: 0 additions & 1 deletion tests/Suite/Attributes/SdkAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Monolog\Handler\ErrorLogHandler;
use SplitIO\Component\Cache\SegmentCache;
use SplitIO\Component\Cache\SplitCache;
use SplitIO\Component\Common\Di;

use SplitIO\Test\Utils;

Expand Down
6 changes: 3 additions & 3 deletions tests/Suite/Component/TrafficTypeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use SplitIO\Component\Cache\SplitCache;
use SplitIO\Test\Suite\Redis\ReflectiveTools;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

class TrafficTypeTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -17,7 +17,7 @@ private function getMockedLogger()
'alert', 'notice', 'write', 'log'))
->getMock();

Di::setLogger($logger);
Context::setLogger($logger);

return $logger;
}
Expand All @@ -42,7 +42,7 @@ public function testTrafficTypeWarning()

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

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

$splitCache = new SplitCache();
Expand Down
1 change: 0 additions & 1 deletion tests/Suite/DynamicConfigurations/SplitTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace SplitIO\Test\Suite\Sdk;

use SplitIO\Component\Common\Di;
use SplitIO\Test\Suite\Redis\ReflectiveTools;
use SplitIO\Component\Cache\SplitCache;
use SplitIO\Grammar\Split;
Expand Down
1 change: 0 additions & 1 deletion tests/Suite/Engine/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SplitIO\Engine\Hash\HashAlgorithmEnum;
use SplitIO\Grammar\Split;
use SplitIO\Test\Suite\Redis\ReflectiveTools;
use SplitIO\Component\Common\Di;

use SplitIO\Test\Utils;

Expand Down
4 changes: 2 additions & 2 deletions tests/Suite/Engine/SplitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
use SplitIO\Engine\Hash\HashAlgorithmEnum;
use SplitIO\Grammar\Split;
use SplitIO\Engine;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;

class SplitterTest extends \PHPUnit\Framework\TestCase
{

public function testDiLog()
{
$logger = LoggerFactory::setupLogger(array('adapter' => 'stdout', 'level' => 'error'));
Di::setLogger($logger);
Context::setLogger($logger);

$this->assertTrue(true);
}
Expand Down
1 change: 0 additions & 1 deletion tests/Suite/Matchers/MatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use SplitIO\Component\Cache\SplitCache;
use SplitIO\Grammar\Condition\Matcher;
use SplitIO\Grammar\Condition\Matcher\DataType\DateTime;
use SplitIO\Component\Common\Di;
use SplitIO\Test\Suite\Redis\ReflectiveTools;
use \ReflectionMethod;

Expand Down
4 changes: 2 additions & 2 deletions tests/Suite/Redis/CacheInterfacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SplitIO\Component\Cache\Pool;
use SplitIO\Component\Cache\SegmentCache;
use SplitIO\Component\Cache\SplitCache;
use SplitIO\Component\Common\Di;
use SplitIO\Component\Common\Context;
use SplitIO\Component\Cache\BlockUntilReadyCache;
use SplitIO\Component\Log\Handler\Stdout;
use SplitIO\Component\Log\Logger;
Expand Down Expand Up @@ -42,7 +42,7 @@ public function testDiLog()

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

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

$this->assertTrue(true);
}
Expand Down
Loading