PayPal\Common\PayPalUserAgent::getValue PHP Méthode

getValue() public static méthode

Returns the value of the User-Agent header Add environment values and php version numbers
public static getValue ( string $sdkName, string $sdkVersion ) : string
$sdkName string
$sdkVersion string
Résultat string
    public static function getValue($sdkName, $sdkVersion)
    {
        $featureList = array('platform-ver=' . PHP_VERSION, 'bit=' . self::_getPHPBit(), 'os=' . str_replace(' ', '_', php_uname('s') . ' ' . php_uname('r')), 'machine=' . php_uname('m'));
        if (defined('OPENSSL_VERSION_TEXT')) {
            $opensslVersion = explode(' ', OPENSSL_VERSION_TEXT);
            $featureList[] = 'crypto-lib-ver=' . $opensslVersion[1];
        }
        if (function_exists('curl_version')) {
            $curlVersion = curl_version();
            $featureList[] = 'curl=' . $curlVersion['version'];
        }
        return sprintf("PayPalSDK/%s %s (%s)", $sdkName, $sdkVersion, implode('; ', $featureList));
    }

Usage Example

Exemple #1
0
 /**
  * @param PayPalHttpConfig $httpConfig
  * @param string                    $request
  * @param mixed                     $options
  * @return mixed|void
  * @throws PayPalConfigurationException
  * @throws PayPalInvalidCredentialException
  * @throws PayPalMissingCredentialException
  */
 public function handle($httpConfig, $request, $options)
 {
     $credential = $this->apiContext->getCredential();
     $config = $this->apiContext->getConfig();
     if ($credential == null) {
         // Try picking credentials from the config file
         $credMgr = PayPalCredentialManager::getInstance($config);
         $credValues = $credMgr->getCredentialObject();
         if (!is_array($credValues)) {
             throw new PayPalMissingCredentialException("Empty or invalid credentials passed");
         }
         $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
     }
     if ($credential == null || !$credential instanceof OAuthTokenCredential) {
         throw new PayPalInvalidCredentialException("Invalid credentials passed");
     }
     $httpConfig->setUrl(rtrim(trim($this->_getEndpoint($config)), '/') . (isset($options['path']) ? $options['path'] : ''));
     // Overwrite Expect Header to disable 100 Continue Issue
     $httpConfig->addHeader("Expect", null);
     if (!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
         $httpConfig->addHeader("User-Agent", PayPalUserAgent::getValue(PayPalConstants::SDK_NAME, PayPalConstants::SDK_VERSION));
     }
     if (!is_null($credential) && $credential instanceof OAuthTokenCredential && is_null($httpConfig->getHeader('Authorization'))) {
         $httpConfig->addHeader('Authorization', "Bearer " . $credential->getAccessToken($config), false);
     }
     if ($httpConfig->getMethod() == 'POST' || $httpConfig->getMethod() == 'PUT') {
         $httpConfig->addHeader('PayPal-Request-Id', $this->apiContext->getRequestId());
     }
     // Add any additional Headers that they may have provided
     $headers = $this->apiContext->getRequestHeaders();
     foreach ($headers as $key => $value) {
         $httpConfig->addHeader($key, $value);
     }
 }
All Usage Examples Of PayPal\Common\PayPalUserAgent::getValue
PayPalUserAgent