mirror of
https://github.com/bitinflow/bunny-cli.git
synced 2026-03-13 21:55:54 +00:00
Improve uploads/deletions
This commit is contained in:
39
app/Bunny/Filesystem/Sort.php
Normal file
39
app/Bunny/Filesystem/Sort.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bunny\Filesystem;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Sort
|
||||
{
|
||||
|
||||
public static function unique(&$directories): array
|
||||
{
|
||||
$relevant = [];
|
||||
|
||||
// sort all requested files
|
||||
uksort($directories, function (string $a, string $b) {
|
||||
$a = count(explode('/', $a));
|
||||
$b = count(explode('/', $b));
|
||||
|
||||
if ($a == $b) {
|
||||
return 0;
|
||||
}
|
||||
return ($a < $b) ? -1 : 1;
|
||||
});
|
||||
|
||||
// filter all child files and directories
|
||||
foreach ($directories as $path => $request) {
|
||||
if (!Str::startsWith($path, array_keys($relevant))) {
|
||||
$relevant[$path] = $request;
|
||||
}
|
||||
}
|
||||
|
||||
return $relevant;
|
||||
}
|
||||
|
||||
private static function isParentDeleted(array $parents, string $file): bool
|
||||
{
|
||||
return Str::startsWith($file, $parents);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user