Skip to content

Commit

Permalink
Merge pull request #313 from Karisch/feature/google-cloud-storage
Browse files Browse the repository at this point in the history
Add support for Google Cloud Storage
  • Loading branch information
wysow committed Mar 9, 2015
2 parents fcc3c3f + ba86a5b commit 4c73bb6
Show file tree
Hide file tree
Showing 7 changed files with 546 additions and 3 deletions.
39 changes: 39 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,45 @@ $adapter = new Gaufrette\Adapter\AzureBlobStorage($factory, 'my-container');
$filesystem = new Gaufrette\Filesystem($adapter);
```

Using GoogleCloudStorage
------------------------

To use the GoogleCloudStorage adapter you will need to create a connection using the [Google APIs Client Library for PHP]
(https://github.com/google/google-api-php-client) and create a Client ID/Service Account in your [Developers Console]
(https://console.developers.google.com/). You can then create the `\Google_Service_Storage` which is required for the
GoogleCloudStorage adapter.

```php
<?php

use Gaufrette\Filesystem;
use Gaufrette\Adapter\GoogleCloudStorage;

$client_id = 'xxxxxxxxxxxxxxx.apps.googleusercontent.com';
$service_account_name = '[email protected]';
$key_file_location = 'key.p12';
$bucket_name = 'mybucket';

$client = new \Google_Client();
$client->setApplicationName('Gaufrette');

$key = file_get_contents($key_file_location);
$cred = new \Google_Auth_AssertionCredentials(
$service_account_name,
array(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL),
$key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}

$service = new \Google_Service_Storage($client);
$adapter = new GoogleCloudStorage($service, $bucket_name, array(), true);

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

Using FTP adapters
---------------

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"aws/aws-sdk-php": "~2",
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"rackspace/php-opencloud" : "1.9.*",
"google/apiclient": "~1.1",
"phpspec/phpspec": "2.0.*",
"phpseclib/phpseclib": "dev-master",
"doctrine/dbal": ">=2.3",
Expand All @@ -42,6 +43,7 @@
"knplabs/knp-gaufrette-bundle": "to use with Symfony2",
"dropbox-php/dropbox-php": "to use the Dropbox adapter",
"rackspace/php-opencloud" : "to use Opencloud adapter",
"google/apiclient": "to use GoogleCloudStorage adapter",
"herzult/php-ssh": "to use SFtp adapter",
"phpseclib/phpseclib": "to use PhpseclibSftp adapter",
"aws/aws-sdk-php": "to use the Amazon S3 adapter",
Expand All @@ -53,7 +55,7 @@
"ext-curl": "*",
"ext-mbstring": "*",
"ext-mongo": "*",
"ext-fileinfo": "This extension is used to automatically detect the content-type of a file in the AwsS3, OpenCloud, and AzureBlogStorage adapters"
"ext-fileinfo": "This extension is used to automatically detect the content-type of a file in the AwsS3, OpenCloud, AzureBlogStorage and GoogleCloudStorage adapters"
},
"autoload": {
"psr-0": { "Gaufrette": "src/" }
Expand Down
48 changes: 46 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions spec/Gaufrette/Adapter/GoogleCloudStorageSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace spec\Gaufrette\Adapter;

use PhpSpec\ObjectBehavior;

class GoogleCloudStorageSpec extends ObjectBehavior
{
public function let(\Google_Service_Storage $service)
{
$this->beConstructedWith($service, 'bucketName');
}

public function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}

public function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}

public function it_is_list_keys_aware()
{
$this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
}
}
Loading

0 comments on commit 4c73bb6

Please sign in to comment.