Skip to content
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

Adds adapter for Google Cloud Client Library #427

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ vendor/
.env
composer.lock
phpunit.xml
.idea/
/nbproject/*
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"mongodb/mongodb": "^1.1",
"microsoft/windowsazure": "~0.4",
"microsoft/azure-storage": "~0.15.0",
"akeneo/phpspec-skip-example-extension": "~1.2"
"akeneo/phpspec-skip-example-extension": "~1.2",
"google/cloud-storage": "^1.1"
},
"suggest": {
"knplabs/knp-gaufrette-bundle": "to use with Symfony2",
Expand All @@ -54,6 +55,9 @@
"google/apiclient": "to use GoogleCloudStorage adapter",
"ext-curl": "*",
"ext-mbstring": "*",
"ext-mongodb": "*",
"mongodb/mongodb": "*",
"google/cloud-storage": "to use Google Cloud Client Library",
"ext-fileinfo": "This extension is used to automatically detect the content-type of a file in the AwsS3, OpenCloud, AzureBlogStorage and GoogleCloudStorage adapters"
},
"autoload": {
Expand Down
66 changes: 66 additions & 0 deletions doc/adapters/google-cloud-client-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
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/

In order to get started:

1) Create a project in [Google Cloud Platform](https://console.cloud.google.com/).
2) Create a bucket for the project in Storage.
3) Create a Service Account in IAM & Admin section that can write access the bucket, download its key.json file.

**At all times make sure you keep your key.json file private and nobody can access it from the Internet.**

## 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 Cloud Storage applies the bucket's default object ACL to the object (uploaded file).
# The example below gives read access to the uploaded files to anyone in the world
# Note that the public URL of the file IS NOT the bucket's file url,
# see https://cloud.google.com/storage/docs/access-public-data for details

$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);

```

Here you can find some more info regarding ACL:
* [Creating and Managing Access Control Lists (ACLs)](https://cloud.google.com/storage/docs/access-control/create-manage-lists)
* [Access Control Lists (ACLs)](https://cloud.google.com/storage/docs/access-control/lists)
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
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@
<env name="AZURE_KEY" value="" />
<env name="AZURE_CONTAINER" value="" />-->

<!-- Configuration for Google Cloud Client adapter -->
<!--<env name="GCCS_PROJECT_ID" value="" />
<env name="GCCS_BUCKET_NAME" value="" />
<env name="GCCS_JSON_KEY_FILE_PATH" value="" />-->

<!-- Configuration for OpenCloud/Rackspace adapter -->
<!--<env name="RACKSPACE_USER" value="" />
<env name="RACKSPACE_APIKEY" value="" />
<env name="RACKSPACE_CONTAINER" value="" />-->

</php>

<testsuites>
Expand Down
Loading