Skip to content

Commit 52c755a

Browse files
committed
适配 thinkphp8.0
1 parent 54cb3cd commit 52c755a

16 files changed

+49
-33
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
php: [ 7.2, 7.3, 7.4, 8.0, 8.1, 8.2 ]
17+
php: [ 8.0, 8.1, 8.2 ]
1818
steps:
1919
- uses: actions/checkout@v3
2020
- name: Setup PHP

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ Route::group(function() {
8181
'key' => '__CONTROLLER__/__ACTION__/__IP__',
8282
]);
8383
```
84+
## 版本与 TP 适配关系
85+
```
86+
2.0.x -> thinkphp 8.0
87+
1.x.x -> thinkphp 6.0/6.1
88+
0.5.x -> thinkphp 5.1
89+
```
8490

8591
## 更新日志
86-
版本 1.3.x 的配置形式完全兼容版本 1.2.x 内容,可以无缝升级,
92+
版本 2.0.x 的可从 1.x 无缝升级;
93+
94+
版本 1.3.x 的配置形式完全兼容版本 1.2.x 内容,可以无缝升级;
95+
96+
版本 1.2.x 的配置形式完全兼容版本 1.1.x 内容,可以无缝升级;
8797

88-
版本 1.2.x 的配置形式完全兼容版本 1.1.x 内容,可以无缝升级。
98+
### 2.0.x 更新
99+
- 适配 thinkphp 8.0;
100+
- 所有 `php` 文件都采用 `declare(strict_types=1);` 强类型约束;
89101

90102
### 1.3.x 更新
91103
- 可通过配置 `visit_fail_response` 自定义限流响应;

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "topthink/think-throttle",
33
"description": "throttle middleware for thinkphp6",
44
"require": {
5-
"php": ">=7.2.0",
6-
"topthink/framework": "^6.0.0"
5+
"php": ">=8.0.0",
6+
"topthink/framework": "^8.0"
77
},
88
"license": "Apache-2.0",
99
"authors": [
@@ -31,8 +31,8 @@
3131
},
3232
"minimum-stability": "dev",
3333
"require-dev": {
34-
"phpunit/phpunit": "^8.5",
34+
"phpunit/phpunit": "^9.5",
3535
"guzzlehttp/guzzle": "^7.7",
36-
"topthink/think": "^6.0.0"
36+
"topthink/think": "^8.0.0"
3737
}
3838
}

src/Throttle.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
2-
3-
declare (strict_types = 1);
2+
declare(strict_types=1);
43

54
namespace think\middleware;
65

src/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* - LeakyBucket : 漏桶限流算法
2525
*/
2626
'driver_name' => CounterFixed::class,
27-
// 响应体中设置速率限制的头部信息,含义见:https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
27+
// 响应体中设置速率限制的头部信息
2828
'visit_enable_show_rate_limit' => true,
2929
// 访问受限时返回的响应
3030
'visit_fail_response' => function (Throttle $throttle, Request $request, int $wait_seconds) {

src/throttle/CounterFixed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace think\middleware\throttle;
55

src/throttle/CounterSlider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace think\middleware\throttle;
55

src/throttle/LeakyBucket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace think\middleware\throttle;
55

src/throttle/ThrottleAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace think\middleware\throttle;
55

src/throttle/TokenBucket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace think\middleware\throttle;
55

tests/BaseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace tests;
34

45
use PHPUnit\Framework\TestCase;

tests/CustomCacheTest.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* 自定义 cache 类
45
*/
@@ -10,37 +11,38 @@
1011
class CustomCache implements CacheInterface {
1112
protected $data = [];
1213

13-
public function get($key, $default = null)
14+
public function get(string $key, mixed $default = null): mixed
1415
{
1516
return isset($this->data[$key]) ? $this->data[$key] : $default;
1617
}
1718

18-
public function set($key, $value, $ttl = null)
19+
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool
1920
{
2021
$this->data[$key] = $value;
22+
return true;
2123
}
2224

23-
public function delete($key) {}
24-
public function clear() {}
25-
public function getMultiple($keys, $default = null) {}
26-
public function setMultiple($values, $ttl = null) {}
27-
public function deleteMultiple($keys) {}
28-
public function has($key) {}
25+
public function delete(string $key): bool { return true; }
26+
public function clear(): bool { return true; }
27+
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
28+
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
29+
public function deleteMultiple(iterable $keys): bool { return true; }
30+
public function has(string $key): bool { return true; }
2931
}
3032

3133
class DummyCache implements CacheInterface {
32-
public function get($key, $default = null)
34+
public function get($key, $default = null): mixed
3335
{
3436
return $default;
3537
}
3638

37-
public function set($key, $value, $ttl = null) {}
38-
public function delete($key) {}
39-
public function clear() {}
40-
public function getMultiple($keys, $default = null) {}
41-
public function setMultiple($values, $ttl = null) {}
42-
public function deleteMultiple($keys) {}
43-
public function has($key) {}
39+
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { return true; }
40+
public function delete(string $key): bool { return true; }
41+
public function clear(): bool { return true; }
42+
public function getMultiple(iterable $keys, mixed $default = null): iterable { return [];}
43+
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; }
44+
public function deleteMultiple(iterable $keys): bool { return true; }
45+
public function has(string $key): bool { return true; }
4446
}
4547

4648

tests/GCApp.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* 默认的 \think\App 的实例初始化后会在一些地方创建对它的引用,
45
* 多数是在静态变量里,这就导致它不能被自动垃圾回收。

tests/ResidentMemoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace tests;
55

tests/ThrottleDefaultConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
declare(strict_types=1);
33

44
namespace tests;
55

tests/VisitRateTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* 访问频率的单元测试
45
*/

0 commit comments

Comments
 (0)