Skip to content

Commit 04320ce

Browse files
committed
allow setting directly env property instead of set LiveMode & TestMode
1 parent d7c4fb9 commit 04320ce

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/Config.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,32 @@ private static function setAppropriateEnv()
148148
{
149149
$currentEnv = (self::$testMode) ? Environment::TEST : Environment::PROD;
150150
self::$env = strtolower($currentEnv);
151-
}
151+
}
152+
153+
public static function setEnv($env)
154+
{
155+
if (Check::isEnvAllowed($env))
156+
{
157+
self::$env = strtolower($env);
158+
self::setApproriateLiveAndTestMode();
159+
}
160+
else
161+
{
162+
throw new \Exception('The '. $env. ' is not allowed. Please chose between test or prod !');
163+
}
164+
}
165+
166+
private static function setApproriateLiveAndTestMode()
167+
{
168+
switch (self::getEnv())
169+
{
170+
case 'test':
171+
self::setTestMode(true);
172+
self::setLiveMode(false);
173+
case 'prod':
174+
self::setTestMode(false);
175+
self::setLiveMode(true);
176+
}
177+
}
152178

153179
}

src/Utils/Check.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ abstract class Check
2626

2727
public static function isCurrencyAllowed($currency)
2828
{
29-
return array_search($currency, self::authorizedCurrency);
29+
return array_search(strtoupper($currency), self::authorizedCurrency);
3030
}
3131

3232
public static function isEnvAllowed($env)
3333
{
34-
return array_search($$env, self::autorizedEnv);
34+
return array_search(strtoupper($env), self::autorizedEnv);
3535
}
3636
}

0 commit comments

Comments
 (0)