Skip to content

Commit 0e700df

Browse files
author
dogstar
committed
2.23.0版本 手动更新compoer
1 parent dbc437a commit 0e700df

9 files changed

Lines changed: 170 additions & 32 deletions

File tree

src/app/Api/Examples/Log.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ public function run() {
3838
// 开发调试类日志:更灵活的日志分类
3939
\PhalApi\DI()->logger->log('demo', 'add user exp', array('name' => 'dogstar', 'after' => 12));
4040
\PhalApi\DI()->logger->log('test', 'add user exp', array('name' => 'dogstar', 'after' => 12));
41+
42+
// 打印获取到的最后一条SQL语句
43+
\PhalApi\DI()->logger->debug('最后一条SQL语句', \PhalApi\DI()->tracer->getLastSql());
4144
}
4245
}

src/app/Api/Examples/Response.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ public function topResult() {
1919

2020
return array('status' => 'data结构内的status 状态码');
2121
}
22+
23+
/**
24+
* 展示调试相关能力
25+
* @desc 使用前请开启调试模式,效果更佳
26+
*/
27+
public function debug() {
28+
$di = \PhalApi\DI();
29+
30+
$di->tracer->mark('打点查看内存使用情况');
31+
32+
return [];
33+
}
2234
}

vendor/composer/installed.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@
6060
},
6161
{
6262
"name": "phalapi/kernal",
63-
"version": "2.21.6",
64-
"version_normalized": "2.21.6.0",
63+
"version": "2.22.0",
64+
"version_normalized": "2.22.0.0",
6565
"source": {
6666
"type": "git",
6767
"url": "https://github.com/phalapi/kernal.git",
68-
"reference": "69aa51d85d6c6be005c030e1dddc7f9436d83736"
68+
"reference": "eb07226d8b179228786476b655428e51faef7aec"
6969
},
7070
"dist": {
7171
"type": "zip",
72-
"url": "https://api.github.com/repos/phalapi/kernal/zipball/69aa51d85d6c6be005c030e1dddc7f9436d83736",
73-
"reference": "69aa51d85d6c6be005c030e1dddc7f9436d83736",
72+
"url": "https://api.github.com/repos/phalapi/kernal/zipball/eb07226d8b179228786476b655428e51faef7aec",
73+
"reference": "eb07226d8b179228786476b655428e51faef7aec",
7474
"shasum": "",
7575
"mirrors": [
7676
{
@@ -83,7 +83,7 @@
8383
"phalapi/notorm": "2.*.*",
8484
"php": ">=5.3.3"
8585
},
86-
"time": "2023-04-17T15:20:12+00:00",
86+
"time": "2023-07-26T08:10:17+00:00",
8787
"type": "library",
8888
"installation-source": "source",
8989
"autoload": {
@@ -121,7 +121,7 @@
121121
],
122122
"support": {
123123
"issues": "https://github.com/phalapi/kernal/issues",
124-
"source": "https://github.com/phalapi/kernal/tree/2.21.6"
124+
"source": "https://github.com/phalapi/kernal/tree/2.22.0"
125125
},
126126
"install-path": "../phalapi/kernal"
127127
},

vendor/composer/installed.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'type' => 'project',
66
'install_path' => __DIR__ . '/../../',
77
'aliases' => array(),
8-
'reference' => '2f5644e615a3a5314f2294edfddffbe4513b5d85',
8+
'reference' => '30f0f7bfce2d7cf2ad033eda17541056ce69b092',
99
'name' => 'phalapi/phalapi',
1010
'dev' => true,
1111
),
@@ -20,12 +20,12 @@
2020
'dev_requirement' => false,
2121
),
2222
'phalapi/kernal' => array(
23-
'pretty_version' => '2.21.6',
24-
'version' => '2.21.6.0',
23+
'pretty_version' => '2.22.0',
24+
'version' => '2.22.0.0',
2525
'type' => 'library',
2626
'install_path' => __DIR__ . '/../phalapi/kernal',
2727
'aliases' => array(),
28-
'reference' => '69aa51d85d6c6be005c030e1dddc7f9436d83736',
28+
'reference' => 'eb07226d8b179228786476b655428e51faef7aec',
2929
'dev_requirement' => false,
3030
),
3131
'phalapi/notorm' => array(
@@ -43,7 +43,7 @@
4343
'type' => 'project',
4444
'install_path' => __DIR__ . '/../../',
4545
'aliases' => array(),
46-
'reference' => '2f5644e615a3a5314f2294edfddffbe4513b5d85',
46+
'reference' => '30f0f7bfce2d7cf2ad033eda17541056ce69b092',
4747
'dev_requirement' => false,
4848
),
4949
'phalapi/qrcode' => array(

vendor/phalapi/kernal/src/CUrl.php

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,54 @@ public function __construct($retryTimes = 1) {
6464
* GET方式的请求
6565
* @param string $url 请求的链接
6666
* @param int $timeoutMs 超时设置,单位:毫秒
67-
* @return string 接口返回的内容,超时返回false
67+
* @return string|boolean 接口返回的内容,超时返回false
6868
*/
6969
public function get($url, $timeoutMs = 3000) {
70-
return $this->request($url, array(), $timeoutMs);
70+
return $this->request($url, array(), $timeoutMs, 'GET');
7171
}
7272

7373
/**
7474
* POST方式的请求
7575
* @param string $url 请求的链接
7676
* @param array $data POST的数据
7777
* @param int $timeoutMs 超时设置,单位:毫秒
78-
* @return string 接口返回的内容,超时返回false
78+
* @return string|boolean 接口返回的内容,超时返回false
7979
*/
8080
public function post($url, $data, $timeoutMs = 3000) {
81-
return $this->request($url, $data, $timeoutMs);
81+
return $this->request($url, $data, $timeoutMs, 'POST');
82+
}
83+
84+
/**
85+
* PUT方式的请求
86+
* @param string $url 请求的链接
87+
* @param array $data PUT的数据
88+
* @param int $timeoutMs 超时设置,单位:毫秒
89+
* @return string|boolean 接口返回的内容,超时返回false
90+
*/
91+
public function put($url, $data, $timeoutMs = 3000) {
92+
return $this->request($url, $data, $timeoutMs, 'PUT');
93+
}
94+
95+
/**
96+
* DELETE方式的请求
97+
* @param string $url 请求的链接
98+
* @param array $data DELETE的数据
99+
* @param int $timeoutMs 超时设置,单位:毫秒
100+
* @return string|boolean 接口返回的内容,超时返回false
101+
*/
102+
public function delete($url, $data, $timeoutMs = 3000) {
103+
return $this->request($url, $data, $timeoutMs, 'DELETE');
104+
}
105+
106+
/**
107+
* PATCH方式的请求
108+
* @param string $url 请求的链接
109+
* @param array $data PATCH的数据
110+
* @param int $timeoutMs 超时设置,单位:毫秒
111+
* @return string|boolean 接口返回的内容,超时返回false
112+
*/
113+
public function patch($url, $data, $timeoutMs = 3000) {
114+
return $this->request($url, $data, $timeoutMs, 'PATCH');
82115
}
83116

84117
/** ------------------ 前置方法 ------------------ **/
@@ -159,26 +192,36 @@ public function withCookies() {
159192
* @param string $url 请求的链接
160193
* @param array $data POST的数据
161194
* @param int $timeoutMs 超时设置,单位:毫秒
162-
* @return string 接口返回的内容,超时返回false,异常取消抛出时返回NULL
195+
* @param string $requestMethod 请求方式,例如:GET/POST/PUT/DELETE,不确定服务器支持这个自定义方法则不要使用它。
196+
* @return string 接口返回的内容,超时返回false,异常取消抛出时返回NULL
163197
* @throws Exception
164198
*/
165-
protected function request($url, $data, $timeoutMs = 3000) {
199+
public function request($url, $data, $timeoutMs = 3000, $requestMethod = NULL) {
166200
$rs = NULL;
167201

168202
$options = array(
169203
CURLOPT_URL => $url,
170204
CURLOPT_RETURNTRANSFER => TRUE,
171205
CURLOPT_HEADER => 0,
206+
CURLOPT_TIMEOUT_MS => $timeoutMs,
172207
CURLOPT_CONNECTTIMEOUT_MS => $timeoutMs,
173208
CURLOPT_HTTPHEADER => $this->getHeaders(),
174209
);
175210

211+
// 请求方式
212+
$requestMethod = strtoupper($requestMethod);
213+
if ($requestMethod) {
214+
$options[CURLOPT_CUSTOMREQUEST] = $requestMethod;
215+
}
216+
if ($requestMethod == 'POST') {
217+
$options[CURLOPT_POST] = TRUE;
218+
}
219+
176220
if (!empty($data)) {
177-
$options[CURLOPT_POST] = 1;
178-
$options[CURLOPT_POSTFIELDS] = $data;
221+
$options[CURLOPT_POSTFIELDS] = $data;
179222
}
180223

181-
$options = $this->option + $options; //$this->>option优先
224+
$options = $this->option + $options; // $this->>option优先
182225

183226
$ch = curl_init();
184227
curl_setopt_array($ch, $options);
@@ -189,17 +232,18 @@ protected function request($url, $data, $timeoutMs = 3000) {
189232
} while ($rs === FALSE && $curRetryTimes >= 0);
190233
$errno = curl_errno($ch);
191234
if ($errno && $this->isThrowExcption) {
192-
throw new InternalServerErrorException(sprintf("%s::%s(%d)\n", $url, curl_error($ch), $errno));
235+
throw new InternalServerErrorException(sprintf("%s %s (Curl error: %d)\n", $url, curl_error($ch), $errno));
193236
}
194237

195-
//update cookie
238+
// update cookie
196239
if ($this->hascookie) {
197240
$cookie = $this->getRetCookie(curl_getinfo($ch, CURLINFO_COOKIELIST));
198241
!empty($cookie) && $this->cookie = $cookie + $this->cookie;
199242
$this->hascookie = FALSE;
200243
unset($this->header['Cookie']);
201244
unset($this->option[CURLOPT_COOKIEFILE]);
202245
}
246+
203247
curl_close($ch);
204248

205249
return $rs;

vendor/phalapi/kernal/src/Helper/Tracer.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Tracer {
2525
*/
2626
protected $sqls = array();
2727

28+
/**
29+
* 日志服务
30+
*/
31+
protected $logger;
32+
33+
public function __construct($logger = NULL) {
34+
$this->logger = $logger ? $logger : \PhalApi\DI()->logger;
35+
}
36+
2837
/**
2938
* 打点,纪录当前时间点
3039
* @param string $tag 当前纪录点的名称,方便最后查看路径节点
@@ -46,6 +55,7 @@ public function mark($tag = NULL) {
4655
'time' => $this->getCurMicroTime(),
4756
'file' => isset($backTrace[0]['file']) ? $backTrace[0]['file'] : '',
4857
'line' => isset($backTrace[0]['line']) ? $backTrace[0]['line'] : 0,
58+
'memory' => $this->getMemoryUsage(),
4959
);
5060
}
5161

@@ -64,9 +74,10 @@ public function getStack() {
6474
$internalTime = $item['time'] - $preMicroTime;
6575
$internalTime = round($internalTime/10, 1);
6676

67-
$stack[] = sprintf('[#%d - %sms%s]%s(%d)',
77+
$stack[] = sprintf('[#%d - %sms - %s%s]%s(%d)',
6878
$index + 1,
6979
$internalTime,
80+
$item['memory'],
7081
$item['tag'] !== NULL ? ' - ' . $item['tag'] : '',
7182
$item['file'],
7283
$item['line']
@@ -84,6 +95,19 @@ protected function getCurMicroTime() {
8495
return round(microtime(true) * 10000);
8596
}
8697

98+
/**
99+
* 获取内存使用
100+
* @param boolean $realUsage 为true时表示获取系统分配总的内存尺寸(不管是否使用);为false时获取实际使用的内存量
101+
* @return string 格式化的内存大小,保留一位小数点,如:120.5MB
102+
*/
103+
protected function getMemoryUsage($realUsage = false) {
104+
$size = memory_get_usage($realUsage);
105+
$unit = array('B','KB','MB','GB','TB','PB');
106+
$i = floor(log($size, 1024));
107+
$str = round($size/pow(1024, $i), 1) . $unit[$i];
108+
return $str;
109+
}
110+
87111
/**
88112
* 纪录SQL语句
89113
* @param string $string SQL语句
@@ -100,7 +124,7 @@ public function sql($statement) {
100124

101125
// 保存到日志
102126
if ($di->config->get('sys.enable_sql_log')) {
103-
$di->logger->log('SQL', $statement, array('request' => $request));
127+
$this->logger->log('SQL', $statement, array('request' => $request));
104128
}
105129
}
106130

@@ -111,4 +135,12 @@ public function sql($statement) {
111135
public function getSqls() {
112136
return $this->sqls;
113137
}
138+
139+
/**
140+
* 返回最后一条SQL语句
141+
* @return string|false 没有任何SQL语句时返回false
142+
*/
143+
public function getLastSql() {
144+
return end($this->sqls);
145+
}
114146
}

vendor/phalapi/kernal/src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* PhalApi框架 Kernal内核 版本号
99
*/
10-
defined('PHALAPI_VERSION') || define('PHALAPI_VERSION', '2.21.6');
10+
defined('PHALAPI_VERSION') || define('PHALAPI_VERSION', '2.22.0');
1111

1212
/**
1313
* 考虑再三,出于人性化关怀,提供要些快速的函数和方法

vendor/phalapi/kernal/tests/src/CUrl_Test.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class PhpUnderControl_PhalApiCUrl_Test extends \PHPUnit_Framework_TestCase
1616
{
1717
public $curl;
1818

19+
public $apiHost = 'http://demo.phalapi.net';
20+
1921
protected function setUp()
2022
{
2123
parent::setUp();
@@ -33,8 +35,8 @@ protected function tearDown()
3335
*/
3436
public function testGet()
3537
{
36-
$url = 'http://demo.phalapi.net/?s=App.Hello.World';
37-
$timeoutMs = 3000;
38+
$url = $this->apiHost . '/?s=App.Hello.World';
39+
$timeoutMs = 30000;
3840

3941
$rs = $this->curl->get($url, $timeoutMs);
4042
//var_dump($rs);
@@ -48,16 +50,52 @@ public function testGet()
4850
*/
4951
public function testPost()
5052
{
51-
$url = 'http://demo.phalapi.net/';
53+
$url = $this->apiHost . '/';
5254
$data = array('username' => 'phalapi');
53-
$timeoutMs = 3000;
55+
$timeoutMs = 30000;
5456

5557
$rs = $this->curl->post($url, $data, $timeoutMs);
5658

5759
$this->assertTrue(is_string($rs));
5860

5961
}
6062

63+
public function testPut()
64+
{
65+
$url = $this->apiHost . '/';
66+
$data = array('username' => 'phalapi');
67+
$timeoutMs = 30000;
68+
69+
$rs = $this->curl->put($url, $data, $timeoutMs);
70+
71+
$this->assertTrue(is_string($rs));
72+
73+
}
74+
75+
public function testDelete()
76+
{
77+
$url = $this->apiHost . '/';
78+
$data = array('username' => 'phalapi');
79+
$timeoutMs = 30000;
80+
81+
$rs = $this->curl->delete($url, $data, $timeoutMs);
82+
83+
$this->assertTrue(is_string($rs));
84+
85+
}
86+
87+
public function testPatch()
88+
{
89+
$url = $this->apiHost . '/';
90+
$data = array('username' => 'phalapi');
91+
$timeoutMs = 30000;
92+
93+
$rs = $this->curl->patch($url, $data, $timeoutMs);
94+
95+
$this->assertTrue(is_string($rs));
96+
97+
}
98+
6199
public function testSet()
62100
{
63101
$this->curl->setHeader(array('Content-Type' => 'text'));
@@ -71,7 +109,7 @@ public function testCookie()
71109

72110
$this->curl->withCookies();
73111

74-
$rs = $this->curl->get('http://demo.phalapi.net/', 3000);
112+
$rs = $this->curl->get('http://demo.phalapi.net/', 30000);
75113
}
76114

77115
public function testGetRetCookie()

0 commit comments

Comments
 (0)