Skip to content

Commit 875e003

Browse files
authored
Merge pull request #45 from nguyenanhung/develop
Add simple helpers
2 parents afa6de6 + b1955a1 commit 875e003

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
"autoload": {
4747
"psr-4": {
4848
"nguyenanhung\\MyRequests\\": "src/"
49-
}
49+
},
50+
"files": [
51+
"helpers/helpers.php"
52+
]
5053
}
5154
}

helpers/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Request Helpers

helpers/helpers.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Project requests
4+
* Created by PhpStorm
5+
* User: 713uk13m <[email protected]>
6+
* Copyright: 713uk13m <[email protected]>
7+
* Date: 08/03/2021
8+
* Time: 23:16
9+
*/
10+
if (!function_exists('sendSimpleRequest')) {
11+
/**
12+
* Function sendSimpleRequest
13+
*
14+
* @param string $url URL Target Endpoint
15+
* @param string|array $data Array Data to Request
16+
* @param string $method GET or POST
17+
*
18+
* @return bool|string|null
19+
* @author : 713uk13m <[email protected]>
20+
* @copyright: 713uk13m <[email protected]>
21+
* @time : 08/03/2021 20:38
22+
*/
23+
function sendSimpleRequest($url = '', $data = [], $method = 'GET')
24+
{
25+
$target = (!empty($data) && (is_array($data) || is_object($data))) ? $url . '?' . http_build_query($data) : $url;
26+
$method = strtoupper($method);
27+
$curl = curl_init();
28+
curl_setopt_array($curl, array(
29+
CURLOPT_URL => $target,
30+
CURLOPT_RETURNTRANSFER => TRUE,
31+
CURLOPT_ENCODING => "",
32+
CURLOPT_MAXREDIRS => 10,
33+
CURLOPT_TIMEOUT => 30,
34+
CURLOPT_CUSTOMREQUEST => $method,
35+
CURLOPT_POSTFIELDS => "",
36+
CURLOPT_HTTPHEADER => array(),
37+
));
38+
$response = curl_exec($curl);
39+
$err = curl_error($curl);
40+
curl_close($curl);
41+
if ($err) {
42+
$message = "cURL Error #: " . $err;
43+
if (function_exists('log_message')) {
44+
log_message('error', $message);
45+
}
46+
47+
return NULL;
48+
} else {
49+
return $response;
50+
}
51+
}
52+
}

src/ProjectInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
interface ProjectInterface
2020
{
21-
const VERSION = '2.0.3';
22-
const LAST_MODIFIED = '2021-08-01';
21+
const VERSION = '2.0.4';
22+
const LAST_MODIFIED = '2021-08-03';
2323
const MIN_PHP_VERSION = '7.0';
2424
const GET = 'GET';
2525
const HEAD = 'HEAD';

0 commit comments

Comments
 (0)