From 46173d50f4267bc3c31621b81cb37be4bef6724e Mon Sep 17 00:00:00 2001 From: Nur Wachid Date: Mon, 29 Apr 2019 22:24:55 +0700 Subject: [PATCH] edit data request json --- src/Request.php | 9 ++------- src/Response/SimpleJSONElement.php | 7 +++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Request.php b/src/Request.php index 1684e18..caf16b1 100644 --- a/src/Request.php +++ b/src/Request.php @@ -623,15 +623,10 @@ public function getResponse() * * @return bool|\O2System\Curl\Response */ - public function post(array $fields = [], $format = 'QUERY') + public function post(array $fields = []) { $this->curlOptions[ CURLOPT_POST ] = true; - - if ($format === 'QUERY') { - $this->curlOptions[ CURLOPT_POSTFIELDS ] = http_build_query($fields, null, '&', PHP_QUERY_RFC3986); - } elseif ($format === 'JSON') { - $this->curlOptions[ CURLOPT_POSTFIELDS ] = json_encode($fields); - } + $this->curlOptions[ CURLOPT_POSTFIELDS ] = http_build_query($fields, null, '&', PHP_QUERY_RFC3986); return $this->getResponse(); } diff --git a/src/Response/SimpleJSONElement.php b/src/Response/SimpleJSONElement.php index 8c809d2..4bbb2e0 100644 --- a/src/Response/SimpleJSONElement.php +++ b/src/Response/SimpleJSONElement.php @@ -31,6 +31,13 @@ class SimpleJSONElement extends SplArrayObject */ public function __construct(array $elements = []) { + foreach ($elements as $key => $value) { + if (strpos($key, '_') !== false) { + $elements[ camelcase($key) ] = $value; + unset($elements[ $key ]); + } + } + parent::__construct($elements); } } \ No newline at end of file