Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6625fc9

Browse files
committed
up: update realpath method logic, add new help method
1 parent 73b2877 commit 6625fc9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/Traits/FileOperateTrait.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use function preg_match;
2727
use function stat;
2828
use function str_contains;
29+
use function str_ends_with;
2930
use function stream_get_contents;
3031
use function stream_set_blocking;
3132
use function strrchr;
@@ -77,6 +78,20 @@ public static function getSuffix(string $filename, bool $clearPoint = false): st
7778
return $clearPoint ? trim($suffix, '.') : $suffix;
7879
}
7980

81+
/**
82+
* @param string $filePath file path
83+
* @param string $suffix suffix name, with '.'. eg: .json
84+
*
85+
* @return string
86+
*/
87+
public static function appendSuffix(string $filePath, string $suffix): string
88+
{
89+
if (!str_ends_with($filePath, $suffix)) {
90+
$filePath .= $suffix;
91+
}
92+
return $filePath;
93+
}
94+
8095
/**
8196
* 获得文件扩展名、后缀名
8297
*

‎src/Traits/FileSystemFuncTrait.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function explode;
2525
use function function_exists;
2626
use function get_resource_type;
27+
use function getcwd;
2728
use function implode;
2829
use function is_dir;
2930
use function is_resource;
@@ -236,7 +237,7 @@ public static function chown(Traversable|array|string $files, string $user, bool
236237
*/
237238
public static function expandPath(string $path): string
238239
{
239-
$path = realpath($path);
240+
return realpath($path);
240241
}
241242

242243
/**
@@ -261,6 +262,11 @@ public static function realpath(string $path): string
261262
$parts[0] = OS::getUserHomeDir();
262263
}
263264

265+
// `.` is relative path
266+
if ($parts[0] === '.') {
267+
$parts[0] = (string)getcwd();
268+
}
269+
264270
$absolutes = [];
265271
foreach ($parts as $part) {
266272
if ('.' === $part) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /