PayPalCorePayPalConfigManager

Class PayPalConfigManager.

Defined (1)

The class is defined in the following location(s).

/classes/lib/PayPal/Core/PayPalConfigManager.php  
  1. class PayPalConfigManager 
  2.  
  3. /** 
  4. * Configuration Options 
  5. * @var array 
  6. */ 
  7. private $configs = array( 
  8. ); 
  9.  
  10. /** 
  11. * Singleton Object 
  12. * @var $this 
  13. */ 
  14. private static $instance; 
  15.  
  16. /** 
  17. * Private Constructor 
  18. */ 
  19. private function __construct() 
  20. if (defined('PP_CONFIG_PATH')) { 
  21. $configFile = constant('PP_CONFIG_PATH') . '/sdk_config.ini'; 
  22. } else { 
  23. $configFile = implode(DIRECTORY_SEPARATOR,  
  24. array(dirname(__FILE__), "..", "config", "sdk_config.ini")); 
  25. if (file_exists($configFile)) { 
  26. $this->addConfigFromIni($configFile); 
  27.  
  28. /** 
  29. * Returns the singleton object 
  30. * @return $this 
  31. */ 
  32. public static function getInstance() 
  33. if (!isset(self::$instance)) { 
  34. self::$instance = new self(); 
  35. return self::$instance; 
  36.  
  37. /** 
  38. * Add Configuration from configuration.ini files 
  39. * @param string $fileName 
  40. * @return $this 
  41. */ 
  42. public function addConfigFromIni($fileName) 
  43. if ($configs = parse_ini_file($fileName)) { 
  44. $this->addConfigs($configs); 
  45. return $this; 
  46.  
  47. /** 
  48. * If a configuration exists in both arrays,  
  49. * then the element from the first array will be used and 
  50. * the matching key's element from the second array will be ignored. 
  51. * @param array $configs 
  52. * @return $this 
  53. */ 
  54. public function addConfigs($configs = array()) 
  55. $this->configs = $configs + $this->configs; 
  56. return $this; 
  57.  
  58. /** 
  59. * Simple getter for configuration params 
  60. * If an exact match for key is not found,  
  61. * does a "contains" search on the key 
  62. * @param string $searchKey 
  63. * @return array 
  64. */ 
  65. public function get($searchKey) 
  66.  
  67. if (array_key_exists($searchKey, $this->configs)) { 
  68. return $this->configs[$searchKey]; 
  69. } else { 
  70. $arr = array(); 
  71. foreach ($this->configs as $k => $v) { 
  72. if (strstr($k, $searchKey)) { 
  73. $arr[$k] = $v; 
  74.  
  75. return $arr; 
  76.  
  77.  
  78. /** 
  79. * Utility method for handling account configuration 
  80. * return config key corresponding to the API userId passed in 
  81. * If $userId is null, returns config keys corresponding to 
  82. * all configured accounts 
  83. * @param string|null $userId 
  84. * @return array|string 
  85. */ 
  86. public function getIniPrefix($userId = null) 
  87.  
  88. if ($userId == null) { 
  89. $arr = array(); 
  90. foreach ($this->configs as $key => $value) { 
  91. $pos = strpos($key, '.'); 
  92. if (strstr($key, "acct")) { 
  93. $arr[] = substr($key, 0, $pos); 
  94. return array_unique($arr); 
  95. } else { 
  96. $iniPrefix = array_search($userId, $this->configs); 
  97. $pos = strpos($iniPrefix, '.'); 
  98. $acct = substr($iniPrefix, 0, $pos); 
  99.  
  100. return $acct; 
  101.  
  102. /** 
  103. * returns the config file hashmap 
  104. */ 
  105. public function getConfigHashmap() 
  106. return $this->configs; 
  107.  
  108. /** 
  109. * Disabling __clone call 
  110. */ 
  111. public function __clone() 
  112. trigger_error('Clone is not allowed.', E_USER_ERROR); 
  113.