Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Duster glob support using Symfony finder #136

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions app/Support/DusterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Support;

use App\Project;
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder;

class DusterConfig
{
Expand Down Expand Up @@ -63,11 +66,49 @@ public static function scopeConfigPaths(array $config): array
*/
public static function expandWildcards(array $paths): array
{
return collect($paths)->flatMap(function ($path) {
return collect($paths)->flatMap(fn ($path) => static::globPath($path))->values()->toArray();
}

/**
* @return array<int, string>
*/
public static function globPath(string $path): array
{
try {
// Finder uses forward slashes even on windows
$path = Str::of($path)->replace('\\', '/')->__toString();

if (Str::of($path)->endsWith('.php')) {
$name = Str::of($path)->afterLast('/');
$path = Str::of($path)->beforeLast('/');

$files = (new Finder)
->ignoreUnreadableDirs()
->ignoreDotFiles(false)
->files()
->in($path);
} else {
$name = '.php';
$files = (new Finder)
->ignoreUnreadableDirs()
->files()
->in($path);
}

return collect($files)
->map(
fn ($file) => Str::of($file->getPathName())->endsWith($name)
// Fixes weird windows path issue with mixed slashes
? Str::of($file->getPathName())->replace('\\', '/')->__toString()
: null
)
->filter()
->all();
} catch (Exception) {
return collect(glob($path, GLOB_NOCHECK))
->filter(fn ($path) => file_exists($path))
->all();
})->toArray();
}
}

public function get(string $key, mixed $default = null): mixed
Expand Down
Binary file modified builds/duster
Binary file not shown.
10 changes: 5 additions & 5 deletions composer-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"php": "^8.1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16.0",
"laravel-zero/framework": "^10.0.0",
"laravel/pint": "^1.9",
"nunomaduro/larastan": "^2.2",
"friendsofphp/php-cs-fixer": "^3.21.1",
"laravel-zero/framework": "^10.1.1",
"laravel/pint": "^v1.11.0",
"larastan/larastan": "^2.7",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest": "^1.21.3",
"rector/rector": "^0.15.10",
"spatie/invade": "^1.1",
"spatie/laravel-ray": "^1.31",
"squizlabs/php_codesniffer": "^3.7",
"tightenco/tlint": "^8.0"
"tightenco/tlint": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading