Skip to content

Commit 6e7df9c

Browse files
committed
fix compatibility with php 5.3
1 parent fe5f6e5 commit 6e7df9c

File tree

8 files changed

+91
-25
lines changed

8 files changed

+91
-25
lines changed

.github/workflows/test-ci.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ jobs:
1010
fail-fast: false
1111
max-parallel: 1
1212
matrix:
13-
php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
13+
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v2
1818

19+
- name: Setup php for mock server
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.2'
23+
24+
- name: Setup build-in server
25+
run: |
26+
nohup php -S localhost:9000 -t ./tests/mock-server/ > phpd.log 2>&1 &
27+
echo $! > mock-server.pid
28+
1929
- name: Setup php
2030
uses: shivammathur/setup-php@v2
2131
with:
@@ -28,19 +38,22 @@ jobs:
2838
2939
- name: Run cases
3040
run: |
31-
nohup php -S localhost:9000 -t ./tests/mock-server/ > phpd.log 2>&1 &
32-
export PHP_SERVER_PID=$!
3341
./vendor/bin/phpcs --standard=PSR2 src
3442
./vendor/bin/phpcs --standard=PSR2 examples
3543
./vendor/bin/phpcs --standard=PSR2 tests
3644
./vendor/bin/phpunit --coverage-clover=coverage.xml
37-
kill $PHP_SERVER_PID
45+
cat mock-server.pid | xargs kill
3846
3947
env:
4048
QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }}
4149
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
4250
QINIU_TEST_BUCKET: ${{ secrets.QINIU_TEST_BUCKET }}
4351
QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }}
4452

53+
- name: Print mock servion log
54+
if: ${{ failure() }}
55+
run: |
56+
cat phpd.log
57+
4558
- name: After_success
4659
run: bash <(curl -s https://codecov.io/bash)

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
],
2020
"require": {
2121
"php": ">=5.3.3",
22-
"myclabs/php-enum": "~1.6.6 || ~1.7.7 || ~1.8.4"
22+
"myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4"
2323
},
2424
"require-dev": {
2525
"paragonie/random_compat": ">=2",
2626
"phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4",
27-
"squizlabs/php_codesniffer": "~3.6"
27+
"squizlabs/php_codesniffer": "^2.3 || ~3.6"
2828
},
2929
"autoload": {
3030
"psr-4": {

src/Qiniu/Enum/QiniuEnum.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
// phpcs:disable
3-
// PSR1.Classes.ClassDeclaration.MultipleClasses
2+
// @codingStandardsIgnoreStart
3+
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
44

55
namespace Qiniu\Enum;
66

@@ -9,6 +9,8 @@
99
if (method_exists("MyCLabs\\Enum\\Enum", "from")) {
1010
abstract class QiniuEnum extends Enum
1111
{
12+
// @codingStandardsIgnoreEnd
13+
// @codingStandardsIgnoreStart
1214
}
1315
} else {
1416
/**
@@ -18,6 +20,7 @@ abstract class QiniuEnum extends Enum
1820
*/
1921
abstract class QiniuEnum extends Enum
2022
{
23+
// @codingStandardsIgnoreEnd
2124
/**
2225
* @param mixed $value
2326
* @return static
@@ -45,5 +48,6 @@ private static function assertValidValueReturningKey($value)
4548

4649
return $key;
4750
}
51+
// @codingStandardsIgnoreStart
4852
}
4953
}

src/Qiniu/Http/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function normalizeKey($key)
8383
return $key;
8484
}
8585

86-
return ucwords(strtolower($key), '-');
86+
return \Qiniu\ucwords(strtolower($key), '-');
8787
}
8888

8989
/**

src/Qiniu/Storage/BucketManager.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,11 @@ public function changeMime($bucket, $key, $mime)
705705
*
706706
* @param string $bucket 待操作资源所在空间
707707
* @param string $key 待操作资源文件名
708-
* @param int $fileType 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储
708+
* @param int $fileType 对象存储类型
709+
* 0 表示标准存储;
710+
* 1 表示低频存储;
711+
* 2 表示归档存储;
712+
* 3 表示深度归档存储;
709713
*
710714
* @return array
711715
* @link https://developer.qiniu.com/kodo/api/3710/chtype
@@ -931,10 +935,18 @@ public function deleteAfterDays($bucket, $key, $days)
931935
*
932936
* @param string $bucket 空间名
933937
* @param string $key 目标资源
934-
* @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
935-
* @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
936-
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
937-
* @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
938+
* @param int $to_line_after_days 多少天后将文件转为低频存储。
939+
* -1 表示取消已设置的转低频存储的生命周期规则;
940+
* 0 表示不修改转低频生命周期规则。
941+
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
942+
* -1 表示取消已设置的转归档存储的生命周期规则;
943+
* 0 表示不修改转归档生命周期规则。
944+
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储。
945+
* -1 表示取消已设置的转深度归档存储的生命周期规则;
946+
* 0 表示不修改转深度归档生命周期规则。
947+
* @param int $delete_after_days 多少天后将文件删除。
948+
* -1 表示取消已设置的删除存储的生命周期规则;
949+
* 0 表示不修改删除存储的生命周期规则。
938950
* @return array
939951
*/
940952
public function setObjectLifecycle(
@@ -961,11 +973,20 @@ public function setObjectLifecycle(
961973
*
962974
* @param string $bucket 空间名
963975
* @param string $key 目标资源
964-
* @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
965-
* @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
966-
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
967-
* @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
968-
* @param array<string, mixed> $cond 匹配条件,只有条件匹配才会设置成功,目前支持:hash、mime、fsize、putTime
976+
* @param int $to_line_after_days 多少天后将文件转为低频存储。
977+
* 设置为 -1 表示取消已设置的转低频存储的生命周期规则;
978+
* 0 表示不修改转低频生命周期规则。
979+
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
980+
* -1 表示取消已设置的转归档存储的生命周期规则;
981+
* 0 表示不修改转归档生命周期规则。
982+
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储。
983+
* -1 表示取消已设置的转深度归档存储的生命周期规则;
984+
* 0 表示不修改转深度归档生命周期规则。
985+
* @param int $delete_after_days 多少天后将文件删除。
986+
* -1 表示取消已设置的删除存储的生命周期规则;
987+
* 0 表示不修改删除存储的生命周期规则。
988+
* @param array<string, mixed> $cond 匹配条件,只有条件匹配才会设置成功。
989+
* 目前支持:hash、mime、fsize、putTime
969990
* @return array
970991
*/
971992
public function setObjectLifecycleWithCond(
@@ -1124,10 +1145,18 @@ public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs)
11241145
/**
11251146
* @param string $bucket 空间名
11261147
* @param array<string> $keys 目标资源
1127-
* @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。
1128-
* @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。
1129-
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。
1130-
* @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。
1148+
* @param int $to_line_after_days 多少天后将文件转为低频存储。
1149+
* -1 表示取消已设置的转低频存储的生命周期规则;
1150+
* 0 表示不修改转低频生命周期规则。
1151+
* @param int $to_archive_after_days 多少天后将文件转为归档存储。
1152+
* -1 表示取消已设置的转归档存储的生命周期规则;
1153+
* 0 表示不修改转归档生命周期规则。
1154+
* @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储。
1155+
* -1 表示取消已设置的转深度归档存储的生命周期规则;
1156+
* 0 表示不修改转深度归档生命周期规则。
1157+
* @param int $delete_after_days 多少天后将文件删除。
1158+
* -1 表示取消已设置的删除存储的生命周期规则;
1159+
* 0 表示不修改删除存储的生命周期规则。
11311160
*
11321161
* @retrun array<string>
11331162
*/

src/Qiniu/functions.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,23 @@ function explodeUpToken($upToken)
278278
$bucket = $scopeItems[0];
279279
return array($accessKey, $bucket, null);
280280
}
281+
282+
// polyfill ucwords for php version < 5.4.32
283+
if (phpversion() < "5.4.32") {
284+
function ucwords($str, $delimiters = " \t\r\n\f\v")
285+
{
286+
$delims = preg_split('//u', $delimiters, -1, PREG_SPLIT_NO_EMPTY);
287+
288+
foreach ($delims as $delim) {
289+
$str = implode($delim, array_map('ucfirst', explode($delim, $str)));
290+
}
291+
292+
return $str;
293+
}
294+
} else {
295+
function ucwords($str, $delimiters)
296+
{
297+
return \ucwords($str, $delimiters);
298+
}
299+
}
281300
}

tests/Qiniu/Tests/ConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace Qiniu\Tests {
4+
45
use PHPUnit\Framework\TestCase;
56

67
use Qiniu\Config;

tests/Qiniu/Tests/ResumeUpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testResumeUploadWithParams()
162162
$token,
163163
$key,
164164
$tempFile,
165-
["x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"],
165+
array("x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"),
166166
'application/octet-stream',
167167
false,
168168
$resumeFile
@@ -236,7 +236,7 @@ public function testResumeUploadV2WithParams()
236236
$token,
237237
$key,
238238
$tempFile,
239-
["x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"],
239+
array("x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"),
240240
'application/octet-stream',
241241
false,
242242
$resumeFile,

0 commit comments

Comments
 (0)