Created
February 17, 2023 17:19
-
-
Save stevebauman/724f6135b1855cf633c9af2064744e5c to your computer and use it in GitHub Desktop.
Filesystem Cloud Mocking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
class FilesystemMockProvider extends ServiceProvider | |
{ | |
public function boot() | |
{ | |
if (App::isProduction()) { | |
return; | |
} | |
if (! config('filesystems.mock', false)) { | |
return; | |
} | |
$public = config('filesystems.disks.public'); | |
foreach (config('filesystems.disks') as $disk => $config) { | |
if ('local' !== $config['driver']) { | |
$root = $config['root'] ?? $config['bucket'] ?? '/'; | |
Storage::set($disk, Storage::createLocalDriver(array_merge($config, $public, [ | |
'root' => implode(DIRECTORY_SEPARATOR, [$public['root'], $root]), | |
'url' => implode(DIRECTORY_SEPARATOR, [$public['url'], $root]), | |
]))); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// config/filesystems.php | |
return [ | |
// ... | |
/* | |
|-------------------------------------------------------------------------- | |
| Filesystem Mocking | |
|-------------------------------------------------------------------------- | |
| | |
| The application may store files in several different cloud providers. | |
| Enabling filesystem mocking will swap these cloud provider drivers | |
| with local ones, storing these files locally for easier testing. | |
| | |
*/ | |
'mock' => env('FILESYSTEM_MOCK', env('APP_ENV') === 'local'), | |
// ... | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment