create singleton object for PPConfigManager
public static getInstance ( ) |
public function getConfig() { if (!isset($this->config)) { $this->config = PPConfigManager::getInstance()->getConfigHashmap(); } return $this->config; }
public function __construct($serviceName, $serviceBinding, $handlers = array(), $config = null) { $this->serviceName = $serviceName; $this->serviceBinding = $serviceBinding; $this->handlers = $handlers; if ($config == null) { $configFile = PPConfigManager::getInstance(); $this->config = $configFile->getConfigHashmap(); } else { $this->config = PPConfigManager::mergrDefaults($config); } }
/** * @test */ public function testMergeWithDefaults() { // Test file based config params and defaults $config = PPConfigManager::getInstance()->getConfigWithDefaults(array()); $this->assertArrayHasKey('mode', $config, 'file config not read when no custom config is passed'); $this->assertEquals('sandbox', $config['mode']); $this->assertEquals(60, $config['http.ConnectionTimeOut']); // Test custom config params and defaults $config = PPConfigManager::getInstance()->getConfigWithDefaults(array('mode' => 'custom')); $this->assertArrayHasKey('mode', $config); $this->assertEquals('custom', $config['mode']); $this->assertEquals(30, $config['http.ConnectionTimeOut']); // Test override for default connection params $config = PPConfigManager::getInstance()->getConfigWithDefaults(array('mode' => 'custom', 'http.ConnectionTimeOut' => 100)); $this->assertArrayHasKey('mode', $config); $this->assertEquals('custom', $config['mode']); $this->assertEquals(100, $config['http.ConnectionTimeOut']); }
/** * * @param string $postData OPTIONAL post data. If null, * the class automatically reads incoming POST data * from the input stream */ public function __construct($postData = '', $config = null) { if ($config == null) { $conf = PPConfigManager::getInstance(); $this->config = $conf->config; } else { $this->config = $config; } if ($postData == '') { // reading posted data from directly from $_POST may causes serialization issues with array data in POST // reading raw POST data from input stream instead. $postData = file_get_contents('php://input'); } $rawPostArray = explode('&', $postData); foreach ($rawPostArray as $keyValue) { $keyValue = explode('=', $keyValue); if (count($keyValue) == 2) { $this->ipnData[$keyValue[0]] = urldecode($keyValue[1]); } } //var_dump($this->ipnData); }
/** * use the default configuration if it is not passed in hashmap */ public static function getConfigWithDefaults($config = null) { return array_merge(PPConfigManager::$defaults, $config != null ? $config : PPConfigManager::getInstance()->getConfigHashmap()); }
/** * @test */ public function testGetInstance() { $instance = $this->object->getInstance(); $this->assertTrue($instance instanceof PPConfigManager); }
/** * @param null $ClientId * @param null $ClientSecret * @return PayPal/Auth/OAuthTokenCredential */ public static function OAuthTokenCredential($ClientId = null, $ClientSecret = null) { //define("PP_CONFIG_PATH", __DIR__); if (isset($ClientId) && isset($ClientSecret)) { return new OAuthTokenCredential($ClientId, $ClientSecret); } $configManager = PPConfigManager::getInstance(); // $cred is used by samples that include this bootstrap file // This piece of code simply demonstrates how you can // dynamically pass in a client id/secret instead of using // the config file. If you do not need a way to pass // in credentials dynamically, you can skip the // <Resource>::setCredential($cred) calls that // you see in the samples. $cred = new OAuthTokenCredential($configManager->get('acct1.ClientId'), $configManager->get('acct1.ClientSecret')); return $cred; }
public function testInvalidCredentials() { $this->setExpectedException('PayPal\\Exception\\PPConnectionException'); $cred = new OAuthTokenCredential('dummy', 'secret'); $this->assertNull($cred->getAccessToken(PPConfigManager::getInstance()->getConfigHashmap())); }
public function get($searchKey) { if (!isset($this->config)) { return PPConfigManager::getInstance()->get($searchKey); } else { if (array_key_exists($searchKey, $this->getConfig())) { return $this->config[$searchKey]; } } return false; }