public function test_glob_recursive() { $files = Filesystem::globRecursive(__DIR__ . '/TestDir/*.txt'); $this->assertEquals([__DIR__ . '/TestDir/foo.txt', __DIR__ . '/TestDir/directory/bar.txt'], $files); }
/** * Recursively find pathnames matching a pattern. * * @param string $pattern * @param int $flags * @return array */ function glob_recursive($pattern, $flags = 0) { return Filesystem::globRecursive($pattern, $flags); }
<?php namespace Propaganistas\LaravelHelperMacros\Macros; use Illuminate\Filesystem\Filesystem; if (!Filesystem::hasMacro('globRecursive')) { /** * Recursively find pathnames matching a pattern. * * @param string $pattern * @param int $flags * @return array */ Filesystem::macro('globRecursive', function ($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $files = array_merge($files, Filesystem::globRecursive($dir . '/' . basename($pattern), $flags)); } return $files; }); }