Skip to content

Commit 9b6f6e8

Browse files
committed
Update CodeIgniter3 Skeleton
1 parent eee7de4 commit 9b6f6e8

File tree

4 files changed

+19
-209
lines changed

4 files changed

+19
-209
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Change Log được viết theo biểu mẫu tại đây: https://keepachangelog.com/en/1.0.0/
44

5+
## [1.0.7] - 2023/03/22
6+
7+
### Update
8+
9+
- [x] Update vendor `nguyenanhung/codeigniter-framework` latest version
10+
- [x] Update vendor `nguyenanhung/codeigniter-basic-helper` latest version
11+
512
## [1.0.6] - 2023/02/13
613

714
### Update

app/libraries/Requests.php

Lines changed: 7 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
<?php
22
defined('BASEPATH') or exit('No direct script access allowed');
33

4-
/**
5-
* Project my-portfolio
6-
* Created by PhpStorm
7-
* User: 713uk13m <dev@nguyenanhung.com>
8-
* Copyright: 713uk13m <dev@nguyenanhung.com>
9-
* Date: 09/01/2020
10-
* Time: 23:30
11-
*/
12-
13-
use Monolog\Logger;
14-
use Monolog\Handler\StreamHandler;
15-
use Monolog\Formatter\LineFormatter;
4+
use nguyenanhung\CodeIgniter\BasicHelper\SimpleRequests;
165

176
/**
187
* Class Requests
198
*
209
* @author 713uk13m <dev@nguyenanhung.com>
2110
* @copyright 713uk13m <dev@nguyenanhung.com>
2211
*/
23-
class Requests
12+
class Requests extends SimpleRequests
2413
{
2514
protected $mono;
2615
protected $DEBUG;
2716
protected $logger_path;
2817
protected $logger_file;
29-
protected $timeout = 60;
30-
protected $header = [];
18+
protected $timeout;
19+
protected $header;
3120

3221
/**
3322
* Requests constructor.
@@ -37,201 +26,10 @@ class Requests
3726
*/
3827
public function __construct()
3928
{
29+
parent::__construct();
4030
$this->DEBUG = true;
4131
$this->logger_path = __DIR__ . '/../../storage/logs/Requests/';
42-
$this->logger_file = 'Log-' . date('Y-m-d') . '.log';
43-
$this->mono = [
44-
'dateFormat' => "Y-m-d H:i:s u",
45-
'outputFormat' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
46-
'monoBubble' => true,
47-
'monoFilePermission' => 0777
48-
];
49-
}
50-
51-
/**
52-
* Function setTimeout
53-
*
54-
* @param $timeout
55-
*
56-
* @return $this
57-
* @author : 713uk13m <dev@nguyenanhung.com>
58-
* @copyright: 713uk13m <dev@nguyenanhung.com>
59-
* @time : 07/27/2021 31:11z
60-
*/
61-
public function setTimeout($timeout): Requests
62-
{
63-
$this->timeout = $timeout;
64-
65-
return $this;
66-
}
67-
68-
/**
69-
* Function setHeader
70-
*
71-
* @param array $header
72-
*
73-
* @return $this
74-
* @author : 713uk13m <dev@nguyenanhung.com>
75-
* @copyright: 713uk13m <dev@nguyenanhung.com>
76-
* @time : 07/27/2021 31:22
77-
*/
78-
public function setHeader(array $header = []): Requests
79-
{
80-
$this->header = $header;
81-
82-
return $this;
83-
}
84-
85-
/**
86-
* Function sendRequest
87-
*
88-
* @param string $url
89-
* @param array $data
90-
* @param string $method
91-
*
92-
* @return string|null
93-
* @author : 713uk13m <dev@nguyenanhung.com>
94-
* @copyright: 713uk13m <dev@nguyenanhung.com>
95-
* @time : 09/18/2021 54:32
96-
*/
97-
public function sendRequest(string $url = '', array $data = [], string $method = 'GET'): ?string
98-
{
99-
try {
100-
$getMethod = strtoupper($method);
101-
// create a log channel
102-
$formatter = new LineFormatter($this->mono['outputFormat'], $this->mono['dateFormat']);
103-
$stream = new StreamHandler($this->logger_path . 'sendRequest/' . $this->logger_file, Logger::INFO, $this->mono['monoBubble'], $this->mono['monoFilePermission']);
104-
$stream->setFormatter($formatter);
105-
$logger = new Logger('Curl');
106-
$logger->pushHandler($stream);
107-
if ($this->DEBUG === true) {
108-
$logger->info('||=========== Logger Requests ===========||');
109-
$logger->info('Method: ' . $getMethod);
110-
$logger->info('Request: ' . $url, $data);
111-
}
112-
// Curl
113-
$curl = new Curl\Curl();
114-
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
115-
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
116-
$curl->setOpt(CURLOPT_ENCODING, "utf-8");
117-
$curl->setOpt(CURLOPT_MAXREDIRS, 10);
118-
$curl->setOpt(CURLOPT_TIMEOUT, 300);
119-
// Request
120-
if ('POST' === $getMethod) {
121-
$curl->post($url, $data);
122-
} else {
123-
$curl->get($url, $data);
124-
}
125-
// Response
126-
$response = $curl->error ? "cURL Error: " . $curl->errorMessage : $curl->response;
127-
// Close Request
128-
$curl->close();
129-
// Log Response
130-
if ($this->DEBUG === true) {
131-
if (is_array($response) || is_object($response)) {
132-
$logger->info('Response: ' . json_encode($response));
133-
} else {
134-
$logger->info('Response: ' . $response);
135-
}
136-
if (isset($curl->requestHeaders)) {
137-
if (is_array($curl->requestHeaders)) {
138-
$logger->info('Request Header: ', $curl->requestHeaders);
139-
} else {
140-
$logger->info('Request Header: ' . json_encode($curl->requestHeaders));
141-
}
142-
}
143-
if (isset($curl->responseHeaders)) {
144-
if (is_array($curl->responseHeaders)) {
145-
$logger->info('Response Header: ', $curl->responseHeaders);
146-
} else {
147-
$logger->info('Response Header: ' . json_encode($curl->responseHeaders));
148-
}
149-
}
150-
}
151-
152-
// Return Response
153-
return $response;
154-
} catch (Exception $e) {
155-
log_message('error', $e->getMessage());
156-
log_message('error', $e->getTraceAsString());
157-
158-
return null;
159-
}
160-
}
161-
162-
// ========================================================================== //
163-
164-
/**
165-
* Function xmlRequest
166-
*
167-
* @param string $url
168-
* @param string $data
169-
* @param int $timeout
170-
*
171-
* @return bool|string|null
172-
* @author : 713uk13m <dev@nguyenanhung.com>
173-
* @copyright: 713uk13m <dev@nguyenanhung.com>
174-
* @time : 07/27/2021 32:35
175-
*/
176-
public function xmlRequest(string $url = '', string $data = '', int $timeout = 60)
177-
{
178-
if (empty($url) || empty($data)) {
179-
return null;
180-
}
181-
try {
182-
// create a log channel
183-
$formatter = new LineFormatter($this->mono['outputFormat'], $this->mono['dateFormat']);
184-
$stream = new StreamHandler($this->logger_path . 'xmlRequest/' . $this->logger_file, Logger::INFO, $this->mono['monoBubble'], $this->mono['monoFilePermission']);
185-
$stream->setFormatter($formatter);
186-
$logger = new Logger('request');
187-
$logger->pushHandler($stream);
188-
if ($this->DEBUG === true) {
189-
$logger->info('||=========== Logger xmlRequest ===========||');
190-
$logger->info('Request URL: ' . $url);
191-
$logger->info('Request Data: ' . $data);
192-
}
193-
$ch = curl_init();
194-
curl_setopt($ch, CURLOPT_URL, $url);
195-
$head[] = "Content-type: text/xml;charset=utf-8";
196-
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
197-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
198-
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
199-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
200-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
201-
curl_setopt($ch, CURLOPT_POST, 1);
202-
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
203-
$page = curl_exec($ch);
204-
curl_close($ch);
205-
if ($this->DEBUG === true) {
206-
$logger->info('Response from Request: ' . $page);
207-
}
208-
209-
return $page;
210-
} catch (Exception $e) {
211-
log_message('error', $e->getMessage());
212-
log_message('error', $e->getTraceAsString());
213-
214-
return null;
215-
}
216-
}
217-
218-
/**
219-
* Function xmlGetValue
220-
*
221-
* @param $xml
222-
* @param $openTag
223-
* @param $closeTag
224-
*
225-
* @return false|string
226-
* @author : 713uk13m <dev@nguyenanhung.com>
227-
* @copyright: 713uk13m <dev@nguyenanhung.com>
228-
* @time : 07/27/2021 32:32
229-
*/
230-
public function xmlGetValue($xml, $openTag, $closeTag)
231-
{
232-
$f = strpos($xml, $openTag) + strlen($openTag);
233-
$l = strpos($xml, $closeTag);
234-
235-
return ($f <= $l) ? substr($xml, $f, $l - $f) : "";
32+
$this->timeout = 60;
33+
$this->header = array();
23634
}
23735
}

app/third_party/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Support class
2+
3+
Các class trong đây được sử dụng với namespace: `nguyenanhung/Support`

deploy/.prod.config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
defined('BASEPATH') or exit('No direct script access allowed');

0 commit comments

Comments
 (0)