/** * Create singleton instance for this class. * * @param array|null $config * @return PayPalCredentialManager */ public static function getInstance($config = null) { if (!self::$instance) { self::$instance = new self($config == null ? PayPalConfigManager::getInstance()->getConfigHashmap() : $config); } return self::$instance; }
/** * Helper method for validating if the class contains accessor methods (getter and setter) for a given attribute * * @param PayPalModel $class An object of PayPalModel * @param string $attributeName Attribute name * @return bool */ public static function validate(PayPalModel $class, $attributeName) { $mode = PayPalConfigManager::getInstance()->get('validation.level'); if (!empty($mode) && $mode != 'disabled') { //Check if $attributeName is string if (gettype($attributeName) !== 'string') { return false; } //If the mode is disabled, bypass the validation foreach (array('set' . $attributeName, 'get' . $attributeName) as $methodName) { if (get_class($class) == get_class(new PayPalModel())) { // Silently return false on cases where you are using PayPalModel instance directly return false; } elseif (!method_exists($class, $methodName)) { //Delegate the error based on the choice $className = is_object($class) ? get_class($class) : (string) $class; $errorMessage = "Missing Accessor: {$className}:{$methodName}. You might be using older version of SDK. If not, create an issue at https://github.com/paypal/PayPal-PHP-SDK/issues"; PayPalLoggingManager::getInstance(__CLASS__)->debug($errorMessage); if ($mode == 'strict') { trigger_error($errorMessage, E_USER_NOTICE); } return false; } } return true; } return false; }
public function initialize() { $config = PayPalConfigManager::getInstance()->getConfigHashmap(); if (!empty($config)) { $this->isLoggingEnabled = array_key_exists('log.LogEnabled', $config) && $config['log.LogEnabled'] == '1'; if ($this->isLoggingEnabled) { $this->loggerFile = $config['log.FileName'] ? $config['log.FileName'] : ini_get('error_log'); $loggingLevel = strtoupper($config['log.LogLevel']); $this->loggingLevel = isset($loggingLevel) && defined("\\Psr\\Log\\LogLevel::{$loggingLevel}") ? constant("\\Psr\\Log\\LogLevel::{$loggingLevel}") : LogLevel::INFO; } } }
/** * Log Debug * * @param string $message */ public function debug($message) { $config = PayPalConfigManager::getInstance()->getConfigHashmap(); // Disable debug in live mode. if (array_key_exists('mode', $config) && $config['mode'] != 'live') { $this->logger->debug($message); } }
/** * Gets a specific configuration from key * * @param $searchKey * @return mixed */ public function get($searchKey) { return PayPalConfigManager::getInstance()->get($searchKey); }
/** * Returns the Value of the key if found in given config, or from PayPal Config Manager * Returns null if not found * * @param $key * @param $config * @return null|string */ private static function getConfigValue($key, $config) { $config = $config && is_array($config) ? $config : PayPalConfigManager::getInstance()->getConfigHashmap(); return array_key_exists($key, $config) ? trim($config[$key]) : null; }
/** * @group integration */ public function testInvalidCredentials() { $this->setExpectedException('PayPal\\Exception\\PayPalConnectionException'); $cred = new OAuthTokenCredential('dummy', 'secret'); $this->assertNull($cred->getAccessToken(PayPalConfigManager::getInstance()->getConfigHashmap())); }
public function testInvalidMagicMethodWithValidationLevel() { PayPalConfigManager::getInstance()->addConfigs(array('validation.level' => 'log')); $obj = new SimpleClass(); $obj->invalid2 = "value2"; $this->assertEquals($obj->invalid2, "value2"); PayPalConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); }
/** * @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 tearDown() { PayPalConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict')); }