3 use PayPal\Core\PPConfigManager;
4 use PayPal\Exception\PPConfigurationException;
6 * PPConfigManager loads the SDK configuration file and
7 * hands out appropriate config params to other classes
11 class PPConfigManager {
15 * @var PPConfigManager
18 //default config values
19 public static $defaults = array(
20 "http.ConnectionTimeOut" => "30",
24 private static $instance;
26 private function __construct(){
27 if(defined('PP_CONFIG_PATH')) {
28 $configFile = constant('PP_CONFIG_PATH') . '/sdk_config.ini';
30 $configFile = implode(DIRECTORY_SEPARATOR,
31 array(dirname(__FILE__), "..", "config", "sdk_config.ini"));
33 $this->load($configFile);
36 // create singleton object for PPConfigManager
37 public static function getInstance()
39 if ( !isset(self::$instance) ) {
40 self::$instance = new PPConfigManager();
42 return self::$instance;
45 //used to load the file
46 private function load($fileName) {
48 $this->config = @parse_ini_file($fileName);
49 if($this->config == NULL || count($this->config) == 0) {
50 throw new PPConfigurationException("Config file $fileName not found","303");
55 * simple getter for configuration params
56 * If an exact match for key is not found,
57 * does a "contains" search on the key
59 public function get($searchKey){
61 if(array_key_exists($searchKey, $this->config))
63 return $this->config[$searchKey];
67 foreach ($this->config as $k => $v){
68 if(strstr($k, $searchKey)){
79 * Utility method for handling account configuration
80 * return config key corresponding to the API userId passed in
82 * If $userId is null, returns config keys corresponding to
83 * all configured accounts
85 public function getIniPrefix($userId = null) {
89 foreach ($this->config as $key => $value) {
90 $pos = strpos($key, '.');
91 if(strstr($key, "acct")){
92 $arr[] = substr($key, 0, $pos);
95 return array_unique($arr);
97 $iniPrefix = array_search($userId, $this->config);
98 $pos = strpos($iniPrefix, '.');
99 $acct = substr($iniPrefix, 0, $pos);
106 * returns the config file hashmap
109 public function getConfigHashmap()
111 return $this->config;
115 * use the default configuration if it is not passed in hashmap
117 public static function mergrDefaults($config)
119 return array_merge(PPConfigManager::$defaults, $config);