Skip to content

Commit

Permalink
Merge pull request #66 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
Update v3.x
  • Loading branch information
nguyenanhung authored Apr 2, 2024
2 parents 3c30509 + c59ffeb commit 5d7901f
Show file tree
Hide file tree
Showing 15 changed files with 3,894 additions and 3,894 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Library use package: Curl, GuzzleHttp and nuSOAP

- [x] V1.x, V2.x support all PHP version `>=5.6`
- [x] V3.x support all PHP version `>=7.0`
- [x] V4.x support all PHP version `>=8.0`

## Installation

Expand All @@ -26,7 +27,7 @@ unzip master.zip
Step 2: Init to Project

```php
<?php
<?php
require '/your/to/path/MyRequests.php';
use \nguyenanhung\MyRequests\MyRequests;

Expand All @@ -45,7 +46,7 @@ composer require nguyenanhung/requests
Step 2: Init to Project

```php
<?php
<?php
require '/your/to/path/vendor/autoload.php';
use \nguyenanhung\MyRequests\MyRequests;
$requests = new MyRequests();
Expand Down
104 changes: 52 additions & 52 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"name": "nguyenanhung/requests",
"type": "library",
"description": "My Requests Library",
"keywords": [
"request",
"http",
"curl",
"get_content",
"rest",
"soap"
],
"homepage": "https://github.com/nguyenanhung/requests",
"license": "GPL-3.0",
"authors": [
{
"name": "Nguyen An Hung",
"email": "[email protected]",
"homepage": "https://nguyenanhung.com",
"role": "Developer"
}
],
"require": {
"php": ">=7.0",
"ext-curl": "*",
"ext-json": "*",
"ext-iconv": "*",
"symfony/http-foundation": "^6.0 || ^5.3 || ^4.4 || ^3.4",
"symfony/polyfill-mbstring": ">= 1.0",
"php-curl-class/php-curl-class": "^9 || ^8",
"guzzlehttp/guzzle": "^7 || ^6",
"nguyenanhung/nusoap": "^0.9",
"nguyenanhung/my-debug": "^3.0 || ^2.0",
"nguyenanhung/ip-helper": "^2.0 || ^1.0"
},
"require-dev": {
"kint-php/kint": "^5 || ^4 || ^3 || ^2 || ^1"
},
"suggest": {
"ext-curl": "Needed to support cURL",
"ext-json": "Needed to support JSON",
"ext-iconv": "Needed to support iconv",
"ext-openssl": "Needed to support SSL",
"ext-mbstring": "Needed to support mb_string"
},
"autoload": {
"psr-4": {
"nguyenanhung\\MyRequests\\": "src/"
},
"files": [
"helpers/helpers.php"
]
}
"name": "nguyenanhung/requests",
"type": "library",
"description": "My Requests Library",
"keywords": [
"request",
"http",
"curl",
"get_content",
"rest",
"soap"
],
"homepage": "https://github.com/nguyenanhung/requests",
"license": "GPL-3.0",
"authors": [
{
"name": "Nguyen An Hung",
"email": "[email protected]",
"homepage": "https://nguyenanhung.com",
"role": "Developer"
}
],
"require": {
"php": ">=7.0",
"ext-curl": "*",
"ext-json": "*",
"ext-iconv": "*",
"symfony/http-foundation": "^6.0 || ^5.3 || ^4.4 || ^3.4",
"symfony/polyfill-mbstring": ">= 1.0",
"php-curl-class/php-curl-class": "^9 || ^8",
"guzzlehttp/guzzle": "^7 || ^6",
"nguyenanhung/nusoap": "^0.9",
"nguyenanhung/my-debug": "^4.0 || ^3.0 || ^2.0",
"nguyenanhung/ip-helper": "^2.0 || ^1.0"
},
"require-dev": {
"kint-php/kint": "^5 || ^4 || ^3 || ^2 || ^1"
},
"suggest": {
"ext-curl": "Needed to support cURL",
"ext-json": "Needed to support JSON",
"ext-iconv": "Needed to support iconv",
"ext-openssl": "Needed to support SSL",
"ext-mbstring": "Needed to support mb_string"
},
"autoload": {
"psr-4": {
"nguyenanhung\\MyRequests\\": "src/"
},
"files": [
"helpers/helpers.php"
]
}
}
108 changes: 54 additions & 54 deletions helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,62 @@
* Time: 23:16
*/
if (!function_exists('sendSimpleRequest')) {
/**
* Function sendSimpleRequest
*
* @param string $url URL Target Endpoint
* @param string|array|object $data Array Data to Request
* @param string $method GET or POST
*
* @return bool|string|null
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 08/03/2021 20:38
*/
function sendSimpleRequest(string $url = '', $data = [], string $method = 'GET')
{
$target = (!empty($data) && (is_array($data) || is_object($data))) ? $url . '?' . http_build_query($data) : $url;
$method = mb_strtoupper($method);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $target,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$message = "cURL Error #: " . $err;
if (function_exists('log_message')) {
log_message('error', $message);
}
/**
* Function sendSimpleRequest
*
* @param string $url URL Target Endpoint
* @param string|array|object $data Array Data to Request
* @param string $method GET or POST
*
* @return bool|string|null
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 08/03/2021 20:38
*/
function sendSimpleRequest(string $url = '', $data = [], string $method = 'GET')
{
$target = (!empty($data) && (is_array($data) || is_object($data))) ? $url . '?' . http_build_query($data) : $url;
$method = mb_strtoupper($method);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $target,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
$message = "cURL Error #: " . $err;
if (function_exists('log_message')) {
log_message('error', $message);
}

return null;
}
return null;
}

return $response;
}
return $response;
}
}
if (!function_exists('getIpAddress')) {
/**
* Function getIpAddress
*
* @param bool $convertToInteger
*
* @return bool|int|string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/20/2021 10:36
*/
function getIpAddress(bool $convertToInteger = false)
{
$ip = new nguyenanhung\MyRequests\Ip();
return $ip->getIpAddress($convertToInteger);
}
/**
* Function getIpAddress
*
* @param bool $convertToInteger
*
* @return bool|int|string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/20/2021 10:36
*/
function getIpAddress(bool $convertToInteger = false)
{
$ip = new nguyenanhung\MyRequests\Ip();
return $ip->getIpAddress($convertToInteger);
}
}
Loading

0 comments on commit 5d7901f

Please sign in to comment.