本文介绍了如何在StorageFacade中利用Filesystem类的glob方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与 Laravel 5有关.

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

I can see in Illuminate\Filesystem\Filesystem a method called glob($pattern, $flags = 0)

不幸的是,Laravel 5随附的默认FilesystemAdapter没有反映此方法.

Unfortunately, this method is not reflected in the default FilesystemAdapter shipped with Laravel 5.

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

This would be great, due to the fact that I would need to do something like Storage::disk('local')->glob([_]*[.blade.php]); (in order to get all stored blade files starting with an underscore.

最干净的方法是什么?

推荐答案

我认为您不能在此处运行glob,但是您可以获取所有文件,然后对其进行过滤,例如:

I think you cannot run glob here, but you could get all files and then filter them, for example:

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

当然,您需要根据需要决定(递归地)使用filesallFiles.如果您有成千上万个文件,这可能不是最佳解决方案,但是如果没有,那应该就足够了

Of course you need to decide to use files or allFiles (recursively) depending on your needs. Probably it's not the best solution if you have thousands of files but if you don't it should be enough

这篇关于如何在StorageFacade中利用Filesystem类的glob方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:38