Eh bien, ma propre solution à ce problème consiste à utiliser différentes clés dans un tableau pour différents environnements.
Dans ce cas, je vais essayer de l'expliquer en PHP
class API_Client
{
const ENV_STAGING = 'staging';
const ENV_PRODUCTION = 'production';
protected static $apiKeys = array(
self::ENV_STAGING => 'thisisthekeyformystagingenv',
self::ENV_PRODUCTION => 'thisisthekeyformyproductionenv',
);
protected static $environment = self::ENV_PRODUCTION;
public static function getEnvironment()
{
return self::$environment;
}
public static function setEnvironment($environment)
{
self::$environment = $environment;
}
public static function apiCall($call)
{
$environment = self::getEnvironment();
if(array_key_exists(self::$apiKeys, $environment))
$apiKey = self::$apiKeys[$environment];
else throw new Exception("No API key found for current environment '$environment'");
return self::_apiCall($apiKey, $call);
}
protected static function _apiCall($apiKey, $call)
{
// Make the call to the API
}
}
J'espère que cette aide ...