google-cloud-storage.md 1.2 KB


currentMenu: google-cloud-storage

GoogleCloudStorage

To use the GoogleCloudStorage adapter you will need to create a connection using the Google APIs Client Library for PHP and create a Client ID/Service Account in your Developers Console. You can then create the \Google_Service_Storage which is required for the GoogleCloudStorage adapter.

Example

<?php

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

$client = new \Google_Client();
$client->setClientId('xxxxxxxxxxxxxxx.apps.googleusercontent.com');
$client->setApplicationName('Gaufrette');

$cred = new \Google_Auth_AssertionCredentials(
    'xxxxxxxxxxxxxxx@developer.gserviceaccount.com',
    array(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL),
    file_get_contents('key.p12')
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}

$service = new \Google_Service_Storage($client);
$adapter = new Gaufrette\Adapter\GoogleCloudStorage($service, $config['gcsBucket'], array(
    'acl' => 'public',
), true);
$filesystem = new Gaufrette\Filesystem($adapter);