如何利用 StorageFacade 的 Filesystem class 的 glob 方法?

How to leverage the glob method of Filesystem class with StorageFacade?

这与Laravel 5有关。

我可以在 Illuminate\Filesystem\Filesystem 中看到一个名为 glob($pattern, $flags = 0)

的方法

遗憾的是,此方法未反映在 Laravel 5 随附的默认 FilesystemAdapter 中。

这太棒了,因为我需要做类似 Storage::disk('local')->glob([_]*[.blade.php]); 的事情(为了让所有存储的 blade 文件都以下划线开头。

实现此目的最干净的方法是什么?

我认为你不能在这里运行 glob,但你可以获取所有文件然后过滤它们,例如:

$files = array_filter(Storage::disk('local')->files(), function ($file)
{
    return preg_match('/_(.*)\.blade\.php$/U', $file);
});

当然你需要根据你的需要决定使用files还是allFiles(递归)。如果你有数千个文件,这可能不是最好的解决方案,但如果你没有,它应该足够了