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 910b3f8

Browse files
committed
👔 up: update some helper methods and add more useful method for FTB
1 parent 8c058c1 commit 910b3f8

File tree

8 files changed

+369
-146
lines changed

8 files changed

+369
-146
lines changed

‎README.md‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ Some useful file system util for php
2222
composer require toolkit/fsutil
2323
```
2424

25-
## Usage
26-
27-
### File Finder
25+
## File Finder
2826

2927
```php
3028
use Toolkit\FsUtil\Extra\FileFinder;
@@ -44,10 +42,14 @@ foreach ($finder as $file) {
4442
}
4543
```
4644

47-
### File Tree Builder
45+
## File Tree Builder
4846

4947
`FileTreeBuilder` - can be quickly create dirs and files, copy dir and files.
5048

49+
- can use path var in `dir()`, `copy()` ... methods. eg: `copy('{baseDir}/to/file', '{workdir}/dst/file')`
50+
51+
Quick start:
52+
5153
```php
5254
use Toolkit\FsUtil\Extra\FileTreeBuilder;
5355

@@ -78,7 +80,16 @@ Will create file tree like:
7880
|-- new-file1.md
7981
```
8082

81-
### Modify Watcher
83+
### path vars
84+
85+
- `tplDir` The template dir path
86+
- `baseDir` base workdir path, only init on first set workdir.
87+
- `current,workdir` current workdir path.
88+
- And all simple type var in `tplVars`.
89+
90+
Usage in path string: `{baseDir}/file`
91+
92+
## Modify Watcher
8293

8394
```php
8495
use Toolkit\FsUtil\Extra\ModifyWatcher;

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=8.0.1",
21+
"php": ">=8.1.1",
2222
"toolkit/stdlib": "^2.0"
2323
},
2424
"autoload": {

‎src/Directory.php‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ public static function mkSubDirs(string $parentDir, array $subDirs, int $mode =
286286
public static function copy(string $oldDir, string $newDir, array $options = []): bool
287287
{
288288
if (!is_dir($oldDir)) {
289-
throw new FileNotFoundException("copy error:source dir does not exist!path: $oldDir");
289+
throw new FileNotFoundException("Copy error: source dir does not exist!path: $oldDir");
290290
}
291291

292292
self::doCopy($oldDir, $newDir, array_merge([
293-
'skipExist' => true,
293+
'skipExist' => true,// skip exist file
294294
'filterFn' => null,
295295
'beforeFn' => null,
296296
'afterFn' => null,
@@ -310,7 +310,7 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
310310
{
311311
self::create($newDir);
312312
$beforeFn = $options['beforeFn'];
313-
$filterFn = $options['filterFn'];
313+
$filterFn = $options['filterFn'];// filter file or dir.
314314

315315
// use '{,.}*' match hidden files
316316
foreach (glob($oldDir . '/{,.}*', GLOB_BRACE) as $old) {
@@ -319,15 +319,14 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
319319
continue;
320320
}
321321

322-
$new = self::joinPath($newDir, $name);
323-
324-
if (is_dir($old)) {
325-
self::doCopy($old, $new, $options);
322+
// return false to skip copy
323+
if ($filterFn && !$filterFn($old)) {
326324
continue;
327325
}
328326

329-
// return false to skip copy
330-
if ($filterFn && !$filterFn($old)) {
327+
$new = self::joinPath($newDir, $name);
328+
if (is_dir($old)) {
329+
self::doCopy($old, $new, $options);
331330
continue;
332331
}
333332

@@ -361,7 +360,6 @@ private static function doCopy(string $oldDir, string $newDir, array $options):
361360
public static function delete(string $path, bool $delSelf = true): bool
362361
{
363362
$dirPath = self::pathFormat($path);
364-
365363
if (is_file($dirPath)) {
366364
return unlink($dirPath);
367365
}

0 commit comments

Comments
(0)

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