Skip to content

Commit

Permalink
Merge pull request #1010 from bshaffer/add-gcs-adapter-to-docs
Browse files Browse the repository at this point in the history
Adds Google Cloud Storage to Flysystem website
  • Loading branch information
frankdejonge committed Mar 12, 2019
2 parents 0a342db + 94ae65f commit 29ab800
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/_data/menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Adapters:
Scaleway Object Storage: '/docs/adapter/scaleway-object-storage/'
Dropbox: '/docs/adapter/dropbox/'
FTP: '/docs/adapter/ftp/'
Google Cloud Storage: '/docs/adapter/google-cloud-storage/'
Memory: '/docs/adapter/memory/'
Null / Test: '/docs/adapter/null-test/'
Rackspace: '/docs/adapter/rackspace/'
Expand Down
47 changes: 47 additions & 0 deletions docs/adapter/google-cloud-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
layout: default
permalink: /docs/adapter/google-cloud-storage/
redirect_from: /adapter/google-cloud-storage/
title: Google Cloud Storage Adapter
---

## Installation

```bash
composer require superbalist/flysystem-google-storage
```

## Usage

Google Cloud Storage requires Service Account Credentials, which can be generated in the [Cloud Console](https://console.cloud.google.com/apis/credentials). Read more in [the official documentation](https://cloud.google.com/docs/authentication/production).

```php
use Google\Cloud\Storage\StorageClient;
use League\Flysystem\Filesystem;
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;

/**
* The credentials will be auto-loaded by the Google Cloud Client.
*
* 1. The client will first look at the GOOGLE_APPLICATION_CREDENTIALS env var.
* You can use ```putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');``` to set the location of your credentials file.
*
* 2. The client will look for the credentials file at the following paths:
* - windows: %APPDATA%/gcloud/application_default_credentials.json
* - others: $HOME/.config/gcloud/application_default_credentials.json
*
* If running in Google App Engine, the built-in service account associated with the application will be used.
* If running in Google Compute Engine, the built-in service account associated with the virtual machine instance will be used.
*/

$storageClient = new StorageClient([
'projectId' => 'your-project-id',
]);
$bucket = $storageClient->bucket('your-bucket-name');

$adapter = new GoogleStorageAdapter($storageClient, $bucket);

$filesystem = new Filesystem($adapter);
```

See the [project README](https://github.com/Superbalist/flysystem-google-cloud-storage#usage) for additional usage examples.

0 comments on commit 29ab800

Please sign in to comment.