moneta-sdk-php v2.0.0
This commit is contained in:
commit
7a455450ce
16 files changed
+1443
No files matched your search
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Moneta;
|
||||
|
||||
class MonetaSdkSettings {
|
||||
/**
|
||||
* Config file names
|
||||
*/
|
||||
const SETTINGS_ACCOUNT = '/account.php';
|
||||
const SETTINGS_API = '/api.php';
|
||||
const SETTINGS_STORAGE = '/storage.php';
|
||||
const SETTINGS_URL = '/url.php';
|
||||
|
||||
/**
|
||||
* Exception messages text
|
||||
*/
|
||||
const EXCEPTION_ERROR_PARAM_NAME = 'There is no such parameter: ';
|
||||
const EXCEPTION_NO_PARAM_FILE = "Config file not found: ";
|
||||
|
||||
/**
|
||||
* @param null $configPath
|
||||
* @param @nameParam
|
||||
* @return array
|
||||
* @throws MonetaSdkException
|
||||
*/
|
||||
public static function getSettings($nameParam, ?string $configPath = null) {
|
||||
$configPath = $configPath ? $configPath : dirname(__DIR__) . '/config';
|
||||
|
||||
$arrayAccountSettings = self::getSettingsFromConfigFiles($configPath . self::SETTINGS_ACCOUNT);
|
||||
$arrayApiSettings = require dirname(__DIR__) . '/config/api.php';
|
||||
$arrayUrlSettings = self::getSettingsFromConfigFiles($configPath . self::SETTINGS_URL);
|
||||
|
||||
$allSettings = array_merge(
|
||||
$arrayAccountSettings,
|
||||
$arrayApiSettings,
|
||||
$arrayUrlSettings
|
||||
);
|
||||
|
||||
if (!isset($allSettings[$nameParam])) {
|
||||
throw new MonetaSdkException(self::EXCEPTION_ERROR_PARAM_NAME . $nameParam);
|
||||
}
|
||||
|
||||
return $allSettings[$nameParam];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fileName
|
||||
* @return array
|
||||
* @throws MonetaSdkException
|
||||
*/
|
||||
private static function getSettingsFromConfigFiles($fileName) {
|
||||
if (!file_exists($fileName)) {
|
||||
throw new MonetaSdkException(self::EXCEPTION_NO_PARAM_FILE . $fileName);
|
||||
}
|
||||
return require($fileName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user