Skip to content

Commit c3b2420

Browse files
committed
breaking: migrate to php 8.0+ for all codes
1 parent 8aec680 commit c3b2420

13 files changed

+115
-121
lines changed

.github/workflows/php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: true
1212
matrix:
13-
php: [7.3, 7.4, 8.0, 8.1] #
13+
php: [8.0, 8.1] #
1414
os: [ubuntu-latest, macOS-latest] # windows-latest,
1515
# include:
1616
# - os: 'ubuntu-latest'

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# FileSystem Util
22

33
[![License](https://img.shields.io/packagist/l/toolkit/fsutil.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/badge/php-%3E=7.3.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/fsutil)
4+
[![Php Version](https://img.shields.io/badge/php-%3E=8.0-brightgreen.svg?maxAge=2592000)](https://packagist.org/packages/toolkit/fsutil)
55
[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/fsutil.svg)](https://packagist.org/packages/toolkit/fsutil)
66
[![Actions Status](https://github.com/php-toolkit/fsutil/workflows/Unit-tests/badge.svg)](https://github.com/php-toolkit/fsutil/actions)
77

@@ -15,6 +15,8 @@ Some useful file system util for php
1515

1616
## Install
1717

18+
- Required PHP 8.0+
19+
1820
```bash
1921
composer require toolkit/fsutil
2022
```

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "toolkit/fsutil",
33
"type": "library",
4-
"description": "some file tool library of the php",
4+
"description": "some file system tool library of the php",
55
"keywords": [
66
"library",
77
"tool",
8+
"filesystem",
89
"php"
910
],
1011
"homepage": "https://github.com/php-toolkit/fsutil",
@@ -13,12 +14,12 @@
1314
{
1415
"name": "inhere",
1516
"email": "[email protected]",
16-
"homepage": "http://www.yzone.net/"
17+
"homepage": "https://github.com/inhere"
1718
}
1819
],
1920
"require": {
20-
"php": ">7.3.0",
21-
"toolkit/stdlib": "^1.0"
21+
"php": ">=8.0.1",
22+
"toolkit/stdlib": "^2.0"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/Directory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public static function getDirs(string $path, bool $loop = false, $parent = null,
106106
* 获得目录下的文件,可选择类型、是否遍历子文件夹
107107
*
108108
* @param string $dir string 目标目录
109-
* @param string|array $ext array('css','html','php') css|html|php
109+
* @param array|string $ext array('css','html','php') css|html|php
110110
* @param bool $recursive int|bool 是否包含子目录
111111
*
112112
* @return array
113113
* @throws FileNotFoundException
114114
*/
115-
public static function simpleInfo(string $dir, $ext = null, bool $recursive = false): array
115+
public static function simpleInfo(string $dir, array|string $ext = '', bool $recursive = false): array
116116
{
117117
$list = [];
118118
$dir = self::pathFormat($dir);
@@ -157,7 +157,7 @@ public static function simpleInfo(string $dir, $ext = null, bool $recursive = fa
157157
*/
158158
public static function getFiles(
159159
string $path,
160-
$ext = null,
160+
array|string $ext = '',
161161
bool $recursive = false,
162162
string $parent = '',
163163
array $list = []
@@ -197,7 +197,7 @@ public static function getFiles(
197197
* @throws InvalidArgumentException
198198
* @throws FileNotFoundException
199199
*/
200-
public static function getFilesInfo(string $path, $ext = null, bool $recursive = false, array &$list = []): array
200+
public static function getFilesInfo(string $path, array|string $ext = '', bool $recursive = false, array &$list = []): array
201201
{
202202
$path = self::pathFormat($path);
203203
if (!is_dir($path)) {

src/File.php

+15-20
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ public static function getContents(
209209
* save contents to file use file_put_contents()
210210
*
211211
* @param string $filename
212-
* @param string|array|resource $data string, array(仅一维数组) 或者是 stream 资源
212+
* @param string|array|resource|mixed $data string, array(仅一维数组) 或者是 stream 资源
213213
* @param int $flags
214-
* @param null $context
214+
* @param resource|null $context
215215
*
216216
* @return int
217217
* @see file_put_contents()
218218
*/
219-
public static function putContents(string $filename, $data, int $flags = 0, $context = null): int
219+
public static function putContents(string $filename, mixed $data, int $flags = 0, $context = null): int
220220
{
221221
$number = file_put_contents($filename, $data, $flags, $context);
222222
if ($number === false) {
@@ -236,7 +236,7 @@ public static function putContents(string $filename, $data, int $flags = 0, $con
236236
*
237237
* @return int
238238
*/
239-
public static function save(string $filename, $data, int $flags = 0, $context = null): int
239+
public static function save(string $filename, mixed $data, int $flags = 0, $context = null): int
240240
{
241241
return self::putContents($filename, $data, $flags, $context);
242242
}
@@ -247,11 +247,11 @@ public static function save(string $filename, $data, int $flags = 0, $context =
247247
* @param string $filename
248248
* @param string|array|resource $data
249249
* @param int $flags
250-
* @param null|mixed $context
250+
* @param null|resource $context
251251
*
252252
* @return int
253253
*/
254-
public static function mkdirSave(string $filename, $data, int $flags = 0, $context = null): int
254+
public static function mkdirSave(string $filename, mixed $data, int $flags = 0, $context = null): int
255255
{
256256
if (!is_dir($dir = dirname($filename))) {
257257
self::mkdir($dir);
@@ -474,7 +474,7 @@ public static function getContentsV2(
474474
bool $useIncludePath = false,
475475
$streamContext = null,
476476
int $curlTimeout = 5
477-
) {
477+
): bool|string {
478478
$isUrl = preg_match('/^https?:\/\//', $file);
479479
if (null === $streamContext && $isUrl) {
480480
$streamContext = @stream_context_create(['http' => ['timeout' => $curlTimeout]]);
@@ -524,16 +524,14 @@ public static function getContentsV2(
524524
}
525525

526526
/**
527-
* @param $inFile
528-
* @param $outFile
527+
* @param array|string $inFile
528+
* @param string $outFile
529529
*
530-
* @return mixed
531-
* @throws InvalidArgumentException
532-
* @throws FileNotFoundException
530+
* @return string
533531
*/
534-
public static function combine($inFile, $outFile)
532+
public static function combine(array|string $inFile, string $outFile): string
535533
{
536-
self::check($inFile);
534+
// self::check($inFile);
537535

538536
$data = '';
539537
if (is_array($inFile)) {
@@ -544,13 +542,10 @@ public static function combine($inFile, $outFile)
544542
throw new FileNotFoundException('File: ' . $value . ' not exists!');
545543
}
546544
}
547-
}
548-
549-
/*if (is_string($inFile) && is_file($value)) {
550-
$data .= trim( file_get_contents($inFile) );
551545
} else {
552-
Trigger::error('文件'.$value.'不存在!!');
553-
}*/
546+
self::check($inFile);
547+
$data = trim(file_get_contents($inFile));
548+
}
554549

555550
$preg_arr = [
556551
'/\/\*.*?\*\/\s*/is', // 去掉所有多行注释/* .... */

0 commit comments

Comments
 (0)