Skip to content

Commit

Permalink
Merge pull request #64 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
Release version 3.1.0
  • Loading branch information
nguyenanhung authored Aug 14, 2023
2 parents dfe76f3 + e3412d6 commit c97f148
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 57 deletions.
27 changes: 17 additions & 10 deletions src/CurlData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
103 changes: 57 additions & 46 deletions src/MyRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public function __destruct()
public function setDebugStatus(bool $debugStatus): self
{
$this->debugStatus = $debugStatus;

return $this;
}

Expand All @@ -270,6 +271,7 @@ public function setDebugStatus(bool $debugStatus): self
public function setDebugLevel(string $debugLevel): self
{
$this->debugLevel = $debugLevel;

return $this;
}

Expand All @@ -286,6 +288,7 @@ public function setDebugLevel(string $debugLevel): self
public function setDebugLoggerPath(string $debugLoggerPath): self
{
$this->debugLoggerPath = $debugLoggerPath;

return $this;
}

Expand All @@ -302,6 +305,7 @@ public function setDebugLoggerPath(string $debugLoggerPath): self
public function setDebugLoggerFilename(string $debugLoggerFilename): self
{
$this->debugLoggerFilename = $debugLoggerFilename;

return $this;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
)
);
Expand All @@ -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
Expand Down Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>", "</ec>"),
'ec' => $this->xmlGetValue($resultXml, "<ec>", "</ec>"),
'msg' => $this->xmlGetValue($resultXml, "<msg>", "</msg>")
);

Expand Down
2 changes: 1 addition & 1 deletion src/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit c97f148

Please sign in to comment.