Skip to content

Adds adapter for Google Cloud Client Library #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"phpunit/phpunit": "3.7.*",
"mikey179/vfsStream": "~1.2.0",
"league/flysystem": "~1.0",
"mongodb/mongodb": "~1.1.4"
"mongodb/mongodb": "~1.1.4",
"google/cloud-storage": "dev-master"
Copy link
Contributor

@akerouanton akerouanton May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google/cloud-storage v1.0 has been released a month ago. Do you think your work is compatible with it? Would be great to depend on a stable branch rather than dev-master ;)

},
"suggest": {
"knplabs/knp-gaufrette-bundle": "to use with Symfony2",
Expand All @@ -61,7 +62,8 @@
"ext-mbstring": "*",
"ext-mongodb": "*",
"ext-fileinfo": "This extension is used to automatically detect the content-type of a file in the AwsS3, OpenCloud, AzureBlogStorage and GoogleCloudStorage adapters",
"mongodb/mongodb": "*"
"mongodb/mongodb": "*",
"google/cloud-storage": "to use Google Cloud Client Library"
},
"autoload": {
"psr-0": { "Gaufrette": "src/" }
Expand All @@ -71,4 +73,4 @@
"dev-master": "0.4.x-dev"
}
}
}
}
52 changes: 52 additions & 0 deletions doc/adapters/google-cloud-client-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
currentMenu: google-cloud-client-storage
---

# Google Cloud Client Storage

This adapter requires an instance of Google\Cloud\Storage\StorageClient that has proper access rights to the bucket you want to use.

For more details see:
http://googlecloudplatform.github.io/google-cloud-php/
https://console.cloud.google.com/

## Example

```php
<?php

use Gaufrette\Filesystem;
use Gaufrette\Adapter\GoogleCloudClientStorage;

$storage = new StorageClient(array(
'projectId' => 'your-project-id',
'keyFilePath' => 'path/to/your/project/key.json'
));

# you can optionally set the directory in the bucket and the acl permissions for all uploaded files...
# by default the uploaded files are read/write by the owner only
# the example below gives read access to the uploaded files to anyone in the world

$adapter = new GoogleCloudClientStorage($storage, 'bucket_name',
array(
'directory' => 'bucket_directory',
'acl' => array(
'allUsers' => \Google\Cloud\Storage\Acl::ROLE_READER
)
)
);

$key = 'myAmazingFile.txt';

# optional
$adapter->setMetadata($key,
array(
'FileDescription' => 'This is my file. There are many like it, but this one is mine.'
)
);

$filesystem = new Filesystem($adapter);

$filesystem->write($key, 'Uploaded at: '.date('Y-m-d @ H:i:s'), true);

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any idea what's the minimum set of security access (roles?) needed to use it? Would be awesome to provide something equivalent to this. But that's a detail, it could be postpone to another PR.

2 changes: 2 additions & 0 deletions doc/adapters/google-cloud-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ To use the GoogleCloudStorage adapter you will need to create a connection using
(https://console.developers.google.com/). You can then create the `\Google_Service_Storage` which is required for the
GoogleCloudStorage adapter.

Install with: composer require google/cloud-storage

## Example

```php
Expand Down
Loading