diff --git a/.~lock.Hasil.ods# b/.~lock.Hasil.ods# new file mode 100644 index 0000000..43d54cb --- /dev/null +++ b/.~lock.Hasil.ods# @@ -0,0 +1 @@ +,DESKTOP-2GSR8J5/Ekky,DESKTOP-2GSR8J5,27.06.2021 02:24,file:///C:/Users/Ekky/AppData/Roaming/LibreOffice/4; \ No newline at end of file diff --git a/Hasil.ods b/Hasil.ods new file mode 100644 index 0000000..2e3c661 Binary files /dev/null and b/Hasil.ods differ diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..aade33f --- /dev/null +++ b/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "5d168508890ed103e7f89cc597b50013", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.1.0" +} diff --git a/example/index.php b/example/index.php index 6aa798e..14fdd3e 100644 --- a/example/index.php +++ b/example/index.php @@ -1,8 +1,9 @@ get('http://belanja-api.herokuapp.com'); +for ($i=0; $i < 10; $i++) { + $response = $curl->get('http://belanja-api.herokuapp.com', ["users_id" => 2]); +} -echo $response; \ No newline at end of file +echo $response; diff --git a/src/Curl.php b/src/Curl.php index a11e938..507326f 100644 --- a/src/Curl.php +++ b/src/Curl.php @@ -77,7 +77,8 @@ * ]; * ``` */ -class Curl { +class Curl +{ const VERSION = 'Curl-PHP-' . PHP_VERSION; @@ -138,7 +139,8 @@ class Curl { */ private $files = array(); - public function __construct() { + public function __construct() + { $this->userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : self::VERSION; } @@ -149,8 +151,9 @@ public function __construct() { * @param array $vars queryParams * @return string response */ - public function get($url, $vars = array()) { - if (!empty($vars)) { + public function get($url, $vars = null) + { + if (isset($vars)) { $url .= (stripos($url, '?') !== false) ? '&' : '?'; $url .= (is_string($vars)) ? $vars : http_build_query($vars, '', '&'); } @@ -163,7 +166,8 @@ public function get($url, $vars = array()) { * @param array $vars postFields * @return string response */ - public function post($url, $vars = array()) { + public function post($url, $vars = array()) + { return $this->request(self::POST, $url, $vars); } @@ -173,7 +177,8 @@ public function post($url, $vars = array()) { * @param array $vars postFields * @return string response */ - public function put($url, $vars = array()) { + public function put($url, $vars = array()) + { return $this->request(self::PUT, $url, $vars); } @@ -183,7 +188,8 @@ public function put($url, $vars = array()) { * @param array $vars postFields * @return string response */ - public function delete($url, $vars = array()) { + public function delete($url, $vars = array()) + { return $this->request(self::DELETE, $url, $vars); } @@ -193,7 +199,8 @@ public function delete($url, $vars = array()) { * @param array $vars [file as key->value] * @return string response */ - public function upload($url, $vars = array()) { + public function upload($url, $vars = array()) + { foreach ($vars as $fieldName => $fileName) { $this->files[] = [ @@ -253,7 +260,8 @@ private function generateBoundary() * @param array $vars * @return string response */ - private function request($method, $url, $vars = array()) { + private function request($method, $url, $vars = array()) + { $this->error = ''; $this->request = curl_init(); if (is_array($vars)) @@ -271,7 +279,8 @@ private function request($method, $url, $vars = array()) { * @param string $method * @return void */ - private function setRequestMethod($method) { + private function setRequestMethod($method) + { switch ($method) { case self::GET: @@ -294,7 +303,8 @@ private function setRequestMethod($method) { * @param string $vars * @return void */ - private function setRequestOptions($url, $vars) { + private function setRequestOptions($url, $vars) + { curl_setopt($this->request, CURLOPT_URL, $url); curl_setopt($this->request, CURLOPT_TIMEOUT, $this->timeout); @@ -313,7 +323,8 @@ private function setRequestOptions($url, $vars) { * [setRequestHeaders] * @return void */ - private function setRequestHeaders() { + private function setRequestHeaders() + { $headers = array(); foreach ($this->headers as $key => $value) { $headers[] = $key . ': ' . $value; @@ -325,7 +336,8 @@ private function setRequestHeaders() { * [generateResponse] * @return string response */ - private function generateResponse() { + private function generateResponse() + { $response = curl_exec($this->request); $header_size = curl_getinfo($this->request, CURLINFO_HEADER_SIZE); @@ -340,5 +352,4 @@ private function generateResponse() { return $content; } - }