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

99封情书 提交于 2020-01-23 04:21:12

问题


This is concerning Laravel 5.

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

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

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.

What is the cleanest way to achieve this?


回答1:


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);
});

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



来源:https://stackoverflow.com/questions/29729863/how-to-leverage-the-glob-method-of-filesystem-class-with-storagefacade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!