Skip to content

Commit

Permalink
Allow configuring the disk's visibility and cache as with S3 (#32)
Browse files Browse the repository at this point in the history
* Configure filesystem with 'visibility', 'disable_asserts' and 'url' options

* Add 'visibility' option to readme
  • Loading branch information
dgoguerra authored and nicja committed Dec 18, 2018
1 parent 4d6430f commit 10c5069
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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
],
```

Expand Down
26 changes: 25 additions & 1 deletion src/GoogleCloudStorageServiceProvider.php
Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 10c5069

Please sign in to comment.