From e3412d6ce4888267fbfc693b6aaa84d056fd500e Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Mon, 14 Aug 2023 14:11:02 +0700 Subject: [PATCH] Release version 3.1.0 --- src/CurlData.php | 27 ++++++---- src/MyRequests.php | 103 ++++++++++++++++++++++----------------- src/ProjectInterface.php | 2 +- 3 files changed, 75 insertions(+), 57 deletions(-) diff --git a/src/CurlData.php b/src/CurlData.php index 238358e..e964e82 100644 --- a/src/CurlData.php +++ b/src/CurlData.php @@ -639,17 +639,24 @@ public function createCurl(string $url = ''): self curl_setopt($curl, CURLOPT_REFERER, $this->referer); } curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent); - $this->response_headers = array(); - $this->response = curl_exec($curl); - $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - $this->curl_error_code = curl_errno($curl); + $parseUrl = parse_url($url); + if (isset($parseUrl['scheme']) && $parseUrl['scheme'] === 'https') { + curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + } + if (isset($parseUrl['scheme']) && $parseUrl['scheme'] === 'http') { + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + } + $this->response_headers = array(); + $this->response = curl_exec($curl); + $this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $this->curl_error_code = curl_errno($curl); $this->curl_error_message = curl_error($curl); - $this->curl_error = !($this->curl_error_code === 0); - $this->http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - $this->http_error = in_array(floor($this->http_status_code / 100), array(4, 5), true); - $this->error = $this->curl_error || $this->http_error; - $this->error_code = $this->error ? ($this->curl_error ? $this->curl_error_code : $this->http_status_code) : 0; - $this->request_headers = preg_split('/\r\n/', curl_getinfo($curl, CURLINFO_HEADER_OUT), null, PREG_SPLIT_NO_EMPTY); + $this->curl_error = !($this->curl_error_code === 0); + $this->http_status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $this->http_error = in_array(floor($this->http_status_code / 100), array(4, 5), true); + $this->error = $this->curl_error || $this->http_error; + $this->error_code = $this->error ? ($this->curl_error ? $this->curl_error_code : $this->http_status_code) : 0; + $this->request_headers = preg_split('/\r\n/', curl_getinfo($curl, CURLINFO_HEADER_OUT), null, PREG_SPLIT_NO_EMPTY); if (isset($this->response_headers['0'])) { if ($this->error) { $this->http_error_message = ($this->response_headers['0']); diff --git a/src/MyRequests.php b/src/MyRequests.php index 7ddb764..3630b41 100644 --- a/src/MyRequests.php +++ b/src/MyRequests.php @@ -254,6 +254,7 @@ public function __destruct() public function setDebugStatus(bool $debugStatus): self { $this->debugStatus = $debugStatus; + return $this; } @@ -270,6 +271,7 @@ public function setDebugStatus(bool $debugStatus): self public function setDebugLevel(string $debugLevel): self { $this->debugLevel = $debugLevel; + return $this; } @@ -286,6 +288,7 @@ public function setDebugLevel(string $debugLevel): self public function setDebugLoggerPath(string $debugLoggerPath): self { $this->debugLoggerPath = $debugLoggerPath; + return $this; } @@ -302,6 +305,7 @@ public function setDebugLoggerPath(string $debugLoggerPath): self public function setDebugLoggerFilename(string $debugLoggerFilename): self { $this->debugLoggerFilename = $debugLoggerFilename; + return $this; } @@ -674,8 +678,8 @@ public function getResponseHeader() * Function guzzlePhpRequest * Send Request use GuzzleHttp\Client - https://packagist.org/packages/guzzlehttp/guzzle * - * @param string $url URL Endpoint to be Request - * @param array $data Data Content to be Request + * @param string $url URL Endpoint to be Request + * @param array $data Data Content to be Request * @param string $method Set Method to be Request * * @return array|\Psr\Http\Message\ResponseInterface|\Psr\Http\Message\StreamInterface|string|null @@ -705,7 +709,7 @@ public function guzzlePhpRequest(string $url = '', array $data = array(), string $client = new Client(); // Create options $options = array( - 'timeout' => $this->timeout, + 'timeout' => $this->timeout, 'connect_timeout' => $this->timeout ); if (is_array($this->headers) && count($this->headers) > 0) { @@ -762,29 +766,29 @@ public function guzzlePhpRequest(string $url = '', array $data = array(), string $status_message = $request->getReasonPhrase(); $http_error = in_array(floor($this->http_code / 100), [4, 5], true); $error_code = array( - 'status' => $status_code, - 'error' => $status_code, - 'error_code' => $status_code, + 'status' => $status_code, + 'error' => $status_code, + 'error_code' => $status_code, 'error_message' => $status_message, - 'http_error' => array( - 'http_error' => $http_error, - 'http_status_code' => $status_code, + 'http_error' => array( + 'http_error' => $http_error, + 'http_status_code' => $status_code, 'http_error_message' => $status_message ), - 'headers' => array( - 'request_headers' => $this->headers, + 'headers' => array( + 'request_headers' => $this->headers, 'response_headers' => $request->getHeaders() ), - 'data' => array( - 'status' => $request->getStatusCode(), - 'error_code' => $request->getStatusCode(), - 'error_message' => $request->getReasonPhrase(), - 'reasonPhrase' => $request->getReasonPhrase(), - 'protocolVersion' => $request->getProtocolVersion(), - 'headers' => $request->getHeaders(), - 'requests_url' => $endpoint, + 'data' => array( + 'status' => $request->getStatusCode(), + 'error_code' => $request->getStatusCode(), + 'error_message' => $request->getReasonPhrase(), + 'reasonPhrase' => $request->getReasonPhrase(), + 'protocolVersion' => $request->getProtocolVersion(), + 'headers' => $request->getHeaders(), + 'requests_url' => $endpoint, 'requests_options' => $this->options, - 'response_body' => $request->getBody() + 'response_body' => $request->getBody() ) ); $this->http_code = $status_code; @@ -828,9 +832,9 @@ public function guzzlePhpRequest(string $url = '', array $data = array(), string * Function curlRequest * Send Request use \Curl\Curl class - https://packagist.org/packages/curl/curl * - * @param string $url URL Endpoint to be Request - * @param array|string $data Data Content to be Request - * @param string $method Set Method to be Request + * @param string $url URL Endpoint to be Request + * @param array|string $data Data Content to be Request + * @param string $method Set Method to be Request * * @return array|null|string Response content from server, * null of Exception Message if Error @@ -877,9 +881,16 @@ public function curlRequest(string $url = '', array $data = array(), string $met if ($this->referrer) { $curl->setReferer($this->referrer); } + $parseUrl = parse_url($url); $curl->setOpt(CURLOPT_RETURNTRANSFER, self::RETURN_TRANSFER); $curl->setOpt(CURLOPT_SSL_VERIFYPEER, $this->isSSL); $curl->setOpt(CURLOPT_SSL_VERIFYHOST, $this->isSSL); + if (isset($parseUrl['scheme']) && $parseUrl['scheme'] === 'https') { + $curl->setOpt(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + } + if (isset($parseUrl['scheme']) && $parseUrl['scheme'] === 'http') { + $curl->setOpt(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + } $curl->setOpt(CURLOPT_SSLVERSION, 6); $curl->setOpt(CURLOPT_ENCODING, self::ENCODING); $curl->setOpt(CURLOPT_MAXREDIRS, self::MAX_REDIRECT); @@ -1048,22 +1059,22 @@ protected function curlRequestErrorParse($curl): array } return array( - 'status' => $resErrorCode, - 'error' => $curl->error, - 'error_code' => $resErrorCode, + 'status' => $resErrorCode, + 'error' => $curl->error, + 'error_code' => $resErrorCode, 'error_message' => $resErrorMessage, - 'curl_error' => array( - 'curl_error' => $resErrorCurl, - 'curl_error_code' => $resErrorCurlCode, + 'curl_error' => array( + 'curl_error' => $resErrorCurl, + 'curl_error_code' => $resErrorCurlCode, 'curl_error_message' => $resErrorCurlMessage ), - 'http_error' => array( - 'http_error' => $resErrorHttp, - 'http_status_code' => $resErrorHttpStatusCode, + 'http_error' => array( + 'http_error' => $resErrorHttp, + 'http_status_code' => $resErrorHttpStatusCode, 'http_error_message' => $resErrorHttpMessage ), - 'headers' => array( - 'request_headers' => $resRequestHeaders, + 'headers' => array( + 'request_headers' => $resRequestHeaders, 'response_headers' => $resResponseHeaders ) ); @@ -1073,9 +1084,9 @@ protected function curlRequestErrorParse($curl): array * Function sendRequest * Handle send Request use Multi Method * - * @param string $url URL Endpoint to be Request - * @param array|string $data Data Content to be Request - * @param string $method Set Method to be Request + * @param string $url URL Endpoint to be Request + * @param array|string $data Data Content to be Request + * @param string $method Set Method to be Request * * @return array|mixed|object|\Psr\Http\Message\ResponseInterface|\Psr\Http\Message\StreamInterface|string|null Response content from server * null of Exception Message if Error @@ -1140,9 +1151,9 @@ public function sendRequest(string $url = '', $data = array(), string $method = * Function xmlRequest * Send XML Request to Server * - * @param string $url URL Endpoint to be Request - * @param string $data Data Content to be Request - * @param int $timeout Timeout Request + * @param string $url URL Endpoint to be Request + * @param string $data Data Content to be Request + * @param int $timeout Timeout Request * * @return array|null|string Response from Server * @author: 713uk13m @@ -1192,9 +1203,9 @@ public function xmlRequest(string $url = '', string $data = '', int $timeout = 6 * Function jsonRequest * Send JSON Request to Server * - * @param string $url URL Endpoint to be Request - * @param array $data Data Content to be Request - * @param int $timeout Timeout Request + * @param string $url URL Endpoint to be Request + * @param array $data Data Content to be Request + * @param int $timeout Timeout Request * * @return array|null|string Response from Server * @author: 713uk13m @@ -1246,8 +1257,8 @@ public function jsonRequest(string $url = '', array $data = array(), int $timeou /** * Function xmlGetValue * - * @param string $xml XML String - * @param string $openTag OpenTag to find + * @param string $xml XML String + * @param string $openTag OpenTag to find * @param string $closeTag CloseTag to find * * @return string Result from Tag, Empty string if not @@ -1281,7 +1292,7 @@ public function xmlGetValue(string $xml = '', string $openTag = '', string $clos public function parseXmlDataRequest(string $resultXml = '') { $array = array( - 'ec' => $this->xmlGetValue($resultXml, "", ""), + 'ec' => $this->xmlGetValue($resultXml, "", ""), 'msg' => $this->xmlGetValue($resultXml, "", "") ); diff --git a/src/ProjectInterface.php b/src/ProjectInterface.php index e8dd36d..83b26ce 100644 --- a/src/ProjectInterface.php +++ b/src/ProjectInterface.php @@ -18,7 +18,7 @@ */ interface ProjectInterface { - const VERSION = '3.0.9'; + const VERSION = '3.1.0'; const LAST_MODIFIED = '2023-08-13'; const MIN_PHP_VERSION = '7.0'; const GET = 'GET';