public static function filesystem() { $filesystem = new Filesystem(); Filesystem::macro('makeWritableByAll', (new ClosureFactory())->makeWritableByAll()); Filesystem::macro('isWritableByAll', (new ClosureFactory())->isWritableByAll()); return $filesystem; }
/** * Register a custom macro. * * @param string $name * @param callable $macro * @return void * @static */ public static function macro($name, $macro) { \Illuminate\Filesystem\Filesystem::macro($name, $macro); }
<?php if (file_exists(__DIR__ . '/vendor/autoload.php')) { require __DIR__ . '/vendor/autoload.php'; } else { if (file_exists(__DIR__ . '/../vendor/autoload.php')) { require __DIR__ . '/../vendor/autoload.php'; } else { require __DIR__ . '/../../../vendor/autoload.php'; } } use Dotenv\Dotenv; use Illuminate\Filesystem\Filesystem; use Illuminate\Cache\FileStore; use Illuminate\Cache\Repository as IlluminateCache; use Work\Cache\Cache; (new Dotenv(getenv('HOME'), '.workrc'))->load(); Filesystem::macro('touch', function ($filename) { $this->append($filename, ''); }); if ((new Filesystem())->exists('.work')) { (new Dotenv(getcwd(), '.work'))->load(); } $filestore = new FileStore(new Filesystem(), getenv('CACHE')); Cache::setCacheRepository(new IlluminateCache($filestore));
<?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; }); }