From 2ba3584eaaa29697f6d6cee6ac9b78aac2f57224 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 19 Feb 2015 14:05:48 +0700 Subject: [PATCH] Reorder class functions --- src/Curl/Curl.php | 102 +++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 24e431e..a6de01b 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -65,6 +65,57 @@ class Curl $this->before_send_function = $callback; } + public function buildPostData($data) + { + if (is_array($data)) { + if (self::is_array_multidim($data)) { + if (isset($this->headers['Content-Type']) && + preg_match($this->json_pattern, $this->headers['Content-Type'])) { + $json_str = json_encode($data); + if (!($json_str === false)) { + $data = $json_str; + } + } else { + $data = self::http_build_multi_query($data); + } + } else { + $binary_data = false; + foreach ($data as $key => $value) { + // Fix "Notice: Array to string conversion" when $value in + // curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array + // that contains an empty array. + if (is_array($value) && empty($value)) { + $data[$key] = ''; + // Fix "curl_setopt(): The usage of the @filename API for + // file uploading is deprecated. Please use the CURLFile + // class instead". + } elseif (is_string($value) && strpos($value, '@') === 0) { + $binary_data = true; + if (class_exists('CURLFile')) { + $data[$key] = new \CURLFile(substr($value, 1)); + } + } elseif ($value instanceof \CURLFile) { + $binary_data = true; + } + } + + if (!$binary_data) { + if (isset($this->headers['Content-Type']) && + preg_match($this->json_pattern, $this->headers['Content-Type'])) { + $json_str = json_encode($data); + if (!($json_str === false)) { + $data = $json_str; + } + } else { + $data = http_build_query($data); + } + } + } + } + + return $data; + } + public function call($function) { if (is_callable($function)) { @@ -223,57 +274,6 @@ class Curl return $this->exec(); } - public function buildPostData($data) - { - if (is_array($data)) { - if (self::is_array_multidim($data)) { - if (isset($this->headers['Content-Type']) && - preg_match($this->json_pattern, $this->headers['Content-Type'])) { - $json_str = json_encode($data); - if (!($json_str === false)) { - $data = $json_str; - } - } else { - $data = self::http_build_multi_query($data); - } - } else { - $binary_data = false; - foreach ($data as $key => $value) { - // Fix "Notice: Array to string conversion" when $value in - // curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array - // that contains an empty array. - if (is_array($value) && empty($value)) { - $data[$key] = ''; - // Fix "curl_setopt(): The usage of the @filename API for - // file uploading is deprecated. Please use the CURLFile - // class instead". - } elseif (is_string($value) && strpos($value, '@') === 0) { - $binary_data = true; - if (class_exists('CURLFile')) { - $data[$key] = new \CURLFile(substr($value, 1)); - } - } elseif ($value instanceof \CURLFile) { - $binary_data = true; - } - } - - if (!$binary_data) { - if (isset($this->headers['Content-Type']) && - preg_match($this->json_pattern, $this->headers['Content-Type'])) { - $json_str = json_encode($data); - if (!($json_str === false)) { - $data = $json_str; - } - } else { - $data = http_build_query($data); - } - } - } - } - - return $data; - } - public function put($url, $data = array()) { $this->setURL($url);