From d2d4fe3f5a6000e1e1677e4b4f58e25e77fcc8ed Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 24 Jul 2016 01:10:26 -0700 Subject: [PATCH] Move JSON content-type pattern encode check to start of Curl::buildPostData --- src/Curl/Curl.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index e1f3dca..d4ac087 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -136,16 +136,14 @@ class Curl public function buildPostData($data) { if (is_array($data)) { - if (self::is_array_multidim($data)) { - if (isset($this->headers['Content-Type']) && - preg_match($this->jsonPattern, $this->headers['Content-Type'])) { - $json_str = json_encode($data); - if (!($json_str === false)) { - $data = $json_str; - } - } else { - $data = self::http_build_multi_query($data); + if (isset($this->headers['Content-Type']) && + preg_match($this->jsonPattern, $this->headers['Content-Type'])) { + $json_str = json_encode($data); + if (!($json_str === false)) { + $data = $json_str; } + } else if (self::is_array_multidim($data)) { + $data = self::http_build_multi_query($data); } else { $binary_data = false; foreach ($data as $key => $value) { @@ -166,15 +164,7 @@ class Curl } if (!$binary_data) { - if (isset($this->headers['Content-Type']) && - preg_match($this->jsonPattern, $this->headers['Content-Type'])) { - $json_str = json_encode($data); - if (!($json_str === false)) { - $data = $json_str; - } - } else { - $data = http_build_query($data, '', '&'); - } + $data = http_build_query($data, '', '&'); } } }