Skip to content

Commit ca411b9

Browse files
committed
tracking instances
1 parent eb1e875 commit ca411b9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/SplitIO/Component/Common/Di.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,19 @@ public static function trackFactory($apiKey)
7171
$tracked = 1;
7272
if (isset(self::getInstance()->factoryTracker[$apiKey])) {
7373
$currentInstances = self::getInstance()->factoryTracker[$apiKey];
74-
self::getInstance()->getLogger()->warning(
75-
"Factory Instantiation: You already have " . $currentInstances .
76-
" factory/ies with this API Key. " .
77-
"We recommend keeping only one instance of the factory at all times " .
78-
"(Singleton pattern) and reusing it throughout your application."
79-
);
74+
if ($currentInstances == 1) {
75+
self::getInstance()->getLogger()->warning(
76+
"Factory Instantiation: You already have 1 factory with this API Key. " .
77+
"We recommend keeping only one instance of the factory at all times " .
78+
"(Singleton pattern) and reusing it throughout your application."
79+
);
80+
} else {
81+
self::getInstance()->getLogger()->warning(
82+
"Factory Instantiation: You already have " . $currentInstances . " factories with this API Key. " .
83+
"We recommend keeping only one instance of the factory at all times " .
84+
"(Singleton pattern) and reusing it throughout your application."
85+
);
86+
}
8087
$tracked = $currentInstances + $tracked;
8188
} elseif (count(self::getInstance()->factoryTracker) > 0) {
8289
self::getInstance()->getLogger()->warning(

tests/Suite/InputValidation/FactoryTrackerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function testMultipleClientInstantiation()
3939
$logger->expects($this->any())
4040
->method('warning')
4141
->with($this->logicalOr(
42-
$this->equalTo("Factory Instantiation: You already have 1 factory/ies with this API Key. "
42+
$this->equalTo("Factory Instantiation: You already have 1 factory with this API Key. "
4343
. "We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing "
4444
. "it throughout your application."),
45-
$this->equalTo("Factory Instantiation: You already have 2 factory/ies with this API Key. "
45+
$this->equalTo("Factory Instantiation: You already have 2 factories with this API Key. "
4646
. "We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing "
4747
. "it throughout your application."),
4848
$this->equalTo("Factory Instantiation: You already have an instance of the Split factory. "

0 commit comments

Comments
 (0)