Skip to content

Commit

Permalink
upgrade to google cloud package + add unit tests (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgoslett authored Sep 26, 2016
1 parent e10363c commit 17554f3
Show file tree
Hide file tree
Showing 5 changed files with 992 additions and 209 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- nightly

before_install:
- bash -c 'if [ "$TRAVIS_PHP_VERSION" == "hhvm" ]; then rm phpunit.xml; fi;'
Expand Down
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,44 @@ composer require superbalist/flysystem-google-storage
## Usage

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

$credentials = new \Google_Auth_AssertionCredentials(
'[your service account]',
[\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL],
file_get_contents('[[path to the p12 key file]]'),
'[[your secret]]'
);
/**
* 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);

$client = new \Google_Client();
$client->setAssertionCredentials($credentials);
$client->setDeveloperKey('[[your developer key]]');
/**
* The credentials are manually specified by passing in a keyFilePath.
*/

$service = new \Google_Service_Storage($client);
$storageClient = new StorageClient([
'projectId' => 'your-project-id',
'keyFilePath' => '/path/to/service-account.json',
]);
$bucket = $storageClient->bucket('your-bucket-name');

$adapter = new GoogleStorageAdapter($service, '[[your bucket name]]');
$adapter = new GoogleStorageAdapter($storageClient, $bucket);

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


## TODO

* Unit tests to be written
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=5.5.0",
"league/flysystem": "~1.0",
"google/apiclient": "~1.1"
"google/cloud": "^0.8.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand Down
Loading

0 comments on commit 17554f3

Please sign in to comment.