diff --git a/README.md b/README.md index b660882..a1f9c88 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Add a new disk to your `filesystems.php` config 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket 'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below + 'visibility' => 'public', // optional: public|private ], ``` diff --git a/src/GoogleCloudStorageServiceProvider.php b/src/GoogleCloudStorageServiceProvider.php index d4c1d25..c3bb34e 100644 --- a/src/GoogleCloudStorageServiceProvider.php +++ b/src/GoogleCloudStorageServiceProvider.php @@ -4,12 +4,35 @@ use Google\Cloud\Storage\StorageClient; use Illuminate\Filesystem\FilesystemManager; +use Illuminate\Support\Arr; use Illuminate\Support\ServiceProvider; +use League\Flysystem\AdapterInterface; +use League\Flysystem\Cached\CachedAdapter; use League\Flysystem\Filesystem; use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter; class GoogleCloudStorageServiceProvider extends ServiceProvider { + /** + * Create a Filesystem instance with the given adapter. + * + * @param \League\Flysystem\AdapterInterface $adapter + * @param array $config + * @return \League\Flysystem\FlysystemInterfaceAdapterInterface + */ + protected function createFilesystem(AdapterInterface $adapter, array $config) + { + $cache = Arr::pull($config, 'cache'); + + $config = Arr::only($config, ['visibility', 'disable_asserts', 'url']); + + if ($cache) { + $adapter = new CachedAdapter($adapter, $this->createCacheStore($cache)); + } + + return new Filesystem($adapter, count($config) > 0 ? $config : null); + } + /** * Perform post-registration booting of services. */ @@ -27,10 +50,11 @@ public function boot() $adapter = new GoogleStorageAdapter($storageClient, $bucket, $pathPrefix, $storageApiUri); - return new Filesystem($adapter); + return $this->createFilesystem($adapter, $config); }); } + /** * Register bindings in the container. */