Stripe\Util\Util::utf8 PHP 메소드

utf8() 공개 정적인 메소드

public static utf8 ( string | mixed $value ) : string | mixed
$value string | mixed A string to UTF8-encode.
리턴 string | mixed The UTF8-encoded string, or the object passed in if it wasn't a string.
    public static function utf8($value)
    {
        if (self::$isMbstringAvailable === null) {
            self::$isMbstringAvailable = function_exists('mb_detect_encoding');
            if (!self::$isMbstringAvailable) {
                trigger_error("It looks like the mbstring extension is not enabled. " . "UTF-8 strings will not properly be encoded. Ask your system " . "administrator to enable the mbstring extension, or write to " . "[email protected] if you have any questions.", E_USER_WARNING);
            }
        }
        if (is_string($value) && self::$isMbstringAvailable && mb_detect_encoding($value, "UTF-8", true) != "UTF-8") {
            return utf8_encode($value);
        } else {
            return $value;
        }
    }

Usage Example

예제 #1
0
 public function request($method, $absUrl, $headers, $params, $hasFile)
 {
     $curl = curl_init();
     $method = strtolower($method);
     $opts = array();
     if ($method == 'get') {
         if ($hasFile) {
             throw new Error\Api("Issuing a GET request with a file parameter");
         }
         $opts[CURLOPT_HTTPGET] = 1;
         if (count($params) > 0) {
             $encoded = self::encode($params);
             $absUrl = "{$absUrl}?{$encoded}";
         }
     } elseif ($method == 'post') {
         $opts[CURLOPT_POST] = 1;
         $opts[CURLOPT_POSTFIELDS] = $hasFile ? $params : self::encode($params);
     } elseif ($method == 'delete') {
         $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
         if (count($params) > 0) {
             $encoded = self::encode($params);
             $absUrl = "{$absUrl}?{$encoded}";
         }
     } else {
         throw new Error\Api("Unrecognized method {$method}");
     }
     $absUrl = Util\Util::utf8($absUrl);
     $opts[CURLOPT_URL] = $absUrl;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_CONNECTTIMEOUT] = 30;
     $opts[CURLOPT_TIMEOUT] = 80;
     $opts[CURLOPT_RETURNTRANSFER] = true;
     $opts[CURLOPT_HTTPHEADER] = $headers;
     if (!Stripe::$verifySslCerts) {
         $opts[CURLOPT_SSL_VERIFYPEER] = false;
     }
     curl_setopt_array($curl, $opts);
     $rbody = curl_exec($curl);
     if (!defined('CURLE_SSL_CACERT_BADFILE')) {
         define('CURLE_SSL_CACERT_BADFILE', 77);
         // constant not defined in PHP
     }
     $errno = curl_errno($curl);
     if ($errno == CURLE_SSL_CACERT || $errno == CURLE_SSL_PEER_CERTIFICATE || $errno == CURLE_SSL_CACERT_BADFILE) {
         array_push($headers, 'X-Stripe-Client-Info: {"ca":"using Stripe-supplied CA bundle"}');
         $cert = self::caBundle();
         curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($curl, CURLOPT_CAINFO, $cert);
         $rbody = curl_exec($curl);
     }
     if ($rbody === false) {
         $errno = curl_errno($curl);
         $message = curl_error($curl);
         curl_close($curl);
         $this->handleCurlError($absUrl, $errno, $message);
     }
     $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     return array($rbody, $rcode);
 }
All Usage Examples Of Stripe\Util\Util::utf8