getInstance() public static method

Returns the singleton object
public static getInstance ( string $loggerName = __CLASS__ )
$loggerName string
コード例 #1
0
 /**
  * Construct
  *
  * @param string $clientId     client id obtained from the developer portal
  * @param string $clientSecret client secret obtained from the developer portal
  */
 public function __construct($clientId, $clientSecret)
 {
     $this->clientId = $clientId;
     $this->clientSecret = $clientSecret;
     $this->cipher = new Cipher($this->clientSecret);
     $this->logger = PayPalLoggingManager::getInstance(__CLASS__);
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * Default Constructor
  *
  * @param PayPalHttpConfig $httpConfig
  * @param array            $config
  * @throws PayPalConfigurationException
  */
 public function __construct(PayPalHttpConfig $httpConfig, array $config)
 {
     if (!function_exists("curl_init")) {
         throw new PayPalConfigurationException("Curl module is not available on this system");
     }
     $this->httpConfig = $httpConfig;
     $this->logger = PayPalLoggingManager::getInstance(__CLASS__);
 }
コード例 #4
0
ファイル: OAuthTokenCredential.php プロジェクト: Roc4rdho/app
 /**
  * Generates a new access token
  *
  * @param array $config
  * @param null|string $refreshToken
  * @return null
  * @throws PayPalConnectionException
  */
 private function generateAccessToken($config, $refreshToken = null)
 {
     $params = array('grant_type' => 'client_credentials');
     if ($refreshToken != null) {
         // If the refresh token is provided, it would get access token using refresh token
         // Used for Future Payments
         $params['grant_type'] = 'refresh_token';
         $params['refresh_token'] = $refreshToken;
     }
     $payload = http_build_query($params);
     $response = $this->getToken($config, $this->clientId, $this->clientSecret, $payload);
     if ($response == null || !isset($response["access_token"]) || !isset($response["expires_in"])) {
         $this->accessToken = null;
         $this->tokenExpiresIn = null;
         PayPalLoggingManager::getInstance(__CLASS__)->warning("Could not generate new Access token. Invalid response from server: ");
         throw new PayPalConnectionException(null, "Could not generate new Access token. Invalid response from server: ");
     } else {
         $this->accessToken = $response["access_token"];
         $this->tokenExpiresIn = $response["expires_in"];
     }
     $this->tokenCreateTime = time();
     return $this->accessToken;
 }
コード例 #5
0
 /**
  * Default Constructor
  *
  * @param ApiContext $apiContext
  */
 public function __construct(ApiContext $apiContext)
 {
     $this->apiContext = $apiContext;
     $this->logger = PayPalLoggingManager::getInstance(__CLASS__);
 }
コード例 #6
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = PayPalLoggingManager::getInstance('InvoiceTest');
 }